stats.c 3.9 KB

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