Skip to content

Commit c3a3800

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo-4.14-20170728' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes for 4.14 from Arnaldo Carvalho de Melo: New features: - Add PERF_SAMPLE_CALLCHAIN and PERF_RECORD_MMAP[2] to 'perf data' CTF conversion, allowing CTF trace visualization tools to show callchains and to resolve symbols (Geneviève Bastien) Improvements: - Use group read for event groups in 'perf stat', reducing overhead when groups are defined in the event specification, i.e. when using {} to enclose a list of events, asking them to be read at the same time, e.g.: "perf stat -e '{cycles,instructions}'" (Jiri Olsa) Fixes: - Do not overwrite perf_sample->weight in 'perf annotate' when processing samples, use whatever came from the kernel when perf_event_attr.sample_type has PERF_SAMPLE_WEIGHT set or just handle its default value, 0, when that is not set and "weight" is one of the sort orders chosen (Arnaldo Carvalho de Melo) - 'perf annotate --show-total-period' fixes: - TUI should show period, not nr_samples - Set appropriate column width for period/percent - Fix the column header to show "Period" when when that is what is being asked for (Taeung Song, Arnaldo Carvalho de Melo) - Use default sort if evlist is empty, fixing pipe mode (David Carrillo-Cisneros) Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
2 parents f5db340 + 6b7007a commit c3a3800

File tree

13 files changed

+334
-32
lines changed

13 files changed

+334
-32
lines changed

tools/perf/builtin-annotate.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
177177
*/
178178
process_branch_stack(sample->branch_stack, al, sample);
179179

180-
sample->weight = 1;
181-
182180
he = hists__add_entry(hists, al, NULL, NULL, NULL, sample, true);
183181
if (he == NULL)
184182
return -ENOMEM;

tools/perf/builtin-data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static int cmd_data_convert(int argc, const char **argv)
6969
};
7070

7171
#ifndef HAVE_LIBBABELTRACE_SUPPORT
72-
pr_err("No conversion support compiled in.\n");
72+
pr_err("No conversion support compiled in. perf should be compiled with environment variables LIBBABELTRACE=1 and LIBBABELTRACE_DIR=/path/to/libbabeltrace/\n");
7373
return -1;
7474
#endif
7575

