Skip to content

Commit ec4212d

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: Infrastructure fixes and changes: * Fix off-by-one bugs in map->end handling (Stephane Eranian) * Fix off-by-one bug in maps__find(), also related to map->end handling (Namhyung Kim) * Make struct symbol->end be the first addr after the symbol range, to make it match the convention used for struct map->end. (Arnaldo Carvalho de Melo) * Fix perf_evlist__add_pollfd() error handling in 'perf kvm stat live' (Jiri Olsa) * Fix python test build by moving callchain_param to an object linked into the python binding (Jiri Olsa) * Do not include a struct hists per perf_evsel, untangling the histogram code from perf_evsel, to pave the way for exporting a minimalistic tools/lib/api/perf/ library usable by tools/perf and initially by the rasd daemon being developed by Borislav Petkov, Robert Richter and Jean Pihet. (Arnaldo Carvalho de Melo) * Make perf_evlist__open(evlist, NULL, NULL), i.e. without cpu and thread maps mean syswide monitoring, reducing the boilerplate for tools that only want system wide mode. (Arnaldo Carvalho de Melo) Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
2 parents 7765490 + 2c241bd commit ec4212d

35 files changed

+392
-229
lines changed

tools/perf/builtin-annotate.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
5151
struct addr_location *al,
5252
struct perf_annotate *ann)
5353
{
54+
struct hists *hists = evsel__hists(evsel);
5455
struct hist_entry *he;
5556
int ret;
5657

@@ -66,13 +67,12 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
6667
return 0;
6768
}
6869

69-
he = __hists__add_entry(&evsel->hists, al, NULL, NULL, NULL, 1, 1, 0,
70-
true);
70+
he = __hists__add_entry(hists, al, NULL, NULL, NULL, 1, 1, 0, true);
7171
if (he == NULL)
7272
return -ENOMEM;
7373

7474
ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
75-
hists__inc_nr_samples(&evsel->hists, true);
75+
hists__inc_nr_samples(hists, true);
7676
return ret;
7777
}
7878

@@ -214,6 +214,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
214214

215215
if (dump_trace) {
216216
perf_session__fprintf_nr_events(session, stdout);
217+
perf_evlist__fprintf_nr_events(session->evlist, stdout);
217218
goto out;
218219
}
219220

@@ -225,7 +226,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
225226

226227
total_nr_samples = 0;
227228
evlist__for_each(session->evlist, pos) {
228-
struct hists *hists = &pos->hists;
229+
struct hists *hists = evsel__hists(pos);
229230
u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
230231

231232
if (nr_samples > 0) {
@@ -325,7 +326,10 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
325326
"Show event group information together"),
326327
OPT_END()
327328
};
328-
int ret;
329+
int ret = hists__init();
330+
331+
if (ret < 0)
332+
return ret;
329333

330334
argc = parse_options(argc, argv, options, annotate_usage, 0);
331335

tools/perf/builtin-diff.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,15 @@ static int diff__process_sample_event(struct perf_tool *tool __maybe_unused,
327327
struct machine *machine)
328328
{
329329
struct addr_location al;
330+
struct hists *hists = evsel__hists(evsel);
330331

331332
if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
332333
pr_warning("problem processing %d event, skipping it.\n",
333334
event->header.type);
334335
return -1;
335336
}
336337

