Skip to content

Commit

Permalink
perf tools: Extract perf-specific stuff from debugfs.c
Browse files Browse the repository at this point in the history
Move them to util.c and simplify code a bit.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1361374353-30385-6-git-send-email-bp@alien8.de
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
suryasaimadhu authored and acmel committed Mar 15, 2013
1 parent 85c66be commit 1355915
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
15 changes: 0 additions & 15 deletions tools/lib/lk/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "debugfs.h"

char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug";
char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events";

static const char * const debugfs_known_mountpoints[] = {
"/sys/kernel/debug/",
Expand Down Expand Up @@ -75,14 +74,7 @@ int debugfs_valid_mountpoint(const char *debugfs)
return 0;
}

static void debugfs_set_tracing_events_path(const char *mountpoint)
{
snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s",
mountpoint, "tracing/events");
}

/* mount the debugfs somewhere if it's not mounted */

char *debugfs_mount(const char *mountpoint)
{
/* see if it's already mounted */
Expand All @@ -105,12 +97,5 @@ char *debugfs_mount(const char *mountpoint)
debugfs_found = true;
strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint));
out:
debugfs_set_tracing_events_path(debugfs_mountpoint);
return debugfs_mountpoint;
}

void debugfs_set_path(const char *mountpoint)
{
snprintf(debugfs_mountpoint, sizeof(debugfs_mountpoint), "%s", mountpoint);
debugfs_set_tracing_events_path(mountpoint);
}
2 changes: 0 additions & 2 deletions tools/lib/lk/debugfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
const char *debugfs_find_mountpoint(void);
int debugfs_valid_mountpoint(const char *debugfs);
char *debugfs_mount(const char *mountpoint);
void debugfs_set_path(const char *mountpoint);

extern char debugfs_mountpoint[];
extern char tracing_events_path[];

#endif /* __LK_DEBUGFS_H__ */
6 changes: 3 additions & 3 deletions tools/perf/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
fprintf(stderr, "No directory given for --debugfs-dir.\n");
usage(perf_usage_string);
}
debugfs_set_path((*argv)[1]);
perf_debugfs_set_path((*argv)[1]);
if (envchanged)
*envchanged = 1;
(*argv)++;
(*argc)--;
} else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {
debugfs_set_path(cmd + strlen(CMD_DEBUGFS_DIR));
perf_debugfs_set_path(cmd + strlen(CMD_DEBUGFS_DIR));
fprintf(stderr, "dir: %s\n", debugfs_mountpoint);
if (envchanged)
*envchanged = 1;
Expand Down Expand Up @@ -461,7 +461,7 @@ int main(int argc, const char **argv)
if (!cmd)
cmd = "perf-help";
/* get debugfs mount point from /proc/mounts */
debugfs_mount(NULL);
perf_debugfs_mount(NULL);
/*
* "perf-xxxx" is the same as "perf xxxx", but we obviously:
*
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/trace-event-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void *malloc_or_die(unsigned int size)

static const char *find_debugfs(void)
{
const char *path = debugfs_mount(NULL);
const char *path = perf_debugfs_mount(NULL);

if (!path)
die("Your kernel not support debugfs filesystem");
Expand Down
27 changes: 27 additions & 0 deletions tools/perf/util/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ bool test_attr__enabled;
bool perf_host = true;
bool perf_guest = false;

char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events";

void event_attr_init(struct perf_event_attr *attr)
{
if (!perf_host)
Expand Down Expand Up @@ -242,3 +244,28 @@ void get_term_dimensions(struct winsize *ws)
ws->ws_row = 25;
ws->ws_col = 80;
}

static void set_tracing_events_path(const char *mountpoint)
{
snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s",
mountpoint, "tracing/events");
}

const char *perf_debugfs_mount(const char *mountpoint)
{
const char *mnt;

mnt = debugfs_mount(mountpoint);
if (!mnt)
return NULL;

set_tracing_events_path(mnt);

return mnt;
}

void perf_debugfs_set_path(const char *mntpt)
{
snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
set_tracing_events_path(mntpt);
}
7 changes: 5 additions & 2 deletions tools/perf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@
#include <linux/magic.h>
#include "types.h"
#include <sys/ttydefaults.h>
#include <lk/debugfs.h>

extern const char *graph_line;
extern const char *graph_dotted_line;
extern char buildid_dir[];
extern char tracing_events_path[];
extern void perf_debugfs_set_path(const char *mountpoint);
const char *perf_debugfs_mount(const char *mountpoint);

/* On most systems <limits.h> would have given us this, but
* not on some systems (e.g. GNU/Hurd).
Expand Down Expand Up @@ -274,5 +278,4 @@ extern unsigned int page_size;

struct winsize;
void get_term_dimensions(struct winsize *ws);

#endif
#endif /* GIT_COMPAT_UTIL_H */

0 comments on commit 1355915

Please sign in to comment.