From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Adrian Hunter <adrian.hunter@intel.com>,
David Ahern <dsahern@gmail.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Jiri Olsa <jolsa@redhat.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Mike Galbraith <efault@gmx.de>, Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <peterz@infradead.org>,
Stephane Eranian <eranian@google.com>
Subject: [PATCH 03/26] perf trace: Use vfs_getname hook if available
Date: Tue, 22 Oct 2013 11:28:11 -0300 [thread overview]
Message-ID: <1382452114-1243-4-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1382452114-1243-1-git-send-email-acme@infradead.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Initially it tries to find a probe:vfs_getname that should be setup
with:
perf probe 'vfs_getname=getname_flags:65 pathname=result->name:string'
or with slight changes to cope with code flux in the getname_flags code.
In the future, if a "vfs:getname" tracepoint becomes available, then it
will be preferred.
This is not strictly required and more expensive method of reading the
/proc/pid/fd/ symlink will be used when the fd->path array entry is not
populated by a previous vfs_getname + open syscall ret sequence.
As with any other 'perf probe' probe the setup must be done just once
and the probe will be left inactive, waiting for users, be it 'perf
trace' of any other tool.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-ujg8se8glq5izmu8cdkq15po@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Documentation/perf-trace.txt | 4 ++
tools/perf/builtin-trace.c | 83 ++++++++++++++++++++++++++++-----
2 files changed, 75 insertions(+), 12 deletions(-)
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt
index 54139c6457f8..7b0497f95a75 100644
--- a/tools/perf/Documentation/perf-trace.txt
+++ b/tools/perf/Documentation/perf-trace.txt
@@ -97,6 +97,10 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs.
Show a summary of syscalls by thread with min, max, and average times (in
msec) and relative stddev.
+--tool_stats::
+ Show tool stats such as number of times fd->pathname was discovered thru
+ hooking the open syscall return + vfs_getname or via reading /proc/pid/fd, etc.
+
SEE ALSO
--------
linkperf:perf-record[1], linkperf:perf-script[1]
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 763bef45afad..86d2b1f2399c 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -951,7 +951,10 @@ fail:
struct trace {
struct perf_tool tool;
- int audit_machine;
+ struct {
+ int machine;
+ int open_id;
+ } audit;
struct {
int max;
struct syscall *table;
@@ -965,14 +968,19 @@ struct trace {
struct strlist *ev_qualifier;
bool not_ev_qualifier;
bool live;
+ const char *last_vfs_getname;
struct intlist *tid_list;
struct intlist *pid_list;
bool sched;
bool multiple_threads;
bool summary;
bool show_comm;
+ bool show_tool_stats;
double duration_filter;
double runtime_ms;
+ struct {
+ u64 vfs_getname, proc_getname;
+ } stats;
};
static int trace__set_fd_pathname(struct thread *thread, int fd, const char *pathname)
@@ -1027,7 +1035,8 @@ static int thread__read_fd_path(struct thread *thread, int fd)
return trace__set_fd_pathname(thread, fd, pathname);
}
-static const char *thread__fd_path(struct thread *thread, int fd, bool live)
+static const char *thread__fd_path(struct thread *thread, int fd,
+ struct trace *trace)
{
struct thread_trace *ttrace = thread->priv;
@@ -1037,9 +1046,13 @@ static const char *thread__fd_path(struct thread *thread, int fd, bool live)
if (fd < 0)
return NULL;
- if ((fd > ttrace->paths.max || ttrace->paths.table[fd] == NULL) &&
- (!live || thread__read_fd_path(thread, fd)))
- return NULL;
+ if ((fd > ttrace->paths.max || ttrace->paths.table[fd] == NULL))
+ if (!trace->live)
+ return NULL;
+ ++trace->stats.proc_getname;
+ if (thread__read_fd_path(thread, fd)) {
+ return NULL;
+ }
return ttrace->paths.table[fd];
}
@@ -1049,7 +1062,7 @@ static size_t syscall_arg__scnprintf_fd(char *bf, size_t size,
{
int fd = arg->val;
size_t printed = scnprintf(bf, size, "%d", fd);
- const char *path = thread__fd_path(arg->thread, fd, arg->trace->live);
+ const char *path = thread__fd_path(arg->thread, fd, arg->trace);
if (path)
printed += scnprintf(bf + printed, size - printed, "<%s>", path);
@@ -1186,7 +1199,7 @@ static int trace__read_syscall_info(struct trace *trace, int id)
{
char tp_name[128];
struct syscall *sc;
- const char *name = audit_syscall_to_name(id, trace->audit_machine);
+ const char *name = audit_syscall_to_name(id, trace->audit.machine);
if (name == NULL)
return -1;
@@ -1450,6 +1463,12 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
ret = perf_evsel__intval(evsel, sample, "ret");
+ if (id == trace->audit.open_id && ret >= 0 && trace->last_vfs_getname) {
+ trace__set_fd_pathname(thread, ret, trace->last_vfs_getname);
+ trace->last_vfs_getname = NULL;
+ ++trace->stats.vfs_getname;
+ }
+
ttrace = thread->priv;
ttrace->exit_time = sample->time;
@@ -1494,6 +1513,13 @@ out:
return 0;
}
+static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
+ struct perf_sample *sample)
+{
+ trace->last_vfs_getname = perf_evsel__rawptr(evsel, sample, "pathname");
+ return 0;
+}
+
static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evsel,
struct perf_sample *sample)
{
@@ -1616,6 +1642,22 @@ static int trace__record(int argc, const char **argv)
static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
+static void perf_evlist__add_vfs_getname(struct perf_evlist *evlist)
+{
+ struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname",
+ evlist->nr_entries);
+ if (evsel == NULL)
+ return;
+
+ if (perf_evsel__field(evsel, "pathname") == NULL) {
+ perf_evsel__delete(evsel);
+ return;
+ }
+
+ evsel->handler.func = trace__vfs_getname;
+ perf_evlist__add(evlist, evsel);
+}
+
static int trace__run(struct trace *trace, int argc, const char **argv)
{
struct perf_evlist *evlist = perf_evlist__new();
@@ -1635,6 +1677,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_exit", trace__sys_exit))
goto out_error_tp;
+ perf_evlist__add_vfs_getname(evlist);
+
if (trace->sched &&
perf_evlist__add_newtp(evlist, "sched", "sched_stat_runtime",
trace__sched_stat_runtime))
@@ -1741,12 +1785,22 @@ again:
if (done)
perf_evlist__disable(evlist);
-
- goto again;
+ else
+ goto again;
out_unmap_evlist:
- if (!err && trace->summary)
- trace__fprintf_thread_summary(trace, trace->output);
+ if (!err) {
+ if (trace->summary)
+ trace__fprintf_thread_summary(trace, trace->output);
+
+ if (trace->show_tool_stats) {
+ fprintf(trace->output, "Stats:\n "
+ " vfs_getname : %" PRIu64 "\n"
+ " proc_getname: %" PRIu64 "\n",
+ trace->stats.vfs_getname,
+ trace->stats.proc_getname);
+ }
+ }
perf_evlist__munmap(evlist);
out_close_evlist:
@@ -1788,6 +1842,7 @@ static int trace__replay(struct trace *trace)
const struct perf_evsel_str_handler handlers[] = {
{ "raw_syscalls:sys_enter", trace__sys_enter, },
{ "raw_syscalls:sys_exit", trace__sys_exit, },
+ { "probe:vfs_getname", trace__vfs_getname, },
};
struct perf_session *session;
@@ -1997,7 +2052,10 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
NULL
};
struct trace trace = {
- .audit_machine = audit_detect_machine(),
+ .audit = {
+ .machine = audit_detect_machine(),
+ .open_id = audit_name_to_syscall("open", trace.audit.machine),
+ },
.syscalls = {
. max = -1,
},
@@ -2019,6 +2077,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
const struct option trace_options[] = {
OPT_BOOLEAN(0, "comm", &trace.show_comm,
"show the thread COMM next to its id"),
+ OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"),
OPT_STRING('e', "expr", &ev_qualifier_str, "expr",
"list of events to trace"),
OPT_STRING('o', "output", &output_name, "file", "output file name"),
--
1.8.1.4
next prev parent reply other threads:[~2013-10-22 14:29 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-22 14:28 [GIT PULL 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 01/26] perf scripting perl: Fix build error on Fedora 12 Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 02/26] perf trace: Split fd -> pathname array handling Arnaldo Carvalho de Melo
2013-10-22 14:28 ` Arnaldo Carvalho de Melo [this message]
2013-10-22 14:28 ` [PATCH 04/26] perf trace: Improve event processing exit Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 05/26] perf evlist: Introduce perf_evlist__strerror_tp method Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 06/26] perf tools: Introduce filename__read_int helper Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 07/26] perf trace: Improve messages related to /proc/sys/kernel/perf_event_paranoid Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 08/26] perf evsel: Add missing 'mmap2' from debug print Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 09/26] perf evsel: Add missing decrement in id sample parsing Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 10/26] perf record: Improve write_output error message Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 11/26] perf session: Add missing sample flush for piped events Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 12/26] perf session: Add missing members to perf_event__attr_swap() Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 13/26] perf evlist: Fix 32-bit build error Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 14/26] perf tools: Fix test_on_exit for 32-bit build Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 15/26] perf tools: Fix bench/numa.c " Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 16/26] perf evlist: Fix perf_evlist__mmap comments Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 17/26] perf evlist: Factor out duplicated mmap code Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 18/26] perf script: Print addr by default for BTS Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 19/26] perf list: Show error if tracepoints not available Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 20/26] perf callchain: Convert children list to rbtree Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 21/26] perf tools: Compare dso's also when comparing symbols Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 22/26] perf tools: Add data object to handle perf data file Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 23/26] perf tools: Add perf_data_file__open interface to data object Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 24/26] perf session: Separating data file properties from session Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 25/26] perf report: Add --max-stack option to limit callchain stack scan Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 26/26] perf top: " Arnaldo Carvalho de Melo
2013-10-23 7:48 ` [GIT PULL 00/26] perf/core improvements and fixes Ingo Molnar
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=1382452114-1243-4-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=dsahern@gmail.com \
--cc=efault@gmx.de \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@kernel.org \
--cc=paulus@samba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®