mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
perf sched: Suppress latency table output when trace samples are missing
When 'perf sched latency' is executed on a perf.data file that lacks
tracepoint samples (i.e., a file recorded without the -R flag or
containing only non-tracepoint events), perf_session__has_traces()
correctly outputs an error message. However, perf_sched__read_events()
subsequently falls through and returns 0 (success).
Consequently, caller functions such as perf_sched__lat() assume event
processing succeeded and proceed to render empty latency header tables
and total summary statistics.
Fix this behaviour by ensuring perf_sched__read_events() aborts early and
returns a suitable error code when perf_session__has_traces() evaluates
to false.
Additionally, validate thread__get_runtime() against NULL in
map_switch_event() to prevent potential null-pointer dereferences.
Fixes: 27295592c2 ("perf session: Share the common trace sample_check routine as perf_session__has_traces")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
parent
006a6f0f6e
commit
4a81d59a9d
|
|
@ -1833,7 +1833,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_sample *sampl
|
|||
sched_out:
|
||||
if (sched->map.task_name) {
|
||||
tr = thread__get_runtime(sched->curr_out_thread[this_cpu.cpu]);
|
||||
if (strcmp(tr->shortname, "") == 0)
|
||||
if (tr == NULL || strcmp(tr->shortname, "") == 0)
|
||||
goto out;
|
||||
|
||||
if (proceed == 1)
|
||||
|
|
@ -2001,7 +2001,7 @@ static int perf_sched__read_events(struct perf_sched *sched)
|
|||
.mode = PERF_DATA_MODE_READ,
|
||||
.force = sched->force,
|
||||
};
|
||||
int rc = -1;
|
||||
int rc = -1, err;
|
||||
|
||||
session = perf_session__new(&data, &sched->tool);
|
||||
if (IS_ERR(session)) {
|
||||
|
|
@ -2018,18 +2018,19 @@ static int perf_sched__read_events(struct perf_sched *sched)
|
|||
if (perf_session__set_tracepoints_handlers(session, handlers))
|
||||
goto out_delete;
|
||||
|
||||
if (perf_session__has_traces(session, "record -R")) {
|
||||
int err = perf_session__process_events(session);
|
||||
if (err) {
|
||||
pr_err("Failed to process events, error %d", err);
|
||||
goto out_delete;
|
||||
}
|
||||
if (!perf_session__has_traces(session, "record -R"))
|
||||
goto out_delete;
|
||||
|
||||
sched->nr_events = evlist__stats(session->evlist)->nr_events[0];
|
||||
sched->nr_lost_events = evlist__stats(session->evlist)->total_lost;
|
||||
sched->nr_lost_chunks = evlist__stats(session->evlist)->nr_events[PERF_RECORD_LOST];
|
||||
err = perf_session__process_events(session);
|
||||
if (err) {
|
||||
pr_err("Failed to process events, error %d", err);
|
||||
goto out_delete;
|
||||
}
|
||||
|
||||
sched->nr_events = evlist__stats(session->evlist)->nr_events[0];
|
||||
sched->nr_lost_events = evlist__stats(session->evlist)->total_lost;
|
||||
sched->nr_lost_chunks = evlist__stats(session->evlist)->nr_events[PERF_RECORD_LOST];
|
||||
|
||||
rc = 0;
|
||||
out_delete:
|
||||
perf_session__delete(session);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user