History

perf trace: Support multiple "vfs_getname" probes

With a suitably defined "probe:vfs_getname" probe, 'perf trace' can "beautify" its output, so syscalls like open() or openat() can print the "filename" argument instead of just its hex address, like: $ perf trace -e open -- touch /dev/null [...] 0.590 ( 0.014 ms): touch/18063 open(filename: /dev/null, flags: CREAT|NOCTTY|NONBLOCK|WRONLY, mode: IRUGO|IWUGO) = 3 [...] The output without such beautifier looks like: 0.529 ( 0.011 ms): touch/18075 open(filename: 0xc78cf288, flags: CREAT|NOCTTY|NONBLOCK|WRONLY, mode: IRUGO|IWUGO) = 3 However, when the vfs_getname probe expands to multiple probes and it is not the first one that is hit, the beautifier fails, as following: 0.326 ( 0.010 ms): touch/18072 open(filename: , flags: CREAT|NOCTTY|NONBLOCK|WRONLY, mode: IRUGO|IWUGO) = 3 Fix it by hooking into all the expanded probes (inlines), now, for instance: [root@quaco ~]# perf probe -l probe:vfs_getname (on getname_flags:73@fs/namei.c with pathname) probe:vfs_getname_1 (on getname_flags:73@fs/namei.c with pathname) [root@quaco ~]# perf trace -e open* sleep 1 0.010 ( 0.005 ms): sleep/5588 openat(dfd: CWD, filename: /etc/ld.so.cache, flags: RDONLY|CLOEXEC) = 3 0.029 ( 0.006 ms): sleep/5588 openat(dfd: CWD, filename: /lib64/libc.so.6, flags: RDONLY|CLOEXEC) = 3 0.194 ( 0.008 ms): sleep/5588 openat(dfd: CWD, filename: /usr/lib/locale/locale-archive, flags: RDONLY|CLOEXEC) = 3 [root@quaco ~]# Works, further verified with: [root@quaco ~]# perf test vfs 65: Use vfs_getname probe to get syscall args filenames : Ok 66: Add vfs_getname probe to get syscall args filenames : Ok 67: Check open filename arg using perf trace + vfs_getname: Ok [root@quaco ~]#

Arnaldo Carvalho de Melo committed 7 years ago

Commit 6ab3bc21 parent 59a17701 file · +18 −7Browse files

Unified · Split

tools/perf/builtin-trace.c+18−7
@@ -2514,19 +2514,30 @@ static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp); · 2513 unmodified lines
25142514
25152515 static bool perf_evlist__add_vfs_getname(struct perf_evlist *evlist)
25162516 {
2517− struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname");
2517+ bool found = false;
2518+ struct perf_evsel *evsel, *tmp;
2519+ struct parse_events_error err = { .idx = 0, };
2520+ int ret = parse_events(evlist, "probe:vfs_getname*", &err);
25182521
2519− if (IS_ERR(evsel))
2522+ if (ret)
25202523 return false;
25212524
2522− if (perf_evsel__field(evsel, "pathname") == NULL) {
2525+ evlist__for_each_entry_safe(evlist, evsel, tmp) {
2526+ if (!strstarts(perf_evsel__name(evsel), "probe:vfs_getname"))
2527+ continue;
2528+
2529+ if (perf_evsel__field(evsel, "pathname")) {
2530+ evsel->handler = trace__vfs_getname;
2531+ found = true;
2532+ continue;
2533+ }
2534+
2535+ list_del_init(&evsel->node);
2536+ evsel->evlist = NULL;
25232537 perf_evsel__delete(evsel);
2524− return false;
25252538 }
25262539
2527− evsel->handler = trace__vfs_getname;
2528− perf_evlist__add(evlist, evsel);
2529− return true;
2540+ return found;
25302541 }
25312542
25322543 static struct perf_evsel *perf_evsel__new_pgfault(u64 config)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t