stats.c 5.3 KB

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