stats.c 5.7 KB

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