stats.c 4.9 KB

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