Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 277277
b: refs/heads/master
c: ebf294b
h: refs/heads/master
i:
  277275: 033803b
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo committed Nov 28, 2011
1 parent dffa0dc commit b867489
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 52 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c168fbfb93a1c4044287858c6784f0bd1f6cfe33
refs/heads/master: ebf294bf4f147aff29df5a16bfb0f8ebca15feaa
3 changes: 2 additions & 1 deletion trunk/tools/perf/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "util/cache.h"
#include "util/debug.h"
#include "util/debugfs.h"
#include "util/evlist.h"
#include "util/parse-options.h"
#include "util/parse-events.h"
Expand Down Expand Up @@ -247,7 +248,7 @@ static int trace_event__id(const char *evname)

if (asprintf(&filename,
"%s/syscalls/%s/id",
debugfs_path, evname) < 0)
tracing_events_path, evname) < 0)
return -1;

fd = open(filename, O_RDONLY);
Expand Down
33 changes: 4 additions & 29 deletions trunk/tools/perf/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ struct pager_config {
int val;
};

static char debugfs_mntpt[MAXPATHLEN];

static int pager_command_config(const char *var, const char *value, void *data)
{
struct pager_config *c = data;
Expand Down Expand Up @@ -81,15 +79,6 @@ static void commit_pager_choice(void)
}
}

static void set_debugfs_path(void)
{
char *path;

path = getenv(PERF_DEBUGFS_ENVIRONMENT);
snprintf(debugfs_path, MAXPATHLEN, "%s/%s", path ?: debugfs_mntpt,
"tracing/events");
}

static int handle_options(const char ***argv, int *argc, int *envchanged)
{
int handled = 0;
Expand Down Expand Up @@ -161,15 +150,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
fprintf(stderr, "No directory given for --debugfs-dir.\n");
usage(perf_usage_string);
}
strncpy(debugfs_mntpt, (*argv)[1], MAXPATHLEN);
debugfs_mntpt[MAXPATHLEN - 1] = '\0';
debugfs_set_path((*argv)[1]);
if (envchanged)
*envchanged = 1;
(*argv)++;
(*argc)--;
} else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {
strncpy(debugfs_mntpt, cmd + strlen(CMD_DEBUGFS_DIR), MAXPATHLEN);
debugfs_mntpt[MAXPATHLEN - 1] = '\0';
debugfs_set_path(cmd + strlen(CMD_DEBUGFS_DIR));
fprintf(stderr, "dir: %s\n", debugfs_mountpoint);
if (envchanged)
*envchanged = 1;
} else {
Expand Down Expand Up @@ -281,7 +269,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
if (use_pager == -1 && p->option & USE_PAGER)
use_pager = 1;
commit_pager_choice();
set_debugfs_path();

status = p->fn(argc, argv, prefix);
exit_browser(status);
Expand Down Expand Up @@ -416,17 +403,6 @@ static int run_argv(int *argcp, const char ***argv)
return done_alias;
}

/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
static void get_debugfs_mntpt(void)
{
const char *path = debugfs_mount(NULL);

if (path)
strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
else
debugfs_mntpt[0] = '\0';
}

static void pthread__block_sigwinch(void)
{
sigset_t set;
Expand All @@ -453,7 +429,7 @@ int main(int argc, const char **argv)
if (!cmd)
cmd = "perf-help";
/* get debugfs mount point from /proc/mounts */
get_debugfs_mntpt();
debugfs_mount(NULL);
/*
* "perf-xxxx" is the same as "perf xxxx", but we obviously:
*
Expand All @@ -476,7 +452,6 @@ int main(int argc, const char **argv)
argc--;
handle_options(&argv, &argc, NULL);
commit_pager_choice();
set_debugfs_path();
set_buildid_dir();

if (argc > 0) {
Expand Down
25 changes: 20 additions & 5 deletions trunk/tools/perf/util/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#include "debugfs.h"
#include "cache.h"

#include <linux/kernel.h>
#include <sys/mount.h>

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

static const char *debugfs_known_mountpoints[] = {
"/sys/kernel/debug/",
Expand Down Expand Up @@ -64,7 +66,7 @@ const char *debugfs_find_mountpoint(void)
/* give up and parse /proc/mounts */
fp = fopen("/proc/mounts", "r");
if (fp == NULL)
die("Can't open /proc/mounts for read");
return NULL;

while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
debugfs_mountpoint, type) == 2) {
Expand Down Expand Up @@ -106,14 +108,20 @@ int debugfs_valid_entry(const char *path)
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 */
if (debugfs_find_mountpoint()) {
debugfs_premounted = 1;
return debugfs_mountpoint;
goto out;
}

/* if not mounted and no argument */
Expand All @@ -129,12 +137,19 @@ char *debugfs_mount(const char *mountpoint)
return NULL;

/* save the mountpoint */
strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint));
debugfs_found = 1;

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);
}

