stats.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <mach.h>
  5. #define Extern extern
  6. #include "power.h"
  7. #define prof profqi
  8. #define Percent(num, max) (int)(((vlong)(num)*100)/(max))
  9. Inset *tables[] = { &ops0, &ops19, &ops31, &ops59, &ops63a, &ops63b, 0 };
  10. void
  11. isum(void)
  12. {
  13. Inst *i;
  14. int pct, j, k;
  15. int total, loads, stores, arith, branch;
  16. int taken, powerreg, syscall, realarith, control;
  17. total = 0;
  18. loads = 0;
  19. stores = 0;
  20. arith = 0;
  21. branch = 0;
  22. taken = 0;
  23. powerreg = 0;
  24. syscall = 0;
  25. realarith = 0;
  26. control = 0;
  27. /* Compute the total so we can have percentages */
  28. for(j = 0; tables[j]; j++)
  29. for(k = tables[j]->nel; --k >= 0;) {
  30. i = &tables[j]->tab[k];
  31. if(i->name && i->func)
  32. total += i->count;
  33. }
  34. Bprint(bioout, "\nInstruction summary.\n\n");
  35. for(j = 0; tables[j]; j++) {
  36. for(k =tables[j]->nel; --k>=0; ) {
  37. i = &tables[j]->tab[k];
  38. if(i->name && i->func) {
  39. if(i->count == 0)
  40. continue;
  41. pct = Percent(i->count, total);
  42. if(pct != 0)
  43. Bprint(bioout, "%-8ud %3d%% %s\n",
  44. i->count, Percent(i->count, total), i->name);
  45. else
  46. Bprint(bioout, "%-8ud %s\n",
  47. i->count, i->name);
  48. switch(i->type) {
  49. default:
  50. fatal(0, "isum bad stype %d\n", i->type);
  51. case Iload:
  52. loads += i->count;
  53. break;
  54. case Istore:
  55. stores += i->count;
  56. break;
  57. case Ilog:
  58. case Iarith:
  59. arith += i->count;
  60. break;
  61. case Ibranch:
  62. branch += i->count;
  63. taken += i->taken;
  64. break;
  65. case Ireg:
  66. powerreg += i->count;
  67. break;
  68. case Isyscall:
  69. syscall += i->count;
  70. break;
  71. case Ifloat:
  72. realarith += i->count;
  73. break;
  74. case Inop:
  75. arith += i->count;
  76. i->count -= nopcount;
  77. break;
  78. case Icontrol:
  79. control += i->count;
  80. break;
  81. }
  82. }
  83. }
  84. }
  85. Bprint(bioout, "\n%-8ud Memory cycles\n", loads+stores+total);
  86. Bprint(bioout, "%-8ud %3d%% Instruction cycles\n",
  87. total, Percent(total, loads+stores+total));
  88. Bprint(bioout, "%-8ud %3d%% Data cycles\n\n",
  89. loads+stores, Percent(loads+stores, loads+stores+total));
  90. Bprint(bioout, "%-8ud %3d%% Stores\n", stores, Percent(stores, total));
  91. Bprint(bioout, "%-8ud %3d%% Loads\n", loads, Percent(loads, total));
  92. Bprint(bioout, " %-8ud Store stall\n", stores*2);
  93. Bprint(bioout, " %-8lud Load stall\n", loadlock);
  94. Bprint(bioout, "%-8ud %3d%% Arithmetic\n", arith, Percent(arith, total));
  95. Bprint(bioout, "%-8ud %3d%% Floating point\n",
  96. realarith, Percent(realarith, total));
  97. Bprint(bioout, "%-8ud %3d%% PowerPC special register load/stores\n",
  98. powerreg, Percent(powerreg, total));
  99. Bprint(bioout, "%-8ud %3d%% PowerPC control instructions\n",
  100. control, Percent(control, total));
  101. Bprint(bioout, "%-8ud %3d%% System calls\n", syscall, Percent(syscall, total));
  102. Bprint(bioout, "%-8ud %3d%% Branches\n", branch, Percent(branch, total));
  103. Bprint(bioout, " %-8ud %3d%% Branches taken\n",
  104. taken, Percent(taken, branch));
  105. }
  106. char *stype[] = { "Stack", "Text", "Data", "Bss" };
  107. void
  108. segsum(void)
  109. {
  110. Segment *s;
  111. int i;
  112. Bprint(bioout, "\n\nMemory Summary\n\n");
  113. Bprint(bioout, " Base End Resident References\n");
  114. for(i = 0; i < Nseg; i++) {
  115. s = &memory.seg[i];
  116. Bprint(bioout, "%-5s %.8lux %.8lux %-8d %-8d\n",
  117. stype[i], s->base, s->end, s->rss*BY2PG, s->refs);
  118. }
  119. }
  120. typedef struct Prof Prof;
  121. struct Prof
  122. {
  123. Symbol s;
  124. long count;
  125. };
  126. Prof prof[5000];
  127. int
  128. profcmp(void *a, void *b)
  129. {
  130. return ((Prof*)b)->count - ((Prof*)a)->count;
  131. }
  132. void
  133. iprofile(void)
  134. {
  135. Prof *p, *n;
  136. int i, b, e;
  137. ulong total;
  138. extern ulong textbase;
  139. i = 0;
  140. p = prof;
  141. if(textsym(&p->s, i) == 0)
  142. return;
  143. i++;
  144. for(;;) {
  145. n = p+1;
  146. if(textsym(&n->s, i) == 0)
  147. break;
  148. b = (p->s.value-textbase)/PROFGRAN;
  149. e = (n->s.value-textbase)/PROFGRAN;
  150. while(b < e)
  151. p->count += iprof[b++];
  152. i++;
  153. p = n;
  154. }
  155. qsort(prof, i, sizeof(Prof), profcmp);
  156. total = 0;
  157. for(b = 0; b < i; b++)
  158. total += prof[b].count;
  159. Bprint(bioout, " cycles %% symbol file\n");
  160. for(b = 0; b < i; b++) {
  161. if(prof[b].count == 0)
  162. continue;
  163. Bprint(bioout, "%8ld %3ld.%ld %-15s ",
  164. prof[b].count,
  165. 100*prof[b].count/total,
  166. (1000*prof[b].count/total)%10,
  167. prof[b].s.name);
  168. printsource(prof[b].s.value);
  169. Bputc(bioout, '\n');
  170. }
  171. memset(prof, 0, sizeof(Prof)*i);
  172. }