Skip to content

Commit 1ecd445

Browse files
namhyungacmel
authored andcommitted
perf tools: Add name field into perf_hpp_fmt
It makes the code a bit simpler and easier to debug IMHO. I guess it can also remove similar code in perf diff, but let's keep it for a future work. :) Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1406785662-5534-7-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent cf59002 commit 1ecd445

4 files changed

Lines changed: 66 additions & 81 deletions

File tree

‎tools/perf/ui/gtk/hists.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
207207
if (perf_hpp__is_sort_entry(fmt))
208208
sym_col = col_idx;
209209

210-
fmt->header(fmt, &hpp, hists_to_evsel(hists));
211-
212210
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
213-
-1, ltrim(s),
211+
-1, fmt->name,
214212
renderer, "markup",
215213
col_idx++, NULL);
216214
}

‎tools/perf/ui/hist.c‎

Lines changed: 61 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -209,29 +209,26 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
209209
return ret;
210210
}
211211

212-
#define __HPP_WIDTH_FN(_type, _str) \
213-
static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \
214-
struct perf_hpp *hpp __maybe_unused, \
215-
struct perf_evsel *evsel) \
216-
{ \
217-
int len = fmt->user_len ?: fmt->len; \
218-
\
219-
if (symbol_conf.event_group) \
220-
len = max(len, evsel->nr_members * fmt->len); \
221-
\
222-
if (len < (int)strlen(_str)) \
223-
len = strlen(_str); \
224-
\
225-
return len; \
226-
}
227-
228-
#define __HPP_HEADER_FN(_type, _str) \
229-
static int hpp__header_##_type(struct perf_hpp_fmt *fmt, \
230-
struct perf_hpp *hpp, \
231-
struct perf_evsel *evsel) \
232-
{ \
233-
int len = hpp__width_##_type(fmt, hpp, evsel); \
234-
return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
212+
static int hpp__width_fn(struct perf_hpp_fmt *fmt,
213+
struct perf_hpp *hpp __maybe_unused,
214+
struct perf_evsel *evsel)
215+
{
216+
int len = fmt->user_len ?: fmt->len;
217+
218+
if (symbol_conf.event_group)
219+
len = max(len, evsel->nr_members * fmt->len);
220+
221+
if (len < (int)strlen(fmt->name))
222+
len = strlen(fmt->name);
223+
224+
return len;
225+
}
226+
227+
static int hpp__header_fn(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
228+
struct perf_evsel *evsel)
229+
{
230+
int len = hpp__width_fn(fmt, hpp, evsel);
231+
return scnprintf(hpp->buf, hpp->size, "%*s", len, fmt->name);
235232
}
236233

237234
static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
@@ -337,86 +334,80 @@ static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \
337334
}
338335

339336

340-
#define HPP_PERCENT_FNS(_type, _str, _field) \
341-
__HPP_WIDTH_FN(_type, _str) \
342-
__HPP_HEADER_FN(_type, _str) \
337+
#define HPP_PERCENT_FNS(_type, _field) \
343338
__HPP_COLOR_PERCENT_FN(_type, _field) \
344339
__HPP_ENTRY_PERCENT_FN(_type, _field) \
345340
__HPP_SORT_FN(_type, _field)
346341

347-
#define HPP_PERCENT_ACC_FNS(_type, _str, _field) \
348-
__HPP_WIDTH_FN(_type, _str) \
349-
__HPP_HEADER_FN(_type, _str) \
342+
#define HPP_PERCENT_ACC_FNS(_type, _field) \
350343
__HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
351344
__HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
352345
__HPP_SORT_ACC_FN(_type, _field)
353346

354-
#define HPP_RAW_FNS(_type, _str, _field) \
355-
__HPP_WIDTH_FN(_type, _str) \
356-
__HPP_HEADER_FN(_type, _str) \
347+
#define HPP_RAW_FNS(_type, _field) \
357348
__HPP_ENTRY_RAW_FN(_type, _field) \
358349
__HPP_SORT_RAW_FN(_type, _field)
359350

