stats.c 4.4 KB

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