337-
if (hists__add_entry(&evsel->hists, &al, sample->period,
338+
if (hists__add_entry(hists, &al, sample->period,
338339
sample->weight, sample->transaction)) {
339340
pr_warning("problem incrementing symbol period, skipping event\n");
340341
return -1;
@@ -346,9 +347,9 @@ static int diff__process_sample_event(struct perf_tool *tool __maybe_unused,
346347
* hists__output_resort() and precompute needs the total
347348
* period in order to sort entries by percentage delta.
348349
*/
349-
evsel->hists.stats.total_period += sample->period;
350+
hists->stats.total_period += sample->period;
350351
if (!al.filtered)
351-
evsel->hists.stats.total_non_filtered_period += sample->period;
352+
hists->stats.total_non_filtered_period += sample->period;
352353

353354
return 0;
354355
}
@@ -382,7 +383,7 @@ static void perf_evlist__collapse_resort(struct perf_evlist *evlist)
382383
struct perf_evsel *evsel;
383384

384385
evlist__for_each(evlist, evsel) {
385-
struct hists *hists = &evsel->hists;
386+
struct hists *hists = evsel__hists(evsel);
386387

387388
hists__collapse_resort(hists, NULL);
388389
}
@@ -631,24 +632,26 @@ static void data_process(void)
631632
bool first = true;
632633

633634
evlist__for_each(evlist_base, evsel_base) {
635+
struct hists *hists_base = evsel__hists(evsel_base);
634636
struct data__file *d;
635637
int i;
636638

637639
data__for_each_file_new(i, d) {
638640
struct perf_evlist *evlist = d->session->evlist;
639641
struct perf_evsel *evsel;
642+
struct hists *hists;
640643

641644
evsel = evsel_match(evsel_base, evlist);
642645
if (!evsel)
643646
continue;
644647

645-
d->hists = &evsel->hists;
648+
hists = evsel__hists(evsel);
649+
d->hists = hists;
646650

647-
hists__match(&evsel_base->hists, &evsel->hists);
651+
hists__match(hists_base, hists);
648652

649653
if (!show_baseline_only)
650-
hists__link(&evsel_base->hists,
651-
&evsel->hists);
654+
hists__link(hists_base, hists);
652655
}
653656

654657
fprintf(stdout, "%s# Event '%s'\n#\n", first ? "" : "\n",
@@ -659,7 +662,7 @@ static void data_process(void)
659662
if (verbose || data__files_cnt > 2)
660663
data__fprintf();
661664

662-
hists__process(&evsel_base->hists);
665+
hists__process(hists_base);
663666
}
664667
}
665668

tools/perf/builtin-kvm.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,7 @@ static int perf_kvm__handle_stdin(void)
896896

897897
static int kvm_events_live_report(struct perf_kvm_stat *kvm)
898898
{
899-
struct pollfd *pollfds = NULL;
900-
int nr_fds, nr_stdin, ret, err = -EINVAL;
899+
int nr_stdin, ret, err = -EINVAL;
901900
struct termios save;
902901

903902
/* live flag must be set first */
@@ -919,34 +918,27 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
919918
signal(SIGINT, sig_handler);
920919
signal(SIGTERM, sig_handler);
921920

922-
/* use pollfds -- need to add timerfd and stdin */
923-
nr_fds = kvm->evlist->pollfd.nr;
924-
925921
/* add timer fd */
926922
if (perf_kvm__timerfd_create(kvm) < 0) {
927923
err = -1;
928924
goto out;
929925
}
930926

931-
if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd))
927+
if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
932928
goto out;
933929

934-
nr_fds++;
935-
936-
if (perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)))
930+
nr_stdin = perf_evlist__add_pollfd(kvm->evlist, fileno(stdin));
931+
if (nr_stdin < 0)
937932
goto out;
938933

939-
nr_stdin = nr_fds;
940-
nr_fds++;
941934
if (fd_set_nonblock(fileno(stdin)) != 0)
942935
goto out;
943936

944-
pollfds = kvm->evlist->pollfd.entries;
945-
946937
/* everything is good - enable the events and process */
947938
perf_evlist__enable(kvm->evlist);
948939

949940
while (!done) {
941+
struct fdarray *fda = &kvm->evlist->pollfd;
950942
int rc;
951943

952944
rc = perf_kvm__mmap_read(kvm);
@@ -957,11 +949,11 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
957949
if (err)
958950
goto out;
959951

960-
if (pollfds[nr_stdin].revents & POLLIN)
952+
if (fda->entries[nr_stdin].revents & POLLIN)
961953
done = perf_kvm__handle_stdin();
962954

963955
if (!rc && !done)
964-
err = poll(pollfds, nr_fds, 100);
956+
err = fdarray__poll(fda, 100);
965957
}
966958

967959
perf_evlist__disable(kvm->evlist);

tools/perf/builtin-record.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "util/parse-options.h"
1515
#include "util/parse-events.h"
1616

