9 #define Percent(num, max) (((num)*100)/(max))
11 extern Inst op0[], op2[], op3[];
12 Inst *tables[] = { op0, op2, op3, 0 };
19 int total, loads, stores, arith, branch;
20 int useddelay, taken, sparcreg, syscall, realarith;
33 /* Compute the total so we can have percentages */
34 for(j = 0; tables[j]; j++)
35 for(i = tables[j]; i->func; i++)
36 if(i->name && i->count)
39 Bprint(bioout, "\nInstruction summary.\n\n");
41 for(j = 0; tables[j]; j++) {
42 for(i =tables[j]; i->func; i++) {
46 pct = Percent(i->count, total);
48 Bprint(bioout, "%-8ud %3d%% %s\n",
49 i->count, Percent(i->count, total), i->name);
51 Bprint(bioout, "%-8ud %s\n",
56 fatal(0, "isum bad stype %d\n", i->type);
69 useddelay += i->useddelay;
78 realarith += i->count;
90 Bprint(bioout, "\n%-8ud Memory cycles\n", loads+stores+total);
92 Bprint(bioout, "%-8ud %3d%% Instruction cycles\n",
93 total, Percent(total, loads+stores+total));
94 Bprint(bioout, "%-8lud %3ld%% Annulled branch cycles\n",
95 anulled, Percent(anulled, total));
97 Bprint(bioout, "%-8ud %3d%% Data cycles\n\n",
98 loads+stores, Percent(loads+stores, loads+stores+total));
100 Bprint(bioout, "%-8ud %3d%% Stores\n", stores, Percent(stores, total));
102 Bprint(bioout, "%-8ud %3d%% Loads\n", loads, Percent(loads, total));
104 Bprint(bioout, " %-8ud Store stall\n", stores*2);
106 Bprint(bioout, " %-8lud Load stall\n", loadlock);
108 Bprint(bioout, "%-8ud %3d%% Arithmetic\n", arith, Percent(arith, total));
110 Bprint(bioout, "%-8ud %3d%% Floating point\n",
111 realarith, Percent(realarith, total));
113 Bprint(bioout, "%-8ud %3d%% Sparc special register load/stores\n",
114 sparcreg, Percent(sparcreg, total));
116 Bprint(bioout, "%-8ud %3d%% System calls\n", syscall, Percent(syscall, total));
118 Bprint(bioout, "%-8ud %3d%% Branches\n", branch, Percent(branch, total));
120 Bprint(bioout, " %-8ud %3d%% Branches taken\n",
121 taken, Percent(taken, branch));
123 Bprint(bioout, " %-8ud %3d%% Delay slots\n",
124 useddelay, Percent(useddelay, branch));
126 Bprint(bioout, " %-8ud %3d%% Unused delay slots\n",
127 nopcount, Percent(nopcount, branch));
129 Bprint(bioout, "%-8ud %3d%% Program total delay slots\n",
130 nopcount, Percent(nopcount, total));
133 char *stype[] = { "Stack", "Text", "Data", "Bss" };
141 Bprint(bioout, "\n\nMemory Summary\n\n");
142 Bprint(bioout, " Base End Resident References\n");
143 for(i = 0; i < Nseg; i++) {
145 Bprint(bioout, "%-5s %.8lux %.8lux %-8d %-8d\n",
146 stype[i], s->base, s->end, s->rss*BY2PG, s->refs);
150 typedef struct Prof Prof;
159 profcmp(void *va, void *vb)
165 return b->count - a->count;
174 extern ulong textbase;
178 if(textsym(&p->s, i) == 0)
183 if(textsym(&n->s, i) == 0)
185 b = (p->s.value-textbase)/PROFGRAN;
186 e = (n->s.value-textbase)/PROFGRAN;
188 p->count += iprof[b++];
193 qsort(prof, i, sizeof(Prof), profcmp);
196 for(b = 0; b < i; b++)
197 total += prof[b].count;
199 Bprint(bioout, " cycles %% symbol file\n");
200 for(b = 0; b < i; b++) {
201 if(prof[b].count == 0)
204 Bprint(bioout, "%8ld %3ld.%ld %-15s ",
206 100*prof[b].count/total,
207 (1000*prof[b].count/total)%10,
210 printsource(prof[b].s.value);
213 memset(prof, 0, sizeof(Prof)*i);