perf: Have perf become tracefs aware
cover perf: Have perf become tracefs aware
As I'm trying to move the tracing directory from debugfs, perf needs to be aware of this as system admins will now be able to mount the tracing directory without needing to mount debugfs. This patch series addresses this and makes perf aware of tracefs.
I based this series on a recent tip branch: perf/core.
You can also get this series from my repo as stated below.
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
tip/perf/core
Head SHA1: 1a334ac9034ceefc1c87e4cd95c6e103ba29df44
Steven Rostedt (Red Hat) (5):
tools lib fs: Add helper to find mounted file systems tools lib api fs: Add tracefs mount helper functions tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro tools lib api fs: Add {tracefs,debugfs}_configured() functions
perf: Make perf aware of tracefs
----
tools/lib/api/Makefile | 4 ++ tools/lib/api/fs/debugfs.c | 68 ++++++++++---------------- tools/lib/api/fs/debugfs.h | 1 + tools/lib/api/fs/findfs.c | 63 ++++++++++++++++++++++++ tools/lib/api/fs/findfs.h | 10 ++++ tools/lib/api/fs/tracefs.c | 84 ++++++++++++++++++++++++++++++++ tools/lib/api/fs/tracefs.h | 30 ++++++++++++ tools/perf/tests/open-syscall-all-cpus.c | 7 ++- tools/perf/tests/open-syscall.c | 7 ++- tools/perf/tests/parse-events.c | 13 ++++- tools/perf/util/cache.h | 1 + tools/perf/util/evlist.c | 7 +-- tools/perf/util/parse-events.c | 15 ++++-- tools/perf/util/parse-events.h | 2 +- tools/perf/util/probe-event.c | 24 ++++++--- tools/perf/util/util.c | 60 ++++++++++++++++++----- tools/perf/util/util.h | 1 + 17 files changed, 323 insertions(+), 74 deletions(-)
PATCH 1/5 tools lib fs: Add helper to find mounted file systems
From: "Steven Rostedt (Red Hat)" <[email protected]>
In preparation for adding tracefs for perf to use, create a findfs helper utility that find_debugfs uses instead of hard coding the search in the code. This will allow for a find_tracefs to be used as well.
--- tools/lib/api/Makefile | 2 ++ tools/lib/api/fs/debugfs.c | 45 ++++----------------------------- tools/lib/api/fs/findfs.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ tools/lib/api/fs/findfs.h | 10 ++++++++ 4 files changed, 80 insertions(+), 40 deletions(-) create mode 100644 tools/lib/api/fs/findfs.c create mode 100644 tools/lib/api/fs/findfs.h
tools/lib/api/Makefile +2 -0
@@ -9,11 +9,13 @@ LIB_H= LIB_OBJS= LIB_H += fs/debugfs.h +LIB_H += fs/findfs.h LIB_H += fs/fs.h # See comment below about piggybacking... LIB_H += fd/array.h LIB_OBJS += $(OUTPUT)fs/debugfs.o +LIB_OBJS += $(OUTPUT)fs/findfs.o LIB_OBJS += $(OUTPUT)fs/fs.o # XXX piggybacking here, need to introduce libapikfd, or rename this # to plain libapik.a and make it have it all api goodies
tools/lib/api/fs/debugfs.c +5 -40
66 lines not on this page · raw message
tools/lib/api/fs/findfs.c new file +63 -0
63 lines not on this page · raw message
tools/lib/api/fs/findfs.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef __API_FINDFS_H__ +#define __API_FINDFS_H__ + +const char *find_mountpoint (const char *fstype,long magic, +char *mountpoint,int len, +const char *const *known_mountpoints); + +int valid_mountpoint (const char *mount,long magic); + +#endif /* __API_FINDFS_H__ */
Signature · 1 line
2.1.4
Re: [PATCH 1/5] tools lib fs: Add helper to find mounted file systems
On Sat, Jan 24, 2015 at 01:13:31PM -0500, Steven Rostedt wrote:
SNIP
Quoted 32 lines
/* find the path to the mounted debugfs */
const char*debugfs_find_mountpoint(void)
{tools/lib/api/fs/debugfs.c +0
-26-const char *const *ptr; -char type[100 ]; -FILE *fp; -if (debugfs_found)return (const char *)debugfs_mountpoint; - ptr = debugfs_known_mountpoints; -while (*ptr) { -if (debugfs_valid_mountpoint (*ptr) ==0 ) { - debugfs_found = true; -strcpy (debugfs_mountpoint, *ptr); -return debugfs_mountpoint; - } - ptr++; - } - -/* give up and parse /proc/mounts */ - fp =fopen ("/proc/mounts" ,"r" ); -if (fp ==NULL ) -return NULL ; - - while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", - debugfs_mountpoint, type) ==2 ) { -if (strcmp (type,"debugfs" ) ==0 ) -break ; - } -fclose (fp); -
tools/lib/api/fs/debugfs.c static bool debugfs_found; · line 32
Quoted 10 lines
tools/lib/api/fs/debugfs.c +3
-6-if (strcmp (type,"debugfs" ) !=0 ) -return NULL ; - - debugfs_found = true; - -return debugfs_mountpoint; +return find_mountpoint ("debugfs" , (long )DEBUGFS_MAGIC , + debugfs_mountpoint,PATH_MAX +1 , + debugfs_known_mountpoints); }
debugfs_found is no longer set 'true' by debugfs_find_mountpoint
jirka
Re: [PATCH 1/5] tools lib fs: Add helper to find mounted file systems
Quoted 13 lines · On Sun, 25 Jan 2015 17:41:00 +0100 Jiri Olsa <[email protected]> wrote:
tools/lib/api/fs/debugfs.c static bool debugfs_found; · line 32
Quoted 7 lines · Steven Rostedt
tools/lib/api/fs/debugfs.c +3
-3- debugfs_found = true; - -return debugfs_mountpoint; +return find_mountpoint ("debugfs" , (long )DEBUGFS_MAGIC , + debugfs_mountpoint,PATH_MAX +1 , + debugfs_known_mountpoints); }
debugfs_foundis no longer set 'true' bydebugfs_find_mountpoint
Grumble. Will fix, thanks.
-- Steve
PATCH 2/5 tools lib api fs: Add tracefs mount helper functions
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Since tracefs will now hold the event directory for perf, and even though by default, debugfs still mounts tracefs on the debugfs/tracing directory, the system admin may now choose to not mount debugfs and instead just mount tracefs instead.
Having tracefs helper functions will facilitate having perf look for tracefs first, and then try debugfs as a fallback.
--- tools/lib/api/Makefile | 2 ++ tools/lib/api/fs/tracefs.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ tools/lib/api/fs/tracefs.h | 29 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 tools/lib/api/fs/tracefs.c create mode 100644 tools/lib/api/fs/tracefs.h
tools/lib/api/Makefile +2 -0
@@ -9,12 +9,14 @@ LIB_H= LIB_OBJS= LIB_H += fs/debugfs.h +LIB_H += fs/tracefs.h LIB_H += fs/findfs.h LIB_H += fs/fs.h # See comment below about piggybacking... LIB_H += fd/array.h LIB_OBJS += $(OUTPUT)fs/debugfs.o +LIB_OBJS += $(OUTPUT)fs/tracefs.o LIB_OBJS += $(OUTPUT)fs/findfs.o LIB_OBJS += $(OUTPUT)fs/fs.o # XXX piggybacking here, need to introduce libapikfd, or rename this
tools/lib/api/fs/tracefs.c new file +71 -0
71 lines not on this page · raw message
tools/lib/api/fs/tracefs.h new file +29 -0
@@ -0,0 +1,29 @@ +#ifndef __API_TRACEFS_H__ +#define __API_TRACEFS_H__ + +#define _STR (x) #x +#define STR (x) _STR(x) + +/* +* On most systems <limits.h> would have given us this, but not on some systems +* (e.g. GNU/Hurd). +*/ +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef TRACEFS_MAGIC +#define TRACEFS_MAGIC 0x74726163 +#endif + +#ifndef PERF_TRACEFS_ENVIRONMENT +#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" +#endif + +const char *tracefs_find_mountpoint (void ); +int tracefs_valid_mountpoint (const char *debugfs); +char *tracefs_mount (const char *mountpoint); + +extern char tracefs_mountpoint[]; + +#endif /* __API_DEBUGFS_H__ */
Signature · 1 line
2.1.4
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
On Sat, Jan 24, 2015 at 01:13:32PM -0500, Steven Rostedt wrote:
SNIP
tools/lib/api/fs/tracefs.h line 5
Quoted 11 lines
tools/lib/api/fs/tracefs.h new file +5
-0@@ -0,0 +1,29 @@ +#ifndef __API_TRACEFS_H__ +#define __API_TRACEFS_H__ + +#define _STR (x) #x +#define STR (x) _STR(x)
I can't find STR macro being used in the code..
jirka
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
Quoted 4 lines · On Sun, 25 Jan 2015 17:45:36 +0100 Jiri Olsa <[email protected]> wrote:
On Sat, Jan 24, 2015 at 01:13:32PM -0500, Steven Rostedt wrote:
SNIP
Quoted 13 lines
tools/lib/api/fs/tracefs.h line 5
Quoted 11 lines
tools/lib/api/fs/tracefs.h new file +5
-0@@ -0,0 +1,29 @@ +#ifndef __API_TRACEFS_H__ +#define __API_TRACEFS_H__ + +#define _STR (x) #x +#define STR (x) _STR(x)I can't find STR macro being used in the code..
I noticed this too just after I sent the series. I was seeing who had good eyes ;-)
It's from doing a cut and paste from debugfs.h, which still has it, even though after this series, it's only used by findfs.c. Thus it should be moved to findfs.h, and removed from debugfs.h and tracefs.h.
Thanks, will fix.
-- Steve
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
In reply to Steven RostedtOn Sat, Jan 24, 2015 at 01:13:32PM -0500, Steven Rostedt wrote:
SNIP
Quoted 10 lines
tools/lib/api/fs/tracefs.c new file +10
-0+static const char *const tracefs_known_mountpoints[] = { +TRACEFS_DEFAULT_PATH , +"/sys/kernel/debug/tracing" , +"/tracing" , +"/trace" , +0 , +}; + +static bool tracefs_found; +
tools/lib/api/fs/tracefs.c line 38
Quoted 10 lines
tools/lib/api/fs/tracefs.c new file +10
-0+/* find the path to the mounted tracefs */ +const char *tracefs_find_mountpoint (void ) +{ +if (tracefs_found) +return (const char *)tracefs_mountpoint; + +return find_mountpoint ("tracefs" , (long )TRACEFS_MAGIC , + tracefs_mountpoint,PATH_MAX +1 , + tracefs_known_mountpoints); +}
also tracefs_found is not set 'true' in case we succeed..
jirka
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
Quoted 18 lines · On Sun, 25 Jan 2015 17:51:14 +0100 Jiri Olsa <[email protected]> wrote:
On Sat, Jan 24, 2015 at 01:13:32PM -0500, Steven Rostedt wrote:
SNIP
Quoted 14 lines
tools/lib/api/fs/tracefs.c new file +14
-0+static const char *const tracefs_known_mountpoints[] = { +TRACEFS_DEFAULT_PATH , +"/sys/kernel/debug/tracing" , +"/tracing" , +"/trace" , +0 , +}; + +static bool tracefs_found; + +/* find the path to the mounted tracefs */ +const char *tracefs_find_mountpoint (void ) +{ +if (tracefs_found)
Quoted 9 lines
tools/lib/api/fs/tracefs.c line 38
Quoted 6 lines
tools/lib/api/fs/tracefs.c new file +6
-0+return (const char *)tracefs_mountpoint; + +return find_mountpoint ("tracefs" , (long )TRACEFS_MAGIC , + tracefs_mountpoint,PATH_MAX +1 , + tracefs_known_mountpoints); +}also
tracefs_foundis not set 'true' in case we succeed..
Thanks will fix. This is something that testing wouldn't catch, because the tracefs_found (and debugfs_found) are just there to not try to remount. Where here it would just refind where it is mounted. Thus, not incorrect code, just inefficient code.
-- Steve
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
In reply to Steven RostedtOn Sat, Jan 24, 2015 at 01:13:32PM -0500, Steven Rostedt wrote:
SNIP
Quoted 8 lines
tools/lib/api/fs/tracefs.h new file +7
-0@@ -0,0 +1,29 @@ +#ifndef __API_TRACEFS_H__ +#define __API_TRACEFS_H__ + +#define _STR (x) #x +#define STR (x) _STR(x) + +/*
tools/lib/api/fs/tracefs.h line 17
Quoted 10 lines
tools/lib/api/fs/tracefs.h new file +10
-0+* On most systems <limits.h> would have given us this, but not on some systems +* (e.g. GNU/Hurd). +*/ +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef TRACEFS_MAGIC +#define TRACEFS_MAGIC 0x74726163 +#endif
I missed the point when tracefs became actual standalone filesystem.. I'll check ;-)
Is it mutualy exclusive to 'debugfs/tracing' or those 2 can live together?
jirka
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
Quoted 26 lines · On Sun, 25 Jan 2015 17:56:19 +0100 Jiri Olsa <[email protected]> wrote:
On Sat, Jan 24, 2015 at 01:13:32PM -0500, Steven Rostedt wrote:
SNIP
Quoted 8 lines
tools/lib/api/fs/tracefs.h new file +7
-0@@ -0,0 +1,29 @@ +#ifndef __API_TRACEFS_H__ +#define __API_TRACEFS_H__ + +#define _STR (x) #x +#define STR (x) _STR(x) + +/* tools/lib/api/fs/tracefs.h line 17
Quoted 10 lines
tools/lib/api/fs/tracefs.h new file +10
-0+* On most systems <limits.h> would have given us this, but not on some systems +* (e.g. GNU/Hurd). +*/ +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef TRACEFS_MAGIC +#define TRACEFS_MAGIC 0x74726163 +#endif I missed the point when tracefs became actual standalone filesystem.. I'll check ;-)
Quoted 2 lines
Is it mutualy exclusive to 'debugfs/tracing' or those 2 can live together?
I'm working on the patches right now. But when it happens perf should be aware of it. I already updated trace-cmd to be aware.
When tracefs is added, debugfs/tracing will automatically mount tracefs when debugfs is mounted. As debugfs currently has some issues with automounting, this part is being discussed currently as well.
Note, WTF is perf checking the magic number for debugfs?? If events move, even if its at the same path, this will break perf!
-- Steve
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
Quoted 35 lines · Steven Rostedt
Quoted 26 lines · On Sun, 25 Jan 2015 17:56:19 +0100 Jiri Olsa <[email protected]> wrote:
On Sat, Jan 24, 2015 at 01:13:32PM -0500, Steven Rostedt wrote:
SNIP
Quoted 8 lines
tools/lib/api/fs/tracefs.h new file +7
-0@@ -0,0 +1,29 @@ +#ifndef __API_TRACEFS_H__ +#define __API_TRACEFS_H__ + +#define _STR (x) #x +#define STR (x) _STR(x) + +/* tools/lib/api/fs/tracefs.h line 17
Quoted 10 lines
tools/lib/api/fs/tracefs.h new file +10
-0+* On most systems <limits.h> would have given us this, but not on some systems +* (e.g. GNU/Hurd). +*/ +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef TRACEFS_MAGIC +#define TRACEFS_MAGIC 0x74726163 +#endif I missed the point when tracefs became actual standalone filesystem.. I'll check ;-)
Quoted 2 lines
Is it mutualy exclusive to 'debugfs/tracing' or those 2 can live together?
I'm working on the patches right now. But when it happens perf should be aware of it. I already updated trace-cmd to be aware.
Quoted 6 lines
When tracefs is added, debugfs/tracing will automatically mount tracefs when debugfs is mounted. As debugfs currently has some issues with automounting, this part is being discussed currently as well.
Note, WTF is perf checking the magic number for debugfs?? If events move, even if its at the same path, this will break perf!
good question.. it's there since 2009:
f6bdafef2ab9 perf_counter: Add tracepoint support to perf list, perf stat
I guess we didn't want anyone to trick us with fake tracepoints ;-)
jirka
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
Quoted 7 lines · On Mon, 26 Jan 2015 10:02:55 +0100 Jiri Olsa <[email protected]> wrote:
Quoted 2 lines
Note, WTF is perf checking the magic number for debugfs?? If events move, even if its at the same path, this will break perf!
good question.. it's there since 2009:
f6bdafef2ab9perf_counter: Add tracepoint support to perf list, perf statI guess we didn't want anyone to trick us with fake tracepoints ;-)
But that would be a feature not a bug. I could imagine admins doing this for some work around.
But can we nuke that check? I don't think it's very useful.
-- Steve
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
Quoted 9 lines · Steven Rostedt
Quoted 6 lines · On Mon, 26 Jan 2015 10:02:55 +0100 Jiri Olsa <[email protected]> wrote:
Quoted 2 lines
Note, WTF is perf checking the magic number for debugfs?? If events move, even if its at the same path, this will break perf!
good question.. it's there since 2009:
f6bdafef2ab9perf_counter: Add tracepoint support to perf list, perf stat
Quoted 6 lines
Quoted 1 line
I guess we didn't want anyone to trick us with fake tracepoints ;-)
But that would be a feature not a bug. I could imagine admins doing this for some work around.
But can we nuke that check? I don't think it's very useful.
I'd be ok with that
jirka
Re: [PATCH 2/5] tools lib api fs: Add tracefs mount helper functions
Em Mon, Jan 26, 2015 at 03:31:48PM +0100, Jiri Olsa escreveu:
Quoted 10 lines · Steven Rostedt
Quoted 9 lines
Quoted 6 lines · On Mon, 26 Jan 2015 10:02:55 +0100 Jiri Olsa <[email protected]> wrote:
Quoted 2 lines
Note, WTF is perf checking the magic number for debugfs?? If events move, even if its at the same path, this will break perf!
good question.. it's there since 2009:
f6bdafef2ab9perf_counter: Add tracepoint support to perf list, perf stat
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
I guess we didn't want anyone to trick us with fake tracepoints ;-)
But that would be a feature not a bug. I could imagine admins doing this for some work around.
But can we nuke that check? I don't think it's very useful.
I'd be ok with that
Yeah, that check is a nuisance, should be removed as it takes away flexibility...
- Arnaldo
PATCH 3/5 tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Instead of hard coding "/sys/kernel/debug" everywhere, create a macro to hold where the default path exists.
--- tools/lib/api/fs/debugfs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tools/lib/api/fs/debugfs.c +7 -3
@@ -10,10 +10,14 @@#include "debugfs.h" #include "findfs.h" -char debugfs_mountpoint[PATH_MAX +1 ] ="/sys/kernel/debug" ; +#ifndef DEBUGFS_DEFAULT_PATH +#define DEBUGFS_DEFAULT_PATH "/sys/kernel/debug" +#endif + +char debugfs_mountpoint[PATH_MAX +1 ] =DEBUGFS_DEFAULT_PATH ;static const char *const debugfs_known_mountpoints[] = { -"/sys/kernel/debug" , +DEBUGFS_DEFAULT_PATH ,"/debug" ,0 , };
@@ -51,7 +55,7 @@ char *debugfs_mount(const char *mountpoint) mountpoint =getenv (PERF_DEBUGFS_ENVIRONMENT );/* if no environment variable, use default */ if (mountpoint ==NULL ) - mountpoint ="/sys/kernel/debug" ; + mountpoint =DEBUGFS_DEFAULT_PATH ; }if (mount (NULL , mountpoint,"debugfs" ,0 ,NULL ) <0 )
Signature · 1 line
2.1.4
PATCH 4/5 tools lib api fs: Add {tracefs,debugfs}_configured() functions
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Add tracefs_configured() to return true if tracefs is configured in the kernel (/sys/kernel/tracing exists), and debugfs_configured() if debugfs is configured in the kernel (/sys/kernel/debug exists).
--- tools/lib/api/fs/debugfs.c | 13 +++++++++++++ tools/lib/api/fs/debugfs.h | 1 + tools/lib/api/fs/tracefs.c | 13 +++++++++++++ tools/lib/api/fs/tracefs.h | 1 + 4 files changed, 28 insertions(+)
tools/lib/api/fs/debugfs.c +13 -0
@@ -2,8 +2,11 @@#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include <stdbool.h> #include <sys/vfs.h> +#include <sys/types.h> +#include <sys/stat.h> #include <sys/mount.h> #include <linux/kernel.h>
@@ -24,6 +27,16 @@ static const char * const debugfs_known_mountpoints[] = {static bool debugfs_found; +bool debugfs_configured (void ) +{ +struct stat st; + +if (stat (DEBUGFS_DEFAULT_PATH , &st) <0 ) +return false; + +return true; +} +/* find the path to the mounted debugfs */ const char *debugfs_find_mountpoint (void ) {
tools/lib/api/fs/debugfs.h +1 -0
@@ -20,6 +20,7 @@#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"#endif +bool debugfs_configured (void );const char *debugfs_find_mountpoint (void );int debugfs_valid_mountpoint (const char *debugfs);char *debugfs_mount (const char *mountpoint);
tools/lib/api/fs/tracefs.c +13 -0
@@ -2,8 +2,11 @@#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include <stdbool.h> #include <sys/vfs.h> +#include <sys/types.h> +#include <sys/stat.h> #include <sys/mount.h> #include <linux/kernel.h>
@@ -26,6 +29,16 @@ static const char * const tracefs_known_mountpoints[] = {static bool tracefs_found; +bool tracefs_configured (void ) +{ +struct stat st; + +if (stat (TRACEFS_DEFAULT_PATH , &st) <0 ) +return false; + +return true; +} +/* find the path to the mounted tracefs */ const char *tracefs_find_mountpoint (void ) {
tools/lib/api/fs/tracefs.h +1 -0
@@ -20,6 +20,7 @@#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"#endif +bool tracefs_configured (void );const char *tracefs_find_mountpoint (void );int tracefs_valid_mountpoint (const char *debugfs);char *tracefs_mount (const char *mountpoint);
Signature · 1 line
2.1.4
Re: [PATCH 4/5] tools lib api fs: Add {tracefs,debugfs}_configured() functions
On Sat, Jan 24, 2015 at 01:13:34PM -0500, Steven Rostedt wrote:
SNIP
Quoted 4 lines
#include <
sys/mount.h>
#include <linux/kernel.h>
tools/lib/api/fs/debugfs.c static const char * const debugfs_known_mountpoints[] = { · line 36
Quoted 10 lines
tools/lib/api/fs/debugfs.c +7
-0@@ -24,6 +27,16 @@ static const char * const debugfs_known_mountpoints[] = {static bool debugfs_found; +bool debugfs_configured (void ) +{ +struct stat st; + +if (stat (DEBUGFS_DEFAULT_PATH , &st) <0 ) +return false; +
hum, should this function rather do
bool debugfs_configured(void)
{
return debugfs_find_mountpoint() != NULL;
}SNIP
tools/lib/api/fs/tracefs.c static const char * const tracefs_known_mountpoints[] = { · line 40
Quoted 11 lines
static bool
tracefs_found;tools/lib/api/fs/tracefs.c +9
-0+bool tracefs_configured (void ) +{ +struct stat st; + +if (stat (TRACEFS_DEFAULT_PATH , &st) <0 ) +return false; + +return true; +}
same for this one..
jirka
Re: [PATCH 4/5] tools lib api fs: Add {tracefs,debugfs}_configured() functions
Quoted 31 lines · On Sun, 25 Jan 2015 18:02:03 +0100 Jiri Olsa <[email protected]> wrote:
On Sat, Jan 24, 2015 at 01:13:34PM -0500, Steven Rostedt wrote:
SNIP
Quoted 4 lines
#include <
sys/mount.h>
#include <linux/kernel.h>tools/lib/api/fs/debugfs.c static const char * const debugfs_known_mountpoints[] = { · line 36
Quoted 10 lines
tools/lib/api/fs/debugfs.c +7
-0@@ -24,6 +27,16 @@ static const char * const debugfs_known_mountpoints[] = {static bool debugfs_found; +bool debugfs_configured (void ) +{ +struct stat st; + +if (stat (DEBUGFS_DEFAULT_PATH , &st) <0 ) +return false; +hum, should this function rather do
bool
debugfs_configured(void){ return debugfs_find_mountpoint() != NULL; }SNIP
Quoted 2 lines
static bool
tracefs_found;
Quoted 11 lines
tools/lib/api/fs/tracefs.c static const char * const tracefs_known_mountpoints[] = { · line 40
Quoted 9 lines
tools/lib/api/fs/tracefs.c +9
-0+bool tracefs_configured (void ) +{ +struct stat st; + +if (stat (TRACEFS_DEFAULT_PATH , &st) <0 ) +return false; + +return true; +}same for this one..
OK, will change.
-- Steve
PATCH 5/5 perf: Make perf aware of tracefs
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
As tracefs may be mounted instead of debugfs to get to the event directories, have perf know about tracefs, and use that file system over debugfs if it is present.
--- tools/perf/tests/open-syscall-all-cpus.c | 7 +++- tools/perf/tests/open-syscall.c | 7 +++- tools/perf/tests/parse-events.c | 13 +++++-- tools/perf/util/cache.h | 1 + tools/perf/util/evlist.c | 7 ++-- tools/perf/util/parse-events.c | 15 +++++--- tools/perf/util/parse-events.h | 2 +- tools/perf/util/probe-event.c | 24 ++++++++----- tools/perf/util/util.c | 60 ++++++++++++++++++++++++++------ tools/perf/util/util.h | 1 + 10 files changed, 106 insertions(+), 31 deletions(-)
tools/perf/tests/open-syscall-all-cpus.c +6 -1
@@ -29,7 +29,12 @@ int test__open_syscall_event_on_all_cpus(void) evsel =perf_evsel__newtp ("syscalls" ,"sys_enter_open" );if (evsel ==NULL ) { -pr_debug ("is debugfs mounted on /sys/kernel/debug?\n" ); +if (tracefs_configured ()) +pr_debug ("is tracefs mounted on /sys/kernel/debug?\n" ); +else if (debugfs_configured ()) +pr_debug ("is debugfs mounted on /sys/kernel/debug?\n" ); +else +pr_debug ("Neither tracefs or debugfs is enabled in this kernel\n" ); goto out_thread_map_delete; }
tools/perf/tests/open-syscall.c +6 -1
@@ -18,7 +18,12 @@ int test__open_syscall_event(void) evsel =perf_evsel__newtp ("syscalls" ,"sys_enter_open" );if (evsel ==NULL ) { -pr_debug ("is debugfs mounted on /sys/kernel/debug?\n" ); +if (tracefs_configured ()) +pr_debug ("is tracefs mounted on /sys/kernel/debug?\n" ); +else if (debugfs_configured ()) +pr_debug ("is debugfs mounted on /sys/kernel/debug?\n" ); +else +pr_debug ("Neither tracefs or debugfs is enabled in this kernel\n" ); goto out_thread_map_delete; }
tools/perf/tests/parse-events.c +11 -2
@@ -3,6 +3,7 @@#include "evsel.h" #include "evlist.h" #include <api/fs/fs.h> +#include <api/fs/tracefs.h> #include <api/fs/debugfs.h> #include "tests.h" #include "debug.h"
@@ -1149,11 +1150,19 @@ static int count_tracepoints(void) {char events_path[PATH_MAX ];struct dirent *events_ent; +const char *mountpoint;DIR *events_dir;int cnt =0 ; -scnprintf (events_path,PATH_MAX ,"%s/tracing/events" , -debugfs_find_mountpoint ()); + mountpoint =tracefs_find_mountpoint (); +if (mountpoint) { +scnprintf (events_path,PATH_MAX ,"%s/events" , + mountpoint); + }else { + mountpoint =debugfs_find_mountpoint (); +scnprintf (events_path,PATH_MAX ,"%s/tracing/events" , + mountpoint); + } events_dir =opendir (events_path);
tools/perf/util/cache.h +1 -0
@@ -17,6 +17,7 @@#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" +#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"typedef int (*config_fn_t )(const char *,const char *,void *);extern int perf_default_config (const char *,const char *,void *);
tools/perf/util/evlist.c +4 -3
@@ -1444,10 +1444,11 @@ int perf_evlist__strerror_tp(struct perf_evlist *evlist __maybe_unused,switch (err) {case ENOENT :scnprintf (buf, size,"%s" , -"Error:\tUnable to find debugfs\n" +"Error:\tUnable to find tracefs or debugfs\n" "Hint:\tWas your kernel was compiled with debugfs support?\n" -"Hint:\tIs the debugfs filesystem mounted?\n" -"Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'" ); +"Hint:\tIs the debugfs or tracefs filesystem mounted?\n" +"Hint:\tTry 'sudo mount -t tracefs nodev /sys/kernel/tracing'\n" +"Hint:\t or 'sudo mount -t debugfs nodev /sys/kernel/debug'" );break ;case EACCES : scnprintf(buf, size,
tools/perf/util/parse-events.c +11 -4
@@ -30,6 +30,13 @@ extern int parse_events_debug;#endif int parse_events_parse (void *data,void *scanner); +static int perf_valid_mountpoint (const char *fs) +{ +if (!tracefs_valid_mountpoint (fs)) +return 0 ; +return debugfs_valid_mountpoint (fs); +} +static struct perf_pmu_event_symbol *perf_pmu_events_list;/* * The variable indicates the number of supported pmu event symbols.
@@ -175,7 +182,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)char evt_path[MAXPATHLEN ];char dir_path[MAXPATHLEN ]; -if (debugfs_valid_mountpoint (tracing_events_path)) +if (perf_valid_mountpoint (tracing_events_path))return NULL ; sys_dir =opendir (tracing_events_path);
@@ -475,7 +482,7 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx, {int ret; - ret =debugfs_valid_mountpoint (tracing_events_path); + ret =perf_valid_mountpoint (tracing_events_path);if (ret)return ret;
@@ -1110,7 +1117,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,char dir_path[MAXPATHLEN ];char sbuf[STRERR_BUFSIZE ]; -if (debugfs_valid_mountpoint (tracing_events_path)) { +if (perf_valid_mountpoint (tracing_events_path)) {printf (" [ Tracepoints not available: %s ]\n" ,strerror_r (errno, sbuf,sizeof (sbuf)));return ;
@@ -1162,7 +1169,7 @@ int is_valid_tracepoint(const char *event_string)char evt_path[MAXPATHLEN ];char dir_path[MAXPATHLEN ]; -if (debugfs_valid_mountpoint (tracing_events_path)) +if (perf_valid_mountpoint (tracing_events_path))return 0 ; sys_dir =opendir (tracing_events_path);
tools/perf/util/parse-events.h +1 -1
@@ -121,6 +121,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,int print_hwcache_events (const char *event_glob,bool name_only);extern int is_valid_tracepoint (const char *event_string); -extern int valid_debugfs_mount (const char *debugfs); +int valid_event_mount (const char *eventfs);#endif /* __PERF_PARSE_EVENTS_H */
tools/perf/util/probe-event.c +16 -8
@@ -41,6 +41,7 @@#include "symbol.h" #include "thread.h" #include <api/fs/debugfs.h> +#include <api/fs/tracefs.h> #include "trace-event.h" /* For __maybe_unused */ #include "probe-event.h" #include "probe-finder.h"
@@ -1805,7 +1806,7 @@ static void print_open_warning(int err, bool is_kprobe)" - please rebuild kernel with %s.\n" , is_kprobe ? 'k' : 'u', config); }else if (err == -ENOTSUP ) -pr_warning ("Debugfs is not mounted.\n" ); +pr_warning ("Tracefs or debugfs is not mounted.\n" );else pr_warning("Failed to open %cprobe_events: %s\n", is_kprobe ? 'k' : 'u',
@@ -1816,7 +1817,7 @@ static void print_both_open_warning(int kerr, int uerr) {/* Both kprobes and uprobes are disabled, warn it. */ if (kerr == -ENOTSUP && uerr == -ENOTSUP ) -pr_warning ("Debugfs is not mounted.\n" ); +pr_warning ("Tracefs or debugfs is not mounted.\n" );else if (kerr == -ENOENT && uerr == -ENOENT )pr_warning ("Please rebuild kernel with CONFIG_KPROBE_EVENTS " "or/and CONFIG_UPROBE_EVENTS.\n" );
@@ -1833,13 +1834,20 @@ static int open_probe_events(const char *trace_file, bool readwrite) {char buf[PATH_MAX ];const char *__debugfs; +const char *tracing_dir ="" ;int ret; - __debugfs =debugfs_find_mountpoint (); -if (__debugfs ==NULL ) -return -ENOTSUP ; + __debugfs =tracefs_find_mountpoint (); +if (__debugfs ==NULL ) { + tracing_dir ="tracing/" ; - ret =e_snprintf (buf,PATH_MAX ,"%s/%s" , __debugfs, trace_file); + __debugfs =debugfs_find_mountpoint (); +if (__debugfs ==NULL ) +return -ENOTSUP ; + } + + ret =e_snprintf (buf,PATH_MAX ,"%s/%s%s" , + __debugfs, tracing_dir, trace_file);if (ret >=0 ) {pr_debug ("Opening %s write=%d\n" , buf, readwrite);if (readwrite && !probe_event_dry_run)
@@ -1855,12 +1863,12 @@ static int open_probe_events(const char *trace_file, bool readwrite)static int open_kprobe_events (bool readwrite) { -return open_probe_events ("tracing/kprobe_events" , readwrite); +return open_probe_events ("kprobe_events" , readwrite); }static int open_uprobe_events (bool readwrite) { -return open_probe_events ("tracing/uprobe_events" , readwrite); +return open_probe_events ("uprobe_events" , readwrite); }/* Get raw string list of current kprobe_events or uprobe_events */
tools/perf/util/util.c +49 -11
98 lines not on this page · raw message
tools/perf/util/util.h +1 -0
@@ -75,6 +75,7 @@#include <linux/types.h> #include <sys/ttydefaults.h> #include <api/fs/debugfs.h> +#include <api/fs/tracefs.h> #include <termios.h> #include <linux/bitops.h> #include <termios.h>
Signature · 1 line
2.1.4
Namhyung Kim
maintainerRe: [PATCH 5/5] perf: Make perf aware of tracefs
Hi Steve,
Quoted 21 lines · Steven Rostedt
From: "Steven Rostedt (Red Hat)" <[email protected]>
As tracefs may be mounted instead of debugfs to get to the event directories, have perf know about tracefs, and use that file system over debugfs if it is present.
Signed-off-by Steven Rostedt <[email protected]>---
const char*find_tracing_dir(void)
{tools/perf/util/util.c +1
-3+const char *tracing_dir ="" ;static char *tracing;static int tracing_found;const char *debugfs;@@ -351,11 +385,15 @@ const char *find_tracing_dir(void)if (tracing_found)return tracing; - debugfs =find_debugfs (); -if (!debugfs) -return NULL ;
tools/perf/util/util.c const char *find_tracing_dir(void) · line 396
Quoted 10 lines
tools/perf/util/util.c +8
-1+ debugfs =find_tracefs (); +if (!debugfs) { + tracing_dir ="/tracing" ; + debugfs =find_debugfs (); +if (!debugfs) +return NULL ; + } -if (asprintf (&tracing,"%s/tracing" , debugfs) <0 ) +if (asprintf (&tracing,"%s%s" , tracing_dir, debugfs) <0 )
s/tracing_dir, debugfs/debugfs, tracing_dir/
Thanks,
Namhyung
Quoted 19 lines
tools/perf/util/util.c +0
-0return NULL ; tracing_found =1 ;tools/perf/util/util.h +1
-0@@ -75,6 +75,7 @@#include <linux/types.h> #include <sys/ttydefaults.h> #include <api/fs/debugfs.h> +#include <api/fs/tracefs.h> #include <termios.h> #include <linux/bitops.h> #include <termios.h> Signature · 1 line
2.1.4
Re: [PATCH 5/5] perf: Make perf aware of tracefs
Quoted 32 lines · On Sun, 25 Jan 2015 22:50:10 +0900 Namhyung Kim <[email protected]> wrote:
Hi Steve,
Quoted 29 lines · Steven Rostedt
From: "Steven Rostedt (Red Hat)" <[email protected]>
As tracefs may be mounted instead of debugfs to get to the event directories, have perf know about tracefs, and use that file system over debugfs if it is present.
Signed-off-by Steven Rostedt <[email protected]>---
const char*find_tracing_dir(void)
{tools/perf/util/util.c +8
-3+const char *tracing_dir ="" ;static char *tracing;static int tracing_found;const char *debugfs;@@ -351,11 +385,15 @@ const char *find_tracing_dir(void)if (tracing_found)return tracing; - debugfs =find_debugfs (); -if (!debugfs) -return NULL ; + debugfs =find_tracefs (); +if (!debugfs) { + tracing_dir ="/tracing" ; + debugfs =find_debugfs (); +if (!debugfs) +return NULL ; + }
Quoted 4 lines
tools/perf/util/util.c const char *find_tracing_dir(void) · line 396
Quoted 2 lines
tools/perf/util/util.c +1
-1-if (asprintf (&tracing,"%s/tracing" , debugfs) <0 ) +if (asprintf (&tracing,"%s%s" , tracing_dir, debugfs) <0 )s/tracing_dir, debugfs/debugfs, tracing_dir/
Hmm, I wonder how I missed this during testing. Ah, I think it broke on tracefs, so I added this, but never tested it again without tracefs.
Thanks, will fix.
-- Steve
Quoted 24 lines
Thanks,
NamhyungQuoted 19 lines
tools/perf/util/util.c +0
-0return NULL ; tracing_found =1 ;tools/perf/util/util.h +1
-0@@ -75,6 +75,7 @@#include <linux/types.h> #include <sys/ttydefaults.h> #include <api/fs/debugfs.h> +#include <api/fs/tracefs.h> #include <termios.h> #include <linux/bitops.h> #include <termios.h> Signature · 1 line
2.1.4
Re: [PATCH 5/5] perf: Make perf aware of tracefs
In reply to Steven RostedtOn Sat, Jan 24, 2015 at 01:13:35PM -0500, Steven Rostedt wrote:
SNIP
tools/perf/util/util.c const char *find_tracing_dir(void) · line 393
Quoted 13 lines
tools/perf/util/util.c +6
-3@@ -351,11 +385,15 @@ const char *find_tracing_dir(void)if (tracing_found)return tracing; - debugfs =find_debugfs (); -if (!debugfs) -return NULL ; + debugfs =find_tracefs (); +if (!debugfs) { + tracing_dir ="/tracing" ; + debugfs =find_debugfs (); +if (!debugfs) +return NULL ;
so this pattern 'try tracefs, if that does not work try debugfs' is all over the patch.. how about we add new new 'virtual' fs to encapsulate that, like:
with followign interface:
bool tpfs_configured(void);
const char *tpfs_find_mountpoint(void);
int tpfs_valid_mountpoint(const char *debugfs);
char *tpfs_mount(const char *mountpoint);
extern char tpfs_mountpoint[];It does not neceserily needs to reside in tools/lib/api/fs/tpfs.[ch], but I believe we need some form of encapsulation for this.
jirka
Re: [PATCH 5/5] perf: Make perf aware of tracefs
Quoted 29 lines · On Sun, 25 Jan 2015 18:34:33 +0100 Jiri Olsa <[email protected]> wrote:
On Sat, Jan 24, 2015 at 01:13:35PM -0500, Steven Rostedt wrote:
SNIP
tools/perf/util/util.c const char *find_tracing_dir(void) · line 393
Quoted 13 lines
tools/perf/util/util.c +6
-3@@ -351,11 +385,15 @@ const char *find_tracing_dir(void)if (tracing_found)return tracing; - debugfs =find_debugfs (); -if (!debugfs) -return NULL ; + debugfs =find_tracefs (); +if (!debugfs) { + tracing_dir ="/tracing" ; + debugfs =find_debugfs (); +if (!debugfs) +return NULL ;so this pattern 'try tracefs, if that does not work try debugfs' is all over the patch.. how about we add new new 'virtual' fs to encapsulate that, like:
with followign interface: bool tpfs_configured(void); const char *tpfs_find_mountpoint(void); int tpfs_valid_mountpoint(const char *debugfs); char *tpfs_mount(const char *mountpoint); extern char tpfs_mountpoint[];
Quoted 2 lines
It does not neceserily needs to reside in tools/lib/api/fs/tpfs.[ch], but I believe we need some form of encapsulation for this.
I did it this way because perf had no encapsulation for finding debugfs paths. I made the change in trace-cmd in one location. Perf does it a little different in each place. I have no idea why there was more than one location slapping on "/tracing".
I'd like to get tracefs into perf before doing any redesign of perf's infrastructure. That could come later as a cleanup.
This is not a fast path, it wont hurt performance. I agree it should be encapsulated, but that's going outside of the scope of this patch series, which is only to add awareness to tracefs, not to clean up perf's access to the debugfs/tracing directory.
-- Steve
Re: [PATCH 5/5] perf: Make perf aware of tracefs
Quoted 40 lines · Steven Rostedt
Quoted 29 lines · On Sun, 25 Jan 2015 18:34:33 +0100 Jiri Olsa <[email protected]> wrote:
On Sat, Jan 24, 2015 at 01:13:35PM -0500, Steven Rostedt wrote:
SNIP
tools/perf/util/util.c const char *find_tracing_dir(void) · line 393
Quoted 13 lines
tools/perf/util/util.c +6
-3@@ -351,11 +385,15 @@ const char *find_tracing_dir(void)if (tracing_found)return tracing; - debugfs =find_debugfs (); -if (!debugfs) -return NULL ; + debugfs =find_tracefs (); +if (!debugfs) { + tracing_dir ="/tracing" ; + debugfs =find_debugfs (); +if (!debugfs) +return NULL ;so this pattern 'try tracefs, if that does not work try debugfs' is all over the patch.. how about we add new new 'virtual' fs to encapsulate that, like:
with followign interface: bool tpfs_configured(void); const char *tpfs_find_mountpoint(void); int tpfs_valid_mountpoint(const char *debugfs); char *tpfs_mount(const char *mountpoint); extern char tpfs_mountpoint[];Quoted 2 lines
It does not neceserily needs to reside in tools/lib/api/fs/tpfs.[ch], but I believe we need some form of encapsulation for this.
I did it this way because perf had no encapsulation for finding debugfs paths. I made the change in trace-cmd in one location. Perf does it a little different in each place. I have no idea why there was more than one location slapping on "/tracing".
Quoted 7 lines
I'd like to get tracefs into perf before doing any redesign of perf's infrastructure. That could come later as a cleanup.
This is not a fast path, it wont hurt performance. I agree it should be encapsulated, but that's going outside of the scope of this patch series, which is only to add awareness to tracefs, not to clean up perf's access to the debugfs/tracing directory.
sure, np.. it could be taken care of later
jirka