Skip to content

Commit 26d8b33

Browse files
namhyungolsajiri
authored andcommitted
perf tools: Consolidate output field handling to hpp format routines
Until now the hpp and sort functions do similar jobs different ways. Since the sort functions converted/wrapped to hpp formats it can do the job in a uniform way. The perf_hpp__sort_list has a list of hpp formats to sort entries and the perf_hpp__list has a list of hpp formats to print output result. To have a backward compatibility, it automatically adds 'overhead' field in front of sort list. And then all of fields in sort list added to the output list (if it's not already there). Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Ingo Molnar <mingo@kernel.org> Link: http://lkml.kernel.org/n/tip-7g3h86woz2sckg3h1lj42ygj@git.kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 043ca38 commit 26d8b33

File tree

6 files changed

+63
-83
lines changed

6 files changed

+63
-83
lines changed

tools/perf/ui/browsers/hists.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,8 @@ static int hist_browser__show_entry(struct hist_browser *browser,
760760
if (!browser->b.navkeypressed)
761761
width += 1;
762762

763-
hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists);
764-
slsmg_write_nstring(s, width);
763+
slsmg_write_nstring("", width);
764+
765765
++row;
766766
++printed;
767767
} else
@@ -1104,27 +1104,32 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser,
11041104
struct hist_entry *he, FILE *fp)
11051105
{
11061106
char s[8192];
1107-
double percent;
11081107
int printed = 0;
11091108
char folded_sign = ' ';
1109+
struct perf_hpp hpp = {
1110+
.buf = s,
1111+
.size = sizeof(s),
1112+
};
1113+
struct perf_hpp_fmt *fmt;
1114+
bool first = true;
1115+
int ret;
11101116

11111117
if (symbol_conf.use_callchain)
11121118
folded_sign = hist_entry__folded(he);
11131119

1114-
hist_entry__sort_snprintf(he, s, sizeof(s), browser->hists);
1115-
percent = (he->stat.period * 100.0) / browser->hists->stats.total_period;
1116-
11171120
if (symbol_conf.use_callchain)
11181121
printed += fprintf(fp, "%c ", folded_sign);
11191122

1120-
printed += fprintf(fp, " %5.2f%%", percent);
1121-
1122-
if (symbol_conf.show_nr_samples)
1123-
printed += fprintf(fp, " %11u", he->stat.nr_events);
1124-
1125-
if (symbol_conf.show_total_period)
1126-
printed += fprintf(fp, " %12" PRIu64, he->stat.period);
1123+
perf_hpp__for_each_format(fmt) {
1124+
if (!first) {
1125+
ret = scnprintf(hpp.buf, hpp.size, " ");
1126+
advance_hpp(&hpp, ret);
1127+
} else
1128+
first = false;
11271129

1130+
ret = fmt->entry(fmt, &hpp, he);
1131+
advance_hpp(&hpp, ret);
1132+
}
11281133
printed += fprintf(fp, "%s\n", rtrim(s));
11291134

11301135
if (folded_sign == '-')

tools/perf/ui/gtk/hists.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
153153
struct perf_hpp_fmt *fmt;
154154
GType col_types[MAX_COLUMNS];
155155
GtkCellRenderer *renderer;
156-
struct sort_entry *se;
157156
GtkTreeStore *store;
158157
struct rb_node *nd;
159158
GtkWidget *view;
@@ -172,16 +171,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
172171
perf_hpp__for_each_format(fmt)
173172
col_types[nr_cols++] = G_TYPE_STRING;
174173

175-
list_for_each_entry(se, &hist_entry__sort_list, list) {
176-
if (se->elide)
177-
continue;
178-
179-
if (se == &sort_sym)
180-
sym_col = nr_cols;
181-
182-
col_types[nr_cols++] = G_TYPE_STRING;
183-
}
184-
185174
store = gtk_tree_store_newv(nr_cols, col_types);
186175

187176
view = gtk_tree_view_new();
@@ -199,16 +188,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
199188
col_idx++, NULL);
200189
}
201190

202-
list_for_each_entry(se, &hist_entry__sort_list, list) {
203-
if (se->elide)
204-
continue;
205-
206-
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
207-
-1, se->se_header,
208-
renderer, "text",
209-
col_idx++, NULL);
210-
}
211-
212191
for (col_idx = 0; col_idx < nr_cols; col_idx++) {
213192
GtkTreeViewColumn *column;
214193

@@ -253,16 +232,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
253232
gtk_tree_store_set(store, &iter, col_idx++, s, -1);
254233
}
255234