17+
#include "util/callchain.h"
1718
#include "util/header.h"
1819
#include "util/event.h"
1920
#include "util/evlist.h"

tools/perf/builtin-report.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,14 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
288288
evname = buf;
289289

290290
for_each_group_member(pos, evsel) {
291+
const struct hists *pos_hists = evsel__hists(pos);
292+
291293
if (symbol_conf.filter_relative) {
292-
nr_samples += pos->hists.stats.nr_non_filtered_samples;
293-
nr_events += pos->hists.stats.total_non_filtered_period;
294+
nr_samples += pos_hists->stats.nr_non_filtered_samples;
295+
nr_events += pos_hists->stats.total_non_filtered_period;
294296
} else {
295-
nr_samples += pos->hists.stats.nr_events[PERF_RECORD_SAMPLE];
296-
nr_events += pos->hists.stats.total_period;
297+
nr_samples += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE];
298+
nr_events += pos_hists->stats.total_period;
297299
}
298300
}
299301
}
@@ -318,7 +320,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
318320
struct perf_evsel *pos;
319321

320322
evlist__for_each(evlist, pos) {
321-
struct hists *hists = &pos->hists;
323+
struct hists *hists = evsel__hists(pos);
322324
const char *evname = perf_evsel__name(pos);
323325

324326
if (symbol_conf.event_group &&
@@ -427,7 +429,7 @@ static void report__collapse_hists(struct report *rep)
427429
ui_progress__init(&prog, rep->nr_entries, "Merging related events...");
428430

429431
evlist__for_each(rep->session->evlist, pos) {
430-
struct hists *hists = &pos->hists;
432+
struct hists *hists = evsel__hists(pos);
431433

432434
if (pos->idx == 0)
433435
hists->symbol_filter_str = rep->symbol_filter_str;
@@ -437,7 +439,7 @@ static void report__collapse_hists(struct report *rep)
437439
/* Non-group events are considered as leader */
438440
if (symbol_conf.event_group &&
439441
!perf_evsel__is_group_leader(pos)) {
440-
struct hists *leader_hists = &pos->leader->hists;
442+
struct hists *leader_hists = evsel__hists(pos->leader);
441443

442444
hists__match(leader_hists, hists);
443445
hists__link(leader_hists, hists);
@@ -485,6 +487,7 @@ static int __cmd_report(struct report *rep)
485487

486488
if (dump_trace) {
487489
perf_session__fprintf_nr_events(session, stdout);
490+
perf_evlist__fprintf_nr_events(session->evlist, stdout);
488491
return 0;
489492
}
490493
}
@@ -500,7 +503,7 @@ static int __cmd_report(struct report *rep)
500503
}
501504

502505
evlist__for_each(session->evlist, pos)
503-
hists__output_resort(&pos->hists);
506+
hists__output_resort(evsel__hists(pos));
504507

505508
return report__browse_hists(rep);
506509
}
@@ -565,7 +568,6 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
565568
struct stat st;
566569
bool has_br_stack = false;
567570
int branch_mode = -1;
568-
int ret = -1;
569571
char callchain_default_opt[] = "fractal,0.5,callee";
570572
const char * const report_usage[] = {
571573
"perf report [<options>]",
@@ -692,6 +694,10 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
692694
struct perf_data_file file = {
693695
.mode = PERF_DATA_MODE_READ,
694696
};
697+
int ret = hists__init();
698+
699+
if (ret < 0)
700+
return ret;
695701

696702
perf_config(report__config, &report);
697703

tools/perf/builtin-sched.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,9 +1431,6 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool __maybe_
14311431
{
14321432
int err = 0;
14331433

1434-
evsel->hists.stats.total_period += sample->period;
1435-
hists__inc_nr_samples(&evsel->hists, true);
1436-
14371434
if (evsel->handler != NULL) {
14381435
tracepoint_handler f = evsel->handler;
14391436
err = f(tool, evsel, sample, machine);

tools/perf/builtin-script.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
572572

573573
scripting_ops->process_event(event, sample, evsel, thread, &al);
574574

575-
evsel->hists.stats.total_period += sample->period;
576575
return 0;
577576
}
578577

0 commit comments

Comments
 (0)