return w + (w-1)/3; // add space for commas
}
-static
-void percentify(Int n, Int ex, Int field_width, char buf[])
-{
- int i, len, space;
-
- VG_(sprintf)(buf, "%d.%d%%", n / ex, n % ex);
- len = VG_(strlen)(buf);
- space = field_width - len;
- if (space < 0) space = 0; /* Allow for v. small field_width */
- i = len;
-
- /* Right justify in field */
- for ( ; i >= 0; i--) buf[i + space] = buf[i];
- for (i = 0; i < space; i++) buf[i] = ' ';
-}
-
static void cg_fini(Int exitcode)
{
static char buf1[128], buf2[128], buf3[128], fmt [128];
p = 100;
if (0 == Ir_total.a) Ir_total.a = 1;
- percentify(Ir_total.m1 * 100 * p / Ir_total.a, p, l1+1, buf1);
+ VG_(percentify)(Ir_total.m1, Ir_total.a, 2, l1+1, buf1);
VG_(message)(Vg_UserMsg, "I1 miss rate: %s", buf1);
- percentify(Ir_total.m2 * 100 * p / Ir_total.a, p, l1+1, buf1);
+ VG_(percentify)(Ir_total.m2, Ir_total.a, 2, l1+1, buf1);
VG_(message)(Vg_UserMsg, "L2i miss rate: %s", buf1);
VG_(message)(Vg_UserMsg, "");
if (0 == D_total.a) D_total.a = 1;
if (0 == Dr_total.a) Dr_total.a = 1;
if (0 == Dw_total.a) Dw_total.a = 1;
- percentify( D_total.m1 * 100 * p / D_total.a, p, l1+1, buf1);
- percentify(Dr_total.m1 * 100 * p / Dr_total.a, p, l2+1, buf2);
- percentify(Dw_total.m1 * 100 * p / Dw_total.a, p, l3+1, buf3);
+ VG_(percentify)( D_total.m1, D_total.a, 1, l1+1, buf1);
+ VG_(percentify)(Dr_total.m1, Dr_total.a, 1, l2+1, buf2);
+ VG_(percentify)(Dw_total.m1, Dw_total.a, 1, l3+1, buf3);
VG_(message)(Vg_UserMsg, "D1 miss rate: %s (%s + %s )", buf1, buf2,buf3);
- percentify( D_total.m2 * 100 * p / D_total.a, p, l1+1, buf1);
- percentify(Dr_total.m2 * 100 * p / Dr_total.a, p, l2+1, buf2);
- percentify(Dw_total.m2 * 100 * p / Dw_total.a, p, l3+1, buf3);
+ VG_(percentify)( D_total.m2, D_total.a, 1, l1+1, buf1);
+ VG_(percentify)(Dr_total.m2, Dr_total.a, 1, l2+1, buf2);
+ VG_(percentify)(Dw_total.m2, Dw_total.a, 1, l3+1, buf3);
VG_(message)(Vg_UserMsg, "L2d miss rate: %s (%s + %s )", buf1, buf2,buf3);
VG_(message)(Vg_UserMsg, "");
VG_(message)(Vg_UserMsg, fmt, "L2 misses: ",
L2_total_m, L2_total_mr, L2_total_mw);
- percentify(L2_total_m * 100 * p / (Ir_total.a + D_total.a), p, l1+1, buf1);
- percentify(L2_total_mr * 100 * p / (Ir_total.a + Dr_total.a), p, l2+1, buf2);
- percentify(L2_total_mw * 100 * p / Dw_total.a, p, l3+1, buf3);
+ VG_(percentify)(L2_total_m, (Ir_total.a + D_total.a), 1, l1+1, buf1);
+ VG_(percentify)(L2_total_mr, (Ir_total.a + Dr_total.a), 1, l2+1, buf2);
+ VG_(percentify)(L2_total_mw, Dw_total.a, 1, l3+1, buf3);
VG_(message)(Vg_UserMsg, "L2 miss rate: %s (%s + %s )", buf1, buf2,buf3);
return ret;
}
+/* ---------------------------------------------------------------------
+ percentify()
+ ------------------------------------------------------------------ */
+
+// Percentify n/m with p decimal places. Includes the '%' symbol at the end.
+void VG_(percentify)(UInt n, UInt m, UInt d, Int n_buf, char buf[])
+{
+ Int i, len, space;
+
+ ULong p1 = (100*n) / m;
+
+ if (d == 0) {
+ VG_(sprintf)(buf, "%lld%%", p1);
+ } else {
+ ULong p2;
+ UInt ex;
+ Char fmt[32];
+ switch (d) {
+ case 1: ex = 10; break;
+ case 2: ex = 100; break;
+ case 3: ex = 1000; break;
+ default: VG_(tool_panic)("Currently can only handle 3 decimal places");
+ }
+ p2 = ((100*n*ex) / m) % ex;
+ // Have to generate the format string in order to be flexible about
+ // the width of the post-decimal-point part.
+ VG_(sprintf)(fmt, "%%lld.%%0%dlld%%%%", d);
+ // fmt is now "%lld.%0<d>lld%%" where <d> is 1,2,3...
+ VG_(sprintf)(buf, fmt, p1, p2);
+ }
+
+ len = VG_(strlen)(buf);
+ space = n_buf - len;
+ if (space < 0) space = 0; /* Allow for v. small field_width */
+ i = len;
+
+ /* Right justify in field */
+ for ( ; i >= 0; i--) buf[i + space] = buf[i];
+ for (i = 0; i < space; i++) buf[i] = ' ';
+}
+
/* ---------------------------------------------------------------------
message()
------------------------------------------------------------------ */
return score(t1) > score(t2);
}
-/* Print n/m in form xx.yy% */
-static
-void percentify ( ULong n, ULong m, Int field_width, Char* buf)
-{
- Int i, len, space;
- ULong lo, hi;
- if (m == 0) m = 1; /* stay sane */
- hi = (n * 100) / m;
- lo = (((n * 100) - hi * m) * 100) / m;
- vg_assert(lo < 100);
- if (lo < 10)
- VG_(sprintf)(buf, "%lld.0%lld%%", hi, lo);
- else
- VG_(sprintf)(buf, "%lld.%lld%%", hi, lo);
-
- len = VG_(strlen)(buf);
- space = field_width - len;
- if (space < 0) space = 0; /* Allow for v. small field_width */
- i = len;
-
- /* Right justify in field */
- for ( ; i >= 0; i--) buf[i + space] = buf[i];
- for (i = 0; i < space; i++) buf[i] = ' ';
-}
-
-
void VG_(show_BB_profile) ( void )
{
Char name[64];
name[63] = 0;
score_here = score(tops[r]);
score_cumul += score_here;
- percentify(score_cumul, score_total, 6, buf_cumul);
- percentify(score_here, score_total, 6, buf_here);
+ VG_(percentify)(score_cumul, score_total, 2, 6, buf_cumul);
+ VG_(percentify)(score_here, score_total, 2, 6, buf_here);
VG_(printf)("%3d: (%9lld %s) %9lld %s 0x%llx %s\n",
r,
score_cumul, buf_cumul,
name[63] = 0;
score_here = score(tops[r]);
score_cumul += score_here;
- percentify(score_cumul, score_total, 6, buf_cumul);
- percentify(score_here, score_total, 6, buf_here);
+ VG_(percentify)(score_cumul, score_total, 2, 6, buf_cumul);
+ VG_(percentify)(score_here, score_total, 2, 6, buf_here);
VG_(printf)("\n");
VG_(printf)("=-=-=-=-=-=-=-=-=-=-=-=-=-= begin BB rank %d "
"=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n", r);