From d9373ff17c49cb5d913d38ef0ed3efa8a11ca6df Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Fri, 6 Jan 2012 10:07:45 -0800 Subject: dynamic metrics report width --- src/metrics.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/metrics.cc b/src/metrics.cc index 07caade..1c7b7de 100644 --- a/src/metrics.cc +++ b/src/metrics.cc @@ -96,13 +96,20 @@ Metric* Metrics::NewMetric(const string& name) { } void Metrics::Report() { - printf("%-10s\t%-6s\t%9s\t%s\n", + int width = 0; + for (vector::iterator i = metrics_.begin(); + i != metrics_.end(); ++i) { + width = max((int)(*i)->name.size(), width); + } + + printf("%-*s\t%-6s\t%9s\t%s\n", width, "metric", "count", "total (ms)" , "avg (us)"); - for (vector::iterator i = metrics_.begin(); i != metrics_.end(); ++i) { + for (vector::iterator i = metrics_.begin(); + i != metrics_.end(); ++i) { Metric* metric = *i; double total = metric->sum / (double)1000; double avg = metric->sum / (double)metric->count; - printf("%-10s\t%-6d\t%-8.1f\t%.1f\n", metric->name.c_str(), + printf("%-*s\t%-6d\t%-8.1f\t%.1f\n", width, metric->name.c_str(), metric->count, total, avg); } } -- cgit v0.12