stats.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 "power.h"
  15. #define prof profqi
  16. #define Percent(num, max) (int)(((vlong)(num)*100)/(max))
  17. Inset *tables[] = { &ops0, &ops19, &ops31, &ops59, &ops63a, &ops63b, 0 };
  18. void
  19. isum(void)
  20. {
  21. Inst *i;
  22. int pct, j, k;
  23. int total, loads, stores, arith, branch;
  24. int taken, powerreg, syscall, realarith, control;
  25. total = 0;
  26. loads = 0;
  27. stores = 0;
  28. arith = 0;
  29. branch = 0;
  30. taken = 0;
  31. powerreg = 0;
  32. syscall = 0;
  33. realarith = 0;
  34. control = 0;
  35. /* Compute the total so we can have percentages */
  36. for(j = 0; tables[j]; j++)
  37. for(k = tables[j]->nel; --k >= 0;) {
  38. i = &tables[j]->tab[k];
  39. if(i->name && i->func)
  40. total += i->count;
  41. }
  42. Bprint(bioout, "\nInstruction summary.\n\n");
  43. for(j = 0; tables[j]; j++) {
  44. for(k =tables[j]->nel; --k>=0; ) {
  45. i = &tables[j]->tab[k];
  46. if(i->name && i->func) {
  47. if(i->count == 0)
  48. continue;
  49. pct = Percent(i->count, total);
  50. if(pct != 0)
  51. Bprint(bioout, "%-8ud %3d%% %s\n",
  52. i->count, Percent(i->count, total), i->name);
  53. else
  54. Bprint(bioout, "%-8ud %s\n",
  55. i->count, i->name);
  56. switch(i->type) {
  57. default:
  58. fatal(0, "isum bad stype %d\n", i->type);
  59. case Iload:
  60. loads += i->count;
  61. break;
  62. case Istore:
  63. stores += i->count;
  64. break;
  65. case Ilog:
  66. case Iarith:
  67. arith += i->count;
  68. break;
  69. case Ibranch:
  70. branch += i->count;
  71. taken += i->taken;
  72. break;
  73. case Ireg:
  74. powerreg += i->count;
  75. break;
  76. case Isyscall:
  77. syscall += i->count;
  78. break;
  79. case Ifloat:
  80. realarith += i->count;
  81. break;
  82. case Inop:
  83. arith += i->count;
  84. i->count -= nopcount;
  85. break;
  86. case Icontrol:
  87. control += i->count;
  88. break;
  89. }
  90. }
  91. }
  92. }
  93. Bprint(bioout, "\n%-8ud Memory cycles\n", loads+stores+total);
  94. if(total == 0)
  95. return;
  96. Bprint(bioout, "%-8ud %3d%% Instruction cycles\n",
  97. total, Percent(total, loads+stores+total));
  98. Bprint(bioout, "%-8ud %3d%% Data cycles\n\n",
  99. loads+stores, Percent(loads+stores, loads+stores+total));
  100. Bprint(bioout, "%-8ud %3d%% Stores\n", stores, Percent(stores, total));
  101. Bprint(bioout, "%-8ud %3d%% Loads\n", loads, Percent(loads, total));
  102. Bprint(bioout, " %-8ud Store stall\n", stores*2);
  103. Bprint(bioout, " %-8lud Load stall\n", loadlock);
  104. Bprint(bioout, "%-8ud %3d%% Arithmetic\n", arith, Percent(arith, total));
  105. Bprint(bioout, "%-8ud %3d%% Floating point\n",
  106. realarith, Percent(realarith, total));
  107. Bprint(bioout, "%-8ud %3d%% PowerPC special register load/stores\n",
  108. powerreg, Percent(powerreg, total));
  109. Bprint(bioout, "%-8ud %3d%% PowerPC control instructions\n",
  110. control, Percent(control, total));
  111. Bprint(bioout, "%-8ud %3d%% System calls\n", syscall, Percent(syscall, total));
  112. Bprint(bioout, "%-8ud %3d%% Branches\n", branch, Percent(branch, total));
  113. Bprint(bioout, " %-8ud %3d%% Branches taken\n",
  114. taken, Percent(taken, branch));
  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 *a, const void *b)
  139. {
  140. return ((Prof*)b)->count - ((Prof*)a)->count;
  141. }
  142. void
  143. iprofile(void)
  144. {
  145. Prof *p, *n;
  146. int i, b, e;
  147. uint32_t total;
  148. extern uint32_t textbase;
  149. i = 0;
  150. p = prof;
  151. if(textsym(&p->s, i) == 0)
  152. return;
  153. i++;
  154. for(;;) {
  155. n = p+1;
  156. if(textsym(&n->s, i) == 0)
  157. break;
  158. b = (p->s.value-textbase)/PROFGRAN;
  159. e = (n->s.value-textbase)/PROFGRAN;
  160. while(b < e)
  161. p->count += iprof[b++];
  162. i++;
  163. p = n;
  164. }
  165. qsort(prof, i, sizeof(Prof), profcmp);
  166. total = 0;
  167. for(b = 0; b < i; b++)
  168. total += prof[b].count;
  169. Bprint(bioout, " cycles %% symbol file\n");
  170. for(b = 0; b < i; b++) {
  171. if(prof[b].count == 0)
  172. continue;
  173. Bprint(bioout, "%8ld %3ld.%ld %-15s ",
  174. prof[b].count,
  175. 100*prof[b].count/total,
  176. (1000*prof[b].count/total)%10,
  177. prof[b].s.name);
  178. printsource(prof[b].s.value);
  179. Bputc(bioout, '\n');
  180. }
  181. memset(prof, 0, sizeof(Prof)*i);
  182. }