256-
list_for_each_entry(se, &hist_entry__sort_list, list) {
257-
if (se->elide)
258-
continue;
259-
260-
se->se_snprintf(h, s, ARRAY_SIZE(s),
261-
hists__col_len(hists, se->se_width_idx));
262-
263-
gtk_tree_store_set(store, &iter, col_idx++, s, -1);
264-
}
265-
266235
if (symbol_conf.use_callchain && sort__has_sym) {
267236
if (callchain_param.mode == CHAIN_GRAPH_REL)
268237
total = h->stat.period;

tools/perf/ui/hist.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ LIST_HEAD(perf_hpp__sort_list);
354354

355355
void perf_hpp__init(void)
356356
{
357+
struct list_head *list;
358+
int i;
359+
360+
for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
361+
INIT_LIST_HEAD(&perf_hpp__format[i].list);
362+
INIT_LIST_HEAD(&perf_hpp__format[i].sort_list);
363+
}
364+
357365
perf_hpp__column_enable(PERF_HPP__OVERHEAD);
358366

359367
if (symbol_conf.show_cpu_utilization) {
@@ -371,6 +379,13 @@ void perf_hpp__init(void)
371379

372380
if (symbol_conf.show_total_period)
373381
perf_hpp__column_enable(PERF_HPP__PERIOD);
382+
383+
/* prepend overhead field for backward compatiblity. */
384+
list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list;
385+
if (list_empty(list))
386+
list_add(list, &perf_hpp__sort_list);
387+
388+
perf_hpp__setup_output_field();
374389
}
375390

376391
void perf_hpp__column_register(struct perf_hpp_fmt *format)
@@ -389,6 +404,17 @@ void perf_hpp__column_enable(unsigned col)
389404
perf_hpp__column_register(&perf_hpp__format[col]);
390405
}
391406

407+
void perf_hpp__setup_output_field(void)
408+
{
409+
struct perf_hpp_fmt *fmt;
410+
411+
/* append sort keys to output field */
412+
perf_hpp__for_each_sort_list(fmt) {
413+
if (list_empty(&fmt->list))
414+
perf_hpp__column_register(fmt);
415+
}
416+
}
417+
392418
int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size,
393419
struct hists *hists)
394420
{

tools/perf/ui/stdio/hist.c

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he,
306306
return hist_entry_callchain__fprintf(he, total_period, left_margin, fp);
307307
}
308308

309-
static int hist_entry__period_snprintf(struct perf_hpp *hpp,
310-
struct hist_entry *he)
309+
static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
311310
{
312311
const char *sep = symbol_conf.field_sep;
313312
struct perf_hpp_fmt *fmt;
@@ -353,8 +352,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
353352
if (size == 0 || size > bfsz)
354353
size = hpp.size = bfsz;
355354

356-
ret = hist_entry__period_snprintf(&hpp, he);
357-
hist_entry__sort_snprintf(he, bf + ret, size - ret, hists);
355+
hist_entry__snprintf(he, &hpp);
358356

359357
ret = fprintf(fp, "%s\n", bf);
360358

@@ -386,28 +384,9 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
386384

387385
init_rem_hits();
388386

389-
if (!show_header)
390-
goto print_entries;
391-
392-
fprintf(fp, "# ");
393-
394-
perf_hpp__for_each_format(fmt) {
395-
if (!first)
396-
fprintf(fp, "%s", sep ?: " ");
397-
else
398-
first = false;
399-
400-
fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
401-
fprintf(fp, "%s", bf);
402-
}
403-
404387
list_for_each_entry(se, &hist_entry__sort_list, list) {
405388
if (se->elide)
406389
continue;
407-
if (sep) {
408-
fprintf(fp, "%c%s", *sep, se->se_header);
409-
continue;
410-
}
411390
width = strlen(se->se_header);
412391
if (symbol_conf.col_width_list_str) {
413392
if (col_width) {
@@ -420,7 +399,21 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
420399
}
421400
if (!hists__new_col_len(hists, se->se_width_idx, width))
422401
width = hists__col_len(hists, se->se_width_idx);
423-
fprintf(fp, " %*s", width, se->se_header);
402+
}
403+
404+
if (!show_header)
405+
goto print_entries;
406+
407+
fprintf(fp, "# ");
408+
409+
perf_hpp__for_each_format(fmt) {
410+
if (!first)
411+
fprintf(fp, "%s", sep ?: " ");
412+
else
413+
first = false;
414+
415+
fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
416+
fprintf(fp, "%s", bf);
424417
}
425418

426419
fprintf(fp, "\n");
@@ -447,20 +440,6 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
447440
fprintf(fp, ".");
448441
}
449442

450-
list_for_each_entry(se, &hist_entry__sort_list, list) {
451-
unsigned int i;
452-
453-
if (se->elide)
454-
continue;
455-
456-
fprintf(fp, " ");
457-
width = hists__col_len(hists, se->se_width_idx);
458-
if (width == 0)
459-
width = strlen(se->se_header);
460-
for (i = 0; i < width; i++)
461-
fprintf(fp, ".");
462-
}
463-
464443
fprintf(fp, "\n");
465444
if (max_rows && ++nr_rows >= max_rows)
466445
goto out;

tools/perf/util/hist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static int hist_entry__sort(struct hist_entry *a, struct hist_entry *b)
569569
struct perf_hpp_fmt *fmt;
570570
int64_t cmp = 0;
571571

572-
perf_hpp__for_each_format(fmt) {
572+
perf_hpp__for_each_sort_list(fmt) {
573573
cmp = fmt->sort(a, b);
574574
if (cmp)
575575
break;

tools/perf/util/hist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ void perf_hpp__init(void);
196196
void perf_hpp__column_register(struct perf_hpp_fmt *format);
197197
void perf_hpp__column_enable(unsigned col);
198198
void perf_hpp__register_sort_field(struct perf_hpp_fmt *format);
199+
void perf_hpp__setup_output_field(void);
199200

200201
typedef u64 (*hpp_field_fn)(struct hist_entry *he);
201202
typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);

0 commit comments

Comments
 (0)