From: David Ahern <dsahern@gmail.com>
To: acme@kernel.org
Cc: mingo@kernel.org, peterz@infradead.org, namhyung@kernel.org,
jolsa@kernel.org, linux-kernel@vger.kernel.org,
David Ahern <dsahern@gmail.com>
Subject: [PATCH] perf sched timehist: Improve error message when analyzing wrong file
Date: Tue, 29 Nov 2016 12:58:48 -0700 [thread overview]
Message-ID: <1480449528-43394-1-git-send-email-dsahern@gmail.com> (raw)
Arnaldo reported an unhelpful error message when running perf sched
timehist on a file that did not contain sched tracepoints:
[root@jouet ~]# perf sched timehist
No trace sample to read. Did you call 'perf record -R'?
[root@jouet ~]# perf evlist -v
cycles:ppp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1
Add a helper to determine if a session has a specific event name,
and then use that helper for timehist. For perf sched timehist the
analysis requires at least sched_switch event, so check for it.
Now when analyzing a file without sched tracepoints you get:
root@f21-vbox:/tmp$ perf sched timehist
sched_switch event does not exist in file; nothing to analyze
Signed-off-by: David Ahern <dsahern@gmail.com>
---
tools/perf/builtin-sched.c | 5 ++++-
tools/perf/util/session.c | 12 ++++++++++++
tools/perf/util/session.h | 2 ++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 870d94cd20ba..7c3c8176f51f 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2629,8 +2629,11 @@ static int perf_sched__timehist(struct perf_sched *sched)
if (perf_session__set_tracepoints_handlers(session, handlers))
goto out;
- if (!perf_session__has_traces(session, "record -R"))
+ /* sched_switch event at a minimum needs to exist */
+ if (!perf_session__has_event(session, "sched:sched_switch")) {
+ pr_err("sched_switch event does not exist in file; nothing to analyze\n");
goto out;
+ }
if (sched->show_migrations &&
perf_session__set_tracepoints_handlers(session, migrate_handlers))
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index f268201048a0..9bb3e03dcd8e 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1897,6 +1897,18 @@ bool perf_session__has_traces(struct perf_session *session, const char *msg)
return false;
}
+bool perf_session__has_event(struct perf_session *session, const char *name)
+{
+ struct perf_evsel *evsel;
+
+ evlist__for_each_entry(session->evlist, evsel) {
+ if (!strcmp(perf_evsel__name(evsel), name))
+ return true;
+ }
+
+ return false;
+}
+
int maps__set_kallsyms_ref_reloc_sym(struct map **maps,
const char *symbol_name, u64 addr)
{
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 4bd758553450..8609eca38c7f 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -64,6 +64,8 @@ int perf_session__resolve_callchain(struct perf_session *session,
bool perf_session__has_traces(struct perf_session *session, const char *msg);
+bool perf_session__has_event(struct perf_session *session, const char *name);
+
void perf_event__attr_swap(struct perf_event_attr *attr);
int perf_session__create_kernel_maps(struct perf_session *session);
--
2.7.4 (Apple Git-66)
next reply other threads:[~2016-11-29 19:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-29 19:58 David Ahern [this message]
2016-11-29 20:14 ` [PATCH] perf sched timehist: Improve error message when analyzing wrong file Arnaldo Carvalho de Melo
2016-11-29 20:17 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1480449528-43394-1-git-send-email-dsahern@gmail.com \
--to=dsahern@gmail.com \
--cc=acme@kernel.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.