aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2012-09-02 22:53:07 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-09-08 12:19:55 -0400
commit9ffad987ff565999d91fc2783dd77f08094a743b (patch)
treed257da6adbc2d099fe1b224d2432d3c1f8e94e21 /tools/perf/ui
parentea251d51d2c7d7233790123227f787c477f567f5 (diff)
perf hists: Handle field separator properly
When a field separator is given, the output format doesn't need to be fancy like aligning to column length, coloring the percent value and so on. And since there's a slight difference to normal format, fix it not to break backward compatibility. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1346640790-17197-3-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui')
-rw-r--r--tools/perf/ui/hist.c74
-rw-r--r--tools/perf/ui/stdio/hist.c3
2 files changed, 50 insertions, 27 deletions
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 8ccd1f2330d1..009adf206c81 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -8,10 +8,9 @@
8/* hist period print (hpp) functions */ 8/* hist period print (hpp) functions */
9static int hpp__header_overhead(struct perf_hpp *hpp) 9static int hpp__header_overhead(struct perf_hpp *hpp)
10{ 10{
11 if (hpp->ptr) 11 const char *fmt = hpp->ptr ? "Baseline" : "Overhead";
12 return scnprintf(hpp->buf, hpp->size, "Baseline"); 12
13 else 13 return scnprintf(hpp->buf, hpp->size, fmt);
14 return scnprintf(hpp->buf, hpp->size, "Overhead");
15} 14}
16 15
17static int hpp__width_overhead(struct perf_hpp *hpp __used) 16static int hpp__width_overhead(struct perf_hpp *hpp __used)
@@ -40,6 +39,7 @@ static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he)
40static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) 39static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he)
41{ 40{
42 double percent = 100.0 * he->period / hpp->total_period; 41 double percent = 100.0 * he->period / hpp->total_period;
42 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %5.2f%%";
43 43
44 if (hpp->ptr) { 44 if (hpp->ptr) {
45 struct hists *old_hists = hpp->ptr; 45 struct hists *old_hists = hpp->ptr;
@@ -52,12 +52,14 @@ static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he)
52 percent = 0.0; 52 percent = 0.0;
53 } 53 }
54 54
55 return scnprintf(hpp->buf, hpp->size, " %5.2f%%", percent); 55 return scnprintf(hpp->buf, hpp->size, fmt, percent);
56} 56}
57 57
58static int hpp__header_overhead_sys(struct perf_hpp *hpp) 58static int hpp__header_overhead_sys(struct perf_hpp *hpp)
59{ 59{
60 return scnprintf(hpp->buf, hpp->size, " sys "); 60 const char *fmt = symbol_conf.field_sep ? "%s" : "%6s";
61
62 return scnprintf(hpp->buf, hpp->size, fmt, "sys");
61} 63}
62 64
63static int hpp__width_overhead_sys(struct perf_hpp *hpp __used) 65static int hpp__width_overhead_sys(struct perf_hpp *hpp __used)
@@ -74,12 +76,16 @@ static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
74static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) 76static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
75{ 77{
76 double percent = 100.0 * he->period_sys / hpp->total_period; 78 double percent = 100.0 * he->period_sys / hpp->total_period;
77 return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent); 79 const char *fmt = symbol_conf.field_sep ? "%.2f" : "%5.2f%%";
80
81 return scnprintf(hpp->buf, hpp->size, fmt, percent);
78} 82}
79 83
80static int hpp__header_overhead_us(struct perf_hpp *hpp) 84static int hpp__header_overhead_us(struct perf_hpp *hpp)
81{ 85{
82 return scnprintf(hpp->buf, hpp->size, " user "); 86 const char *fmt = symbol_conf.field_sep ? "%s" : "%6s";
87
88 return scnprintf(hpp->buf, hpp->size, fmt, "user");
83} 89}
84 90
85static int hpp__width_overhead_us(struct perf_hpp *hpp __used) 91static int hpp__width_overhead_us(struct perf_hpp *hpp __used)
@@ -96,7 +102,9 @@ static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
96static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) 102static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
97{ 103{
98 double percent = 100.0 * he->period_us / hpp->total_period; 104 double percent = 100.0 * he->period_us / hpp->total_period;
99 return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent); 105 const char *fmt = symbol_conf.field_sep ? "%.2f" : "%5.2f%%";
106
107 return scnprintf(hpp->buf, hpp->size, fmt, percent);
100} 108}
101 109
102static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp) 110static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp)
@@ -120,7 +128,9 @@ static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp,
120 struct hist_entry *he) 128 struct hist_entry *he)
121{ 129{
122 double percent = 100.0 * he->period_guest_sys / hpp->total_period; 130 double percent = 100.0 * he->period_guest_sys / hpp->total_period;
123 return scnprintf(hpp->buf, hpp->size, " %5.2f%% ", percent); 131 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %5.2f%% ";
132
133 return scnprintf(hpp->buf, hpp->size, fmt, percent);
124} 134}
125 135
126static int hpp__header_overhead_guest_us(struct perf_hpp *hpp) 136static int hpp__header_overhead_guest_us(struct perf_hpp *hpp)
@@ -144,12 +154,16 @@ static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp,
144 struct hist_entry *he) 154 struct hist_entry *he)
145{ 155{
146 double percent = 100.0 * he->period_guest_us / hpp->total_period; 156 double percent = 100.0 * he->period_guest_us / hpp->total_period;
147 return scnprintf(hpp->buf, hpp->size, " %5.2f%% ", percent); 157 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %5.2f%% ";
158
159 return scnprintf(hpp->buf, hpp->size, fmt, percent);
148} 160}
149 161
150static int hpp__header_samples(struct perf_hpp *hpp) 162static int hpp__header_samples(struct perf_hpp *hpp)
151{ 163{
152 return scnprintf(hpp->buf, hpp->size, " Samples "); 164 const char *fmt = symbol_conf.field_sep ? "%s" : "%11s";
165
166 return scnprintf(hpp->buf, hpp->size, fmt, "Samples");
153} 167}
154 168
155static int hpp__width_samples(struct perf_hpp *hpp __used) 169static int hpp__width_samples(struct perf_hpp *hpp __used)
@@ -159,12 +173,16 @@ static int hpp__width_samples(struct perf_hpp *hpp __used)
159 173
160static int hpp__entry_samples(struct perf_hpp *hpp, struct hist_entry *he) 174static int hpp__entry_samples(struct perf_hpp *hpp, struct hist_entry *he)
161{ 175{
162 return scnprintf(hpp->buf, hpp->size, "%11" PRIu64, he->nr_events); 176 const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%11" PRIu64;
177
178 return scnprintf(hpp->buf, hpp->size, fmt, he->nr_events);
163} 179}
164 180
165static int hpp__header_period(struct perf_hpp *hpp) 181static int hpp__header_period(struct perf_hpp *hpp)
166{ 182{
167 return scnprintf(hpp->buf, hpp->size, " Period "); 183 const char *fmt = symbol_conf.field_sep ? "%s" : "%12s";
184
185 return scnprintf(hpp->buf, hpp->size, fmt, "Period");
168} 186}
169 187
170static int hpp__width_period(struct perf_hpp *hpp __used) 188static int hpp__width_period(struct perf_hpp *hpp __used)
@@ -174,12 +192,16 @@ static int hpp__width_period(struct perf_hpp *hpp __used)
174 192
175static int hpp__entry_period(struct perf_hpp *hpp, struct hist_entry *he) 193static int hpp__entry_period(struct perf_hpp *hpp, struct hist_entry *he)
176{ 194{
177 return scnprintf(hpp->buf, hpp->size, "%12" PRIu64, he->period); 195 const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64;
196
197 return scnprintf(hpp->buf, hpp->size, fmt, he->period);
178} 198}
179 199
180static int hpp__header_delta(struct perf_hpp *hpp) 200static int hpp__header_delta(struct perf_hpp *hpp)
181{ 201{
182 return scnprintf(hpp->buf, hpp->size, " Delta "); 202 const char *fmt = symbol_conf.field_sep ? "%s" : "%7s";
203
204 return scnprintf(hpp->buf, hpp->size, fmt, "Delta");
183} 205}
184 206
185static int hpp__width_delta(struct perf_hpp *hpp __used) 207static int hpp__width_delta(struct perf_hpp *hpp __used)
@@ -193,7 +215,8 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he)
193 u64 old_total, new_total; 215 u64 old_total, new_total;
194 double old_percent = 0, new_percent = 0; 216 double old_percent = 0, new_percent = 0;
195 double diff; 217 double diff;
196 char buf[32]; 218 const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s";
219 char buf[32] = " ";
197 220
198 old_total = pair_hists->stats.total_period; 221 old_total = pair_hists->stats.total_period;
199 if (old_total > 0 && he->pair) 222 if (old_total > 0 && he->pair)
@@ -204,11 +227,10 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he)
204 new_percent = 100.0 * he->period / new_total; 227 new_percent = 100.0 * he->period / new_total;
205 228
206 diff = new_percent - old_percent; 229 diff = new_percent - old_percent;
207 if (fabs(diff) < 0.01) 230 if (fabs(diff) >= 0.01)
208 return scnprintf(hpp->buf, hpp->size, " "); 231 scnprintf(buf, sizeof(buf), "%+4.2F%%", diff);
209 232
210 scnprintf(buf, sizeof(buf), "%+4.2F%%", diff); 233 return scnprintf(hpp->buf, hpp->size, fmt, buf);
211 return scnprintf(hpp->buf, hpp->size, "%7.7s", buf);
212} 234}
213 235
214static int hpp__header_displ(struct perf_hpp *hpp) 236static int hpp__header_displ(struct perf_hpp *hpp)
@@ -223,13 +245,13 @@ static int hpp__width_displ(struct perf_hpp *hpp __used)
223 245
224static int hpp__entry_displ(struct perf_hpp *hpp, struct hist_entry *he __used) 246static int hpp__entry_displ(struct perf_hpp *hpp, struct hist_entry *he __used)
225{ 247{
226 char buf[32]; 248 const char *fmt = symbol_conf.field_sep ? "%s" : "%6.6s";
249 char buf[32] = " ";
227 250
228 if (!hpp->displacement) 251 if (hpp->displacement)
229 return scnprintf(hpp->buf, hpp->size, " "); 252 scnprintf(buf, sizeof(buf), "%+4ld", hpp->displacement);
230 253
231 scnprintf(buf, sizeof(buf), "%+4ld", hpp->displacement); 254 return scnprintf(hpp->buf, hpp->size, fmt, buf);
232 return scnprintf(hpp->buf, hpp->size, "%6.6s", buf);
233} 255}
234 256
235#define HPP__COLOR_PRINT_FNS(_name) \ 257#define HPP__COLOR_PRINT_FNS(_name) \
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 4228b4c6b72d..882461a42830 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -319,11 +319,12 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
319 .displacement = displacement, 319 .displacement = displacement,
320 .ptr = pair_hists, 320 .ptr = pair_hists,
321 }; 321 };
322 bool color = !symbol_conf.field_sep;
322 323
323 if (size == 0 || size > sizeof(bf)) 324 if (size == 0 || size > sizeof(bf))
324 size = hpp.size = sizeof(bf); 325 size = hpp.size = sizeof(bf);
325 326
326 ret = hist_entry__period_snprintf(&hpp, he, true); 327 ret = hist_entry__period_snprintf(&hpp, he, color);
327 hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); 328 hist_entry__sort_snprintf(he, bf + ret, size - ret, hists);
328 329
329 ret = fprintf(fp, "%s\n", bf); 330 ret = fprintf(fp, "%s\n", bf);