stats.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <mach.h>
  5. #define Extern extern
  6. #include "mips.h"
  7. #define Percent(num, max) (((num)*100)/(max))
  8. extern Inst itab[], ispec[], cop1[];
  9. Inst *tables[] = { itab, ispec, cop1, 0 };
  10. void
  11. isum(void)
  12. {
  13. Inst *i;
  14. int total, loads, stores, arith, branch, realarith;
  15. int useddelay, taken, mipreg, syscall;
  16. int ldsunused, ldsused, ltotal;
  17. int pct, j;
  18. total = 0;
  19. loads = 0;
  20. stores = 0;
  21. arith = 0;
  22. branch = 0;
  23. useddelay = 0;
  24. taken = 0;
  25. mipreg = 0;
  26. syscall = 0;
  27. realarith = 0;
  28. /* Compute the total so we can have percentages */
  29. for(i = itab; i->func; i++)
  30. if(i->name && i->count)
  31. total += i->count;
  32. for(i = ispec; i->func; i++) {
  33. if(i->name && i->count) {
  34. }
  35. }
  36. /* Compute the total so we can have percentages */
  37. for(j = 0; tables[j]; j++) {
  38. for(i = tables[j]; i->func; i++) {
  39. if(i->name && i->count) {
  40. /* Dont count floating point twice */
  41. if(strcmp(i->name, "cop1") == 0)
  42. i->count = 0;
  43. else
  44. total += i->count;
  45. }
  46. }
  47. }
  48. Bprint(bioout, "\nInstruction summary.\n\n");
  49. for(j = 0; tables[j]; j++) {
  50. for(i =tables[j]; i->func; i++) {
  51. if(i->name) {
  52. /* This is gross */
  53. if(strcmp(i->name, INOPINST) == 0)
  54. i->count -= nopcount;
  55. if(i->count == 0)
  56. continue;
  57. pct = Percent(i->count, total);
  58. if(pct != 0)
  59. Bprint(bioout, "%-8ud %3d%% %s\n",
  60. i->count, Percent(i->count,
  61. total), i->name);
  62. else
  63. Bprint(bioout, "%-8ud %s\n",
  64. i->count, i->name);
  65. switch(i->type) {
  66. default:
  67. fatal(0, "isum bad stype %d\n", i->type);
  68. case Iload:
  69. loads += i->count;
  70. break;
  71. case Istore:
  72. stores += i->count;
  73. break;
  74. case Iarith:
  75. arith += i->count;
  76. break;
  77. case Ibranch:
  78. branch += i->count;
  79. taken += i->taken;
  80. useddelay += i->useddelay;
  81. break;
  82. case Ireg:
  83. mipreg += i->count;
  84. break;
  85. case Isyscall:
  86. syscall += i->count;
  87. break;
  88. case Ifloat:
  89. realarith += i->count;
  90. break;
  91. }
  92. }
  93. }
  94. }
  95. Bprint(bioout, "\n%-8ud Memory cycles\n", loads+stores+total);
  96. Bprint(bioout, "%-8ud %3d%% Instruction cycles\n",
  97. total, Percent(total, loads+stores+total));
  98. Bprint(bioout, "%-8ud %3d%% Data cycles\n\n",
  99. loads+stores, Percent(loads+stores, loads+stores+total));
  100. Bprint(bioout, "%-8ud %3d%% Stores\n", stores, Percent(stores, total));
  101. Bprint(bioout, "%-8ud %3d%% Loads\n", loads, Percent(loads, total));
  102. /* Delay slots for loads/stores */
  103. ldsunused = nopcount-(branch-useddelay);
  104. ldsused = loads-ldsunused;
  105. ltotal = ldsused + ldsunused;
  106. Bprint(bioout, " %-8ud %3d%% Delay slots\n",
  107. ldsused, Percent(ldsused, ltotal));
  108. Bprint(bioout, " %-8ud %3d%% Unused delay slots\n",
  109. ldsunused, Percent(ldsunused, ltotal));
  110. Bprint(bioout, "%-8ud %3d%% Arithmetic\n",
  111. arith, Percent(arith, total));
  112. Bprint(bioout, "%-8ud %3d%% Floating point\n",
  113. realarith, Percent(realarith, total));
  114. Bprint(bioout, "%-8ud %3d%% Mips special register load/stores\n",
  115. mipreg, Percent(mipreg, total));
  116. Bprint(bioout, "%-8ud %3d%% System calls\n",
  117. syscall, Percent(syscall, total));
  118. Bprint(bioout, "%-8ud %3d%% Branches\n",
  119. branch, Percent(branch, total));
  120. Bprint(bioout, " %-8ud %3d%% Branches taken\n",
  121. taken, Percent(taken, branch));
  122. Bprint(bioout, " %-8ud %3d%% Delay slots\n",
  123. useddelay, Percent(useddelay, branch));
  124. Bprint(bioout, " %-8ud %3d%% Unused delay slots\n",
  125. branch-useddelay, Percent(branch-useddelay, branch));
  126. Bprint(bioout, "%-8ud %3d%% Program total delay slots\n",
  127. nopcount, Percent(nopcount, total));
  128. }
  129. void
  130. tlbsum(void)
  131. {
  132. if(tlb.on == 0)
  133. return;
  134. Bprint(bioout, "\n\nTlb summary\n");
  135. Bprint(bioout, "\n%-8d User entries\n", tlb.tlbsize);
  136. Bprint(bioout, "%-8d Accesses\n", tlb.hit+tlb.miss);
  137. Bprint(bioout, "%-8d Tlb hits\n", tlb.hit);
  138. Bprint(bioout, "%-8d Tlb misses\n", tlb.miss);
  139. Bprint(bioout, "%7d%% Hit rate\n", Percent(tlb.hit, tlb.hit+tlb.miss));
  140. }
  141. char *stype[] = { "Stack", "Text", "Data", "Bss" };
  142. void
  143. segsum(void)
  144. {
  145. Segment *s;
  146. int i;
  147. Bprint(bioout, "\n\nMemory Summary\n\n");
  148. Bprint(bioout, " Base End Resident References\n");
  149. for(i = 0; i < Nseg; i++) {
  150. s = &memory.seg[i];
  151. Bprint(bioout, "%-5s %.8lux %.8lux %-8d %-8d\n",
  152. stype[i], s->base, s->end, s->rss*BY2PG, s->refs);
  153. }
  154. }
  155. typedef struct Prof Prof;
  156. struct Prof
  157. {
  158. Symbol s;
  159. long count;
  160. };
  161. Prof prof[5000];
  162. int
  163. profcmp(void *va, void *vb)
  164. {
  165. Prof *a, *b;
  166. a = va;
  167. b = vb;
  168. return b->count - a->count;
  169. }
  170. void
  171. iprofile(void)
  172. {
  173. Prof *p, *n;
  174. int i, b, e;
  175. ulong total;
  176. extern ulong textbase;
  177. i = 0;
  178. p = prof;
  179. if(textsym(&p->s, i) == 0)
  180. return;
  181. i++;
  182. for(;;) {
  183. n = p+1;
  184. if(textsym(&n->s, i) == 0)
  185. break;
  186. b = (p->s.value-textbase)/PROFGRAN;
  187. e = (n->s.value-textbase)/PROFGRAN;
  188. while(b < e)
  189. p->count += iprof[b++];
  190. i++;
  191. p = n;
  192. }
  193. qsort(prof, i, sizeof(Prof), profcmp);
  194. total = 0;
  195. for(b = 0; b < i; b++)
  196. total += prof[b].count;
  197. Bprint(bioout, " cycles %% symbol file\n");
  198. for(b = 0; b < i; b++) {
  199. if(prof[b].count == 0)
  200. continue;
  201. Bprint(bioout, "%8ld %3ld.%ld %-15s ",
  202. prof[b].count,
  203. 100*prof[b].count/total,
  204. (1000*prof[b].count/total)%10,
  205. prof[b].s.name);
  206. printsource(prof[b].s.value);
  207. Bputc(bioout, '\n');
  208. }
  209. memset(prof, 0, sizeof(Prof)*i);
  210. }