tools/perf/builtin-stat.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,20 @@ static void perf_stat__reset_stats(void)
213213
static int create_perf_stat_counter(struct perf_evsel *evsel)
214214
{
215215
struct perf_event_attr *attr = &evsel->attr;
216+
struct perf_evsel *leader = evsel->leader;
216217

217-
if (stat_config.scale)
218+
if (stat_config.scale) {
218219
attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
219220
PERF_FORMAT_TOTAL_TIME_RUNNING;
221+
}
222+
223+
/*
224+
* The event is part of non trivial group, let's enable
225+
* the group read (for leader) and ID retrieval for all
226+
* members.
227+
*/
228+
if (leader->nr_members > 1)
229+
attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP;
220230

221231
attr->inherit = !no_inherit;
222232

@@ -333,13 +343,21 @@ static int read_counter(struct perf_evsel *counter)
333343
struct perf_counts_values *count;
334344

335345
count = perf_counts(counter->counts, cpu, thread);
336-
if (perf_evsel__read(counter, cpu, thread, count)) {
346+
347+
/*
348+
* The leader's group read loads data into its group members
349+
* (via perf_evsel__read_counter) and sets threir count->loaded.
350+
*/
351+
if (!count->loaded &&
352+
perf_evsel__read_counter(counter, cpu, thread)) {
337353
counter->counts->scaled = -1;
338354
perf_counts(counter->counts, cpu, thread)->ena = 0;
339355
perf_counts(counter->counts, cpu, thread)->run = 0;
340356
return -1;
341357
}
342358

359+
count->loaded = false;
360+
343361
if (STAT_RECORD) {
344362
if (perf_evsel__write_stat_event(counter, cpu, thread, count)) {
345363
pr_err("failed to write stat event\n");
@@ -559,6 +577,11 @@ static int store_counter_ids(struct perf_evsel *counter)
559577
return __store_counter_ids(counter, cpus, threads);
560578
}
561579

580+
static bool perf_evsel__should_store_id(struct perf_evsel *counter)
581+
{
582+
return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID;
583+
}
584+
562585
static int __run_perf_stat(int argc, const char **argv)
563586
{
564587
int interval = stat_config.interval;
@@ -631,7 +654,8 @@ static int __run_perf_stat(int argc, const char **argv)
631654
if (l > unit_width)
632655
unit_width = l;
633656

634-
if (STAT_RECORD && store_counter_ids(counter))
657+
if (perf_evsel__should_store_id(counter) &&
658+
store_counter_ids(counter))
635659
return -1;
636660
}
637661

tools/perf/ui/browsers/annotate.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include <sys/ttydefaults.h>
1818

1919
struct disasm_line_samples {
20-
double percent;
21-
u64 nr;
20+
double percent;
21+
struct sym_hist_entry he;
2222
};
2323

2424
#define IPC_WIDTH 6
@@ -110,11 +110,12 @@ static int annotate_browser__set_jumps_percent_color(struct annotate_browser *br
110110

111111
static int annotate_browser__pcnt_width(struct annotate_browser *ab)
112112
{
113-
int w = 7 * ab->nr_events;
113+
return (annotate_browser__opts.show_total_period ? 12 : 7) * ab->nr_events;
114+
}
114115

115-
if (ab->have_cycles)
116-
w += IPC_WIDTH + CYCLES_WIDTH;
117-
return w;
116+
static int annotate_browser__cycles_width(struct annotate_browser *ab)
117+
{
118+
return ab->have_cycles ? IPC_WIDTH + CYCLES_WIDTH : 0;
118119
}
119120

120121
static void annotate_browser__write(struct ui_browser *browser, void *entry, int row)
@@ -127,7 +128,8 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
127128
(!current_entry || (browser->use_navkeypressed &&
128129
!browser->navkeypressed)));
129130
int width = browser->width, printed;
130-
int i, pcnt_width = annotate_browser__pcnt_width(ab);
131+
int i, pcnt_width = annotate_browser__pcnt_width(ab),
132+
cycles_width = annotate_browser__cycles_width(ab);
131133
double percent_max = 0.0;
132134
char bf[256];
133135
bool show_title = false;
@@ -151,8 +153,8 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
151153
bdl->samples[i].percent,
152154
current_entry);
153155
if (annotate_browser__opts.show_total_period) {
154-
ui_browser__printf(browser, "%6" PRIu64 " ",
155-
bdl->samples[i].nr);
156+
ui_browser__printf(browser, "%11" PRIu64 " ",
157+
bdl->samples[i].he.period);
156158
} else {
157159
ui_browser__printf(browser, "%6.2f ",
158160
bdl->samples[i].percent);
@@ -162,9 +164,11 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
162164
ui_browser__set_percent_color(browser, 0, current_entry);
163165

164166
if (!show_title)
165-
ui_browser__write_nstring(browser, " ", 7 * ab->nr_events);
166-
else
167-
ui_browser__printf(browser, "%*s", 7, "Percent");
167+
ui_browser__write_nstring(browser, " ", pcnt_width);
168+
else {
169+
ui_browser__printf(browser, "%*s", pcnt_width,
170+
annotate_browser__opts.show_total_period ? "Period" : "Percent");
171+
}
168172
}
169173
if (ab->have_cycles) {
170174
if (dl->ipc)
@@ -190,7 +194,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
190194
width += 1;
191195

192196
if (!*dl->line)
193-
ui_browser__write_nstring(browser, " ", width - pcnt_width);
197+
ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width);
194198
else if (dl->offset == -1) {
195199
if (dl->line_nr && annotate_browser__opts.show_linenr)
196200
printed = scnprintf(bf, sizeof(bf), "%-*d ",
@@ -199,7 +203,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
199203
printed = scnprintf(bf, sizeof(bf), "%*s ",
200204
ab->addr_width, " ");
201205
ui_browser__write_nstring(browser, bf, printed);
202-
ui_browser__write_nstring(browser, dl->line, width - printed - pcnt_width + 1);
206+
ui_browser__write_nstring(browser, dl->line, width - printed - pcnt_width - cycles_width + 1);
203207
} else {
204208
u64 addr = dl->offset;
205209
int color = -1;
@@ -256,7 +260,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
256260
}
257261

258262
disasm_line__scnprintf(dl, bf, sizeof(bf), !annotate_browser__opts.use_offset);
259-
ui_browser__write_nstring(browser, bf, width - pcnt_width - 3 - printed);
263+
ui_browser__write_nstring(browser, bf, width - pcnt_width - cycles_width - 3 - printed);
260264
}
261265

262266
if (current_entry)
@@ -457,7 +461,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
457461
pos->offset,
458462
next ? next->offset : len,
459463
&path, &sample);
460-
bpos->samples[i].nr = sample.nr_samples;
464+
bpos->samples[i].he = sample;
461465

462466
if (max_percent < bpos->samples[i].percent)
463467
max_percent = bpos->samples[i].percent;

tools/perf/util/annotate.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,9 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
963963
u64 period = 0;
964964

965965
while (offset < end) {
966-
hits += h->addr[offset++].nr_samples;
967-
period += h->addr[offset++].period;
966+
hits += h->addr[offset].nr_samples;
967+
period += h->addr[offset].period;
968+
++offset;
968969
}
969970

970971
if (h->nr_samples) {
@@ -1142,7 +1143,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
11421143
color = get_percent_color(percent);
11431144

11441145
if (symbol_conf.show_total_period)
1145-
color_fprintf(stdout, color, " %7" PRIu64,
1146+
color_fprintf(stdout, color, " %11" PRIu64,
11461147
sample.period);
11471148
else
11481149
color_fprintf(stdout, color, " %7.2f", percent);
@@ -1165,7 +1166,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
11651166
} else if (max_lines && printed >= max_lines)
11661167
return 1;
11671168
else {
1168-
int width = 8;
1169+
int width = symbol_conf.show_total_period ? 12 : 8;
11691170

11701171
if (queue)
11711172
return -1;
@@ -1806,7 +1807,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
18061807
int printed = 2, queue_len = 0;
18071808
int more = 0;
18081809
u64 len;
1809-
int width = 8;
1810+
int width = symbol_conf.show_total_period ? 12 : 8;
18101811
int graph_dotted_len;
18111812

18121813
filename = strdup(dso->long_name);

tools/perf/util/counts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct perf_counts_values {
1212
};
1313
u64 values[3];
1414
};
15+
bool loaded;
1516
};
1617

1718
struct perf_counts {

0 commit comments

Comments
 (0)