360-
__HPP_WIDTH_FN(overhead_self, "Self")
361-
__HPP_HEADER_FN(overhead_self, "Self")
351+
HPP_PERCENT_FNS(overhead, period)
352+
HPP_PERCENT_FNS(overhead_sys, period_sys)
353+
HPP_PERCENT_FNS(overhead_us, period_us)
354+
HPP_PERCENT_FNS(overhead_guest_sys, period_guest_sys)
355+
HPP_PERCENT_FNS(overhead_guest_us, period_guest_us)
356+
HPP_PERCENT_ACC_FNS(overhead_acc, period)
362357

363-
HPP_PERCENT_FNS(overhead, "Overhead", period)
364-
HPP_PERCENT_FNS(overhead_sys, "sys", period_sys)
365-
HPP_PERCENT_FNS(overhead_us, "usr", period_us)
366-
HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys)
367-
HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us)
368-
HPP_PERCENT_ACC_FNS(overhead_acc, "Children", period)
369-
370-
HPP_RAW_FNS(samples, "Samples", nr_events)
371-
HPP_RAW_FNS(period, "Period", period)
358+
HPP_RAW_FNS(samples, nr_events)
359+
HPP_RAW_FNS(period, period)
372360

373361
static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused,
374362
struct hist_entry *b __maybe_unused)
375363
{
376364
return 0;
377365
}
378366

379-
#define HPP__COLOR_PRINT_FNS(_name) \
367+
#define HPP__COLOR_PRINT_FNS(_name, _fn) \
380368
{ \
381-
.header = hpp__header_ ## _name, \
382-
.width = hpp__width_ ## _name, \
383-
.color = hpp__color_ ## _name, \
384-
.entry = hpp__entry_ ## _name, \
369+
.name = _name, \
370+
.header = hpp__header_fn, \
371+
.width = hpp__width_fn, \
372+
.color = hpp__color_ ## _fn, \
373+
.entry = hpp__entry_ ## _fn, \
385374
.cmp = hpp__nop_cmp, \
386375
.collapse = hpp__nop_cmp, \
387-
.sort = hpp__sort_ ## _name, \
376+
.sort = hpp__sort_ ## _fn, \
388377
}
389378

390-
#define HPP__COLOR_ACC_PRINT_FNS(_name) \
379+
#define HPP__COLOR_ACC_PRINT_FNS(_name, _fn) \
391380
{ \
392-
.header = hpp__header_ ## _name, \
393-
.width = hpp__width_ ## _name, \
394-
.color = hpp__color_ ## _name, \
395-
.entry = hpp__entry_ ## _name, \
381+
.name = _name, \
382+
.header = hpp__header_fn, \
383+
.width = hpp__width_fn, \
384+
.color = hpp__color_ ## _fn, \
385+
.entry = hpp__entry_ ## _fn, \
396386
.cmp = hpp__nop_cmp, \
397387
.collapse = hpp__nop_cmp, \
398-
.sort = hpp__sort_ ## _name, \
388+
.sort = hpp__sort_ ## _fn, \
399389
}
400390

401-
#define HPP__PRINT_FNS(_name) \
391+
#define HPP__PRINT_FNS(_name, _fn) \
402392
{ \
403-
.header = hpp__header_ ## _name, \
404-
.width = hpp__width_ ## _name, \
405-
.entry = hpp__entry_ ## _name, \
393+
.name = _name, \
394+
.header = hpp__header_fn, \
395+
.width = hpp__width_fn, \
396+
.entry = hpp__entry_ ## _fn, \
406397
.cmp = hpp__nop_cmp, \
407398
.collapse = hpp__nop_cmp, \
408-
.sort = hpp__sort_ ## _name, \
399+
.sort = hpp__sort_ ## _fn, \
409400
}
410401