/* umount the debugfs */

int debugfs_umount(void)
Expand Down
4 changes: 4 additions & 0 deletions trunk/tools/perf/util/debugfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ int debugfs_valid_mountpoint(const char *debugfs);
int debugfs_valid_entry(const char *path);
char *debugfs_mount(const char *mountpoint);
int debugfs_umount(void);
void debugfs_set_path(const char *mountpoint);
int debugfs_write(const char *entry, const char *value);
int debugfs_read(const char *entry, char *buffer, size_t size);
void debugfs_force_cleanup(void);
int debugfs_make_path(const char *element, char *buffer, int size);

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

#endif /* __DEBUGFS_H__ */
28 changes: 13 additions & 15 deletions trunk/tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ enum event_result {
EVT_HANDLED_ALL
};

char debugfs_path[MAXPATHLEN];

#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x

Expand Down Expand Up @@ -140,7 +138,7 @@ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
char evt_path[MAXPATHLEN];
int fd;

snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", tracing_events_path,
sys_dir->d_name, evt_dir->d_name);
fd = open(evt_path, O_RDONLY);
if (fd < 0)
Expand Down Expand Up @@ -171,16 +169,16 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];

if (debugfs_valid_mountpoint(debugfs_path))
if (debugfs_valid_mountpoint(tracing_events_path))
return NULL;

sys_dir = opendir(debugfs_path);
sys_dir = opendir(tracing_events_path);
if (!sys_dir)
return NULL;

for_each_subsystem(sys_dir, sys_dirent, sys_next) {

snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
sys_dirent.d_name);
evt_dir = opendir(dir_path);
if (!evt_dir)
Expand Down Expand Up @@ -447,7 +445,7 @@ parse_single_tracepoint_event(char *sys_name,
u64 id;
int fd;

snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", tracing_events_path,
sys_name, evt_name);

fd = open(evt_path, O_RDONLY);
Expand Down Expand Up @@ -485,7 +483,7 @@ parse_multiple_tracepoint_event(struct perf_evlist *evlist, char *sys_name,
struct dirent *evt_ent;
DIR *evt_dir;

snprintf(evt_path, MAXPATHLEN, "%s/%s", debugfs_path, sys_name);
snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name);
evt_dir = opendir(evt_path);

if (!evt_dir) {
Expand Down Expand Up @@ -528,7 +526,7 @@ parse_tracepoint_event(struct perf_evlist *evlist, const char **strp,
char sys_name[MAX_EVENT_LENGTH];
unsigned int sys_length, evt_length;

if (debugfs_valid_mountpoint(debugfs_path))
if (debugfs_valid_mountpoint(tracing_events_path))
return 0;

evt_name = strchr(*strp, ':');
Expand Down Expand Up @@ -920,10 +918,10 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob)
char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];

if (debugfs_valid_mountpoint(debugfs_path))
if (debugfs_valid_mountpoint(tracing_events_path))
return;

sys_dir = opendir(debugfs_path);
sys_dir = opendir(tracing_events_path);
if (!sys_dir)
return;

Expand All @@ -932,7 +930,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob)
!strglobmatch(sys_dirent.d_name, subsys_glob))
continue;

snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
sys_dirent.d_name);
evt_dir = opendir(dir_path);
if (!evt_dir)
Expand Down Expand Up @@ -964,16 +962,16 @@ int is_valid_tracepoint(const char *event_string)
char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];

if (debugfs_valid_mountpoint(debugfs_path))
if (debugfs_valid_mountpoint(tracing_events_path))
return 0;

sys_dir = opendir(debugfs_path);
sys_dir = opendir(tracing_events_path);
if (!sys_dir)
return 0;

for_each_subsystem(sys_dir, sys_dirent, sys_next) {

snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
sys_dirent.d_name);
evt_dir = opendir(dir_path);
if (!evt_dir)
Expand Down
1 change: 0 additions & 1 deletion trunk/tools/perf/util/parse-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob);
int print_hwcache_events(const char *event_glob);
extern int is_valid_tracepoint(const char *event_string);

extern char debugfs_path[];
extern int valid_debugfs_mount(const char *debugfs);

#endif /* __PERF_PARSE_EVENTS_H */

0 comments on commit b867489

Please sign in to comment.