stats.c 4.4 KB

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