411402
struct perf_hpp_fmt perf_hpp__format[] = {
412-
HPP__COLOR_PRINT_FNS(overhead),
413-
HPP__COLOR_PRINT_FNS(overhead_sys),
414-
HPP__COLOR_PRINT_FNS(overhead_us),
415-
HPP__COLOR_PRINT_FNS(overhead_guest_sys),
416-
HPP__COLOR_PRINT_FNS(overhead_guest_us),
417-
HPP__COLOR_ACC_PRINT_FNS(overhead_acc),
418-
HPP__PRINT_FNS(samples),
419-
HPP__PRINT_FNS(period)
403+
HPP__COLOR_PRINT_FNS("Overhead", overhead),
404+
HPP__COLOR_PRINT_FNS("sys", overhead_sys),
405+
HPP__COLOR_PRINT_FNS("usr", overhead_us),
406+
HPP__COLOR_PRINT_FNS("guest sys", overhead_guest_sys),
407+
HPP__COLOR_PRINT_FNS("guest usr", overhead_guest_us),
408+
HPP__COLOR_ACC_PRINT_FNS("Children", overhead_acc),
409+
HPP__PRINT_FNS("Samples", samples),
410+
HPP__PRINT_FNS("Period", period)
420411
};
421412

422413
LIST_HEAD(perf_hpp__list);
@@ -466,11 +457,7 @@ void perf_hpp__init(void)
466457

467458
if (symbol_conf.cumulate_callchain) {
468459
perf_hpp__column_enable(PERF_HPP__OVERHEAD_ACC);
469-
470-
perf_hpp__format[PERF_HPP__OVERHEAD].header =
471-
hpp__header_overhead_self;
472-
perf_hpp__format[PERF_HPP__OVERHEAD].width =
473-
hpp__width_overhead_self;
460+
perf_hpp__format[PERF_HPP__OVERHEAD].name = "Self";
474461
}
475462

476463
perf_hpp__column_enable(PERF_HPP__OVERHEAD);
@@ -536,8 +523,7 @@ void perf_hpp__cancel_cumulate(void)
536523
return;
537524

538525
perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC);
539-
perf_hpp__format[PERF_HPP__OVERHEAD].header = hpp__header_overhead;
540-
perf_hpp__format[PERF_HPP__OVERHEAD].width = hpp__width_overhead;
526+
perf_hpp__format[PERF_HPP__OVERHEAD].name = "Overhead";
541527
}
542528

543529
void perf_hpp__setup_output_field(void)

‎tools/perf/util/hist.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ struct perf_hpp {
192192
};
193193

194194
struct perf_hpp_fmt {
195+
const char *name;
195196
int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
196197
struct perf_evsel *evsel);
197198
int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,

‎tools/perf/util/sort.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,7 @@ void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists)
12061206
return;
12071207

12081208
hse = container_of(fmt, struct hpp_sort_entry, hpp);
1209-
hists__new_col_len(hists, hse->se->se_width_idx,
1210-
strlen(hse->se->se_header));
1209+
hists__new_col_len(hists, hse->se->se_width_idx, strlen(fmt->name));
12111210
}
12121211

12131212
static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
@@ -1221,7 +1220,7 @@ static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
12211220
if (!len)
12221221
len = hists__col_len(&evsel->hists, hse->se->se_width_idx);
12231222

1224-
return scnprintf(hpp->buf, hpp->size, "%-*.*s", len, len, hse->se->se_header);
1223+
return scnprintf(hpp->buf, hpp->size, "%-*.*s", len, len, fmt->name);
12251224
}
12261225

12271226
static int __sort__hpp_width(struct perf_hpp_fmt *fmt,
@@ -1265,6 +1264,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd)
12651264
}
12661265

12671266
hse->se = sd->entry;
1267+
hse->hpp.name = sd->entry->se_header;
12681268
hse->hpp.header = __sort__hpp_header;
12691269
hse->hpp.width = __sort__hpp_width;
12701270
hse->hpp.entry = __sort__hpp_entry;

0 commit comments

Comments
 (0)