From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754245Ab1AUPIZ (ORCPT ); Fri, 21 Jan 2011 10:08:25 -0500 Received: from s15228384.onlinehome-server.info ([87.106.30.177]:58536 "EHLO mail.x86-64.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754164Ab1AUPIL (ORCPT ); Fri, 21 Jan 2011 10:08:11 -0500 From: Borislav Petkov To: , Cc: , , , , , , Borislav Petkov Subject: [PATCH 11/12] perf: Export tracepoint_id_to_path Date: Fri, 21 Jan 2011 16:09:34 +0100 Message-Id: <1295622575-18607-12-git-send-email-bp@amd64.org> X-Mailer: git-send-email 1.7.4.rc2 In-Reply-To: <1295622575-18607-1-git-send-email-bp@amd64.org> References: <1295622575-18607-1-git-send-email-bp@amd64.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov This is needed when linking against libtrace.a so move it to and adjust all headers accordingly. Signed-off-by: Borislav Petkov --- tools/lib/trace/trace-event-info.c | 123 ++++++++++++++++++++++++++++++----- tools/lib/trace/trace-event.h | 19 ++++++ tools/perf/util/parse-events.c | 104 +----------------------------- tools/perf/util/parse-events.h | 1 - tools/perf/util/parse-options.h | 1 + 5 files changed, 128 insertions(+), 120 deletions(-) diff --git a/tools/lib/trace/trace-event-info.c b/tools/lib/trace/trace-event-info.c index 808bdfa..77fade5 100644 --- a/tools/lib/trace/trace-event-info.c +++ b/tools/lib/trace/trace-event-info.c @@ -18,7 +18,6 @@ * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#define _GNU_SOURCE #include #include #include @@ -26,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -39,9 +39,11 @@ #include "../../perf/perf.h" #include "trace-event.h" -#include #include "../../perf/util/evsel.h" +#include +#include + #define VERSION "0.5" #define _STR(x) #x @@ -58,6 +60,7 @@ unsigned int page_size; static const char *output_file = "trace.info"; +static const char *dfs_path; static int output_fd; struct event_list { @@ -72,7 +75,7 @@ struct events { char *name; }; -static void die(const char *fmt, ...) +static void t_die(const char *fmt, ...) { va_list ap; int ret = errno; @@ -97,7 +100,7 @@ void *malloc_or_die(unsigned int size) data = malloc(size); if (!data) - die("malloc"); + t_die("malloc"); return data; } @@ -106,7 +109,7 @@ static const char *find_debugfs(void) const char *path = debugfs_mount(NULL); if (!path) - die("Your kernel not support debugfs filesystem"); + t_die("Your kernel not support debugfs filesystem"); return path; } @@ -167,7 +170,7 @@ static ssize_t write_or_die(const void *buf, size_t len) ret = write(output_fd, buf, len); if (ret < 0) - die("writing to '%s'", output_file); + t_die("writing to '%s'", output_file); return ret; } @@ -205,7 +208,7 @@ static unsigned long long copy_file(const char *file) fd = open(file, O_RDONLY); if (fd < 0) - die("Can't read '%s'", file); + t_die("Can't read '%s'", file); size = copy_file_fd(fd); close(fd); @@ -236,7 +239,7 @@ unsigned long get_filesize(const char *file) fd = open(file, O_RDONLY); if (fd < 0) - die("Can't read '%s'", file); + t_die("Can't read '%s'", file); size = get_size_fd(fd); close(fd); @@ -252,7 +255,7 @@ static void read_header_files(void) path = get_tracing_file("events/header_page"); fd = open(path, O_RDONLY); if (fd < 0) - die("can't read '%s'", path); + t_die("can't read '%s'", path); /* unfortunately, you can not stat debugfs files for size */ size = get_size_fd(fd); @@ -263,14 +266,14 @@ static void read_header_files(void) close(fd); if (size != check_size) - die("wrong size for '%s' size=%lld read=%lld", + t_die("wrong size for '%s' size=%lld read=%lld", path, size, check_size); put_tracing_file(path); path = get_tracing_file("events/header_event"); fd = open(path, O_RDONLY); if (fd < 0) - die("can't read '%s'", path); + t_die("can't read '%s'", path); size = get_size_fd(fd); @@ -278,7 +281,7 @@ static void read_header_files(void) write_or_die(&size, 8); check_size = copy_file_fd(fd); if (size != check_size) - die("wrong size for '%s'", path); + t_die("wrong size for '%s'", path); put_tracing_file(path); close(fd); } @@ -306,7 +309,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps) dir = opendir(sys); if (!dir) - die("can't read directory '%s'", sys); + t_die("can't read directory '%s'", sys); while ((dent = readdir(dir))) { if (dent->d_type != DT_DIR || @@ -342,7 +345,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps) write_or_die(&size, 8); check_size = copy_file(format); if (size != check_size) - die("error in size of file '%s'", format); + t_die("error in size of file '%s'", format); } free(format); @@ -386,7 +389,7 @@ static void read_event_files(struct tracepoint_path *tps) dir = opendir(path); if (!dir) - die("can't read directory '%s'", path); + t_die("can't read directory '%s'", path); while ((dent = readdir(dir))) { if (dent->d_type != DT_DIR || @@ -440,7 +443,7 @@ static void read_proc_kallsyms(void) write_or_die(&size, 4); check_size = copy_file(path); if (size != check_size) - die("error in size of file '%s'", path); + t_die("error in size of file '%s'", path); } @@ -463,11 +466,95 @@ static void read_ftrace_printk(void) write_or_die(&size, 4); check_size = copy_file(path); if (size != check_size) - die("error in size of file '%s'", path); + t_die("error in size of file '%s'", path); out: put_tracing_file(path); } +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", dfs_path, + sys_dir->d_name, evt_dir->d_name); + fd = open(evt_path, O_RDONLY); + if (fd < 0) + return -EINVAL; + close(fd); + + return 0; +} + +struct tracepoint_path *tracepoint_id_to_path(u64 config) +{ + struct tracepoint_path *path = NULL; + DIR *sys_dir, *evt_dir; + struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; + char id_buf[4]; + int fd; + u64 id; + char evt_path[MAXPATHLEN]; + char dir_path[MAXPATHLEN]; + + dfs_path = debugfs_mount(NULL); + if (!dfs_path) + return NULL; + + sys_dir = opendir(dfs_path); + if (!sys_dir) + return NULL; + + for_each_subsystem(sys_dir, sys_dirent, sys_next) { + + snprintf(dir_path, MAXPATHLEN, "%s/%s", dfs_path, + sys_dirent.d_name); + evt_dir = opendir(dir_path); + if (!evt_dir) + continue; + + for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { + + snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, + evt_dirent.d_name); + fd = open(evt_path, O_RDONLY); + if (fd < 0) + continue; + if (read(fd, id_buf, sizeof(id_buf)) < 0) { + close(fd); + continue; + } + close(fd); + id = atoll(id_buf); + if (id == config) { + closedir(evt_dir); + closedir(sys_dir); + path = zalloc(sizeof(*path)); + path->system = malloc(MAX_EVENT_LENGTH); + if (!path->system) { + free(path); + return NULL; + } + path->name = malloc(MAX_EVENT_LENGTH); + if (!path->name) { + free(path->system); + free(path); + return NULL; + } + strncpy(path->system, sys_dirent.d_name, + MAX_EVENT_LENGTH); + strncpy(path->name, evt_dirent.d_name, + MAX_EVENT_LENGTH); + return path; + } + } + closedir(evt_dir); + } + + closedir(sys_dir); + return NULL; +} + static struct tracepoint_path * get_tracepoints_path(struct list_head *pattrs) { @@ -481,7 +568,7 @@ get_tracepoints_path(struct list_head *pattrs) ++nr_tracepoints; ppath->next = tracepoint_id_to_path(pos->attr.config); if (!ppath->next) - die("%s\n", "No memory to alloc tracepoints list"); + t_die("%s\n", "No memory to alloc tracepoints list"); ppath = ppath->next; } diff --git a/tools/lib/trace/trace-event.h b/tools/lib/trace/trace-event.h index 0c06b5b..501e1ad 100644 --- a/tools/lib/trace/trace-event.h +++ b/tools/lib/trace/trace-event.h @@ -2,6 +2,7 @@ #define __LIB_TRACE_EVENTS_H #include +#include #include "../../perf/util/parse-events.h" #define __unused __attribute__((unused)) @@ -312,4 +313,22 @@ int common_pc(struct scripting_context *context); int common_flags(struct scripting_context *context); int common_lock_depth(struct scripting_context *context); +#define MAX_EVENT_LENGTH 512 +#define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1) + +#define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ + while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ + if (sys_dirent.d_type == DT_DIR && \ + (strcmp(sys_dirent.d_name, ".")) && \ + (strcmp(sys_dirent.d_name, ".."))) + +#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \ + while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ + if (evt_dirent.d_type == DT_DIR && \ + (strcmp(evt_dirent.d_name, ".")) && \ + (strcmp(evt_dirent.d_name, "..")) && \ + (!tp_event_has_id(&sys_dirent, &evt_dirent))) + +extern int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir); +extern struct tracepoint_path *tracepoint_id_to_path(u64 config); #endif /* __LIB_TRACE_EVENTS_H */ diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index b17b01f..f336cba 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1,5 +1,4 @@ #include "../../../include/linux/hw_breakpoint.h" -#include #include "../perf.h" #include "evsel.h" #include "parse-options.h" @@ -9,7 +8,10 @@ #include "symbol.h" #include "cache.h" #include "header.h" + #include +#include +#include int nr_counters; @@ -125,106 +127,6 @@ static unsigned long hw_cache_stat[C(MAX)] = { [C(BPU)] = (CACHE_READ), }; -#define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ - while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ - if (sys_dirent.d_type == DT_DIR && \ - (strcmp(sys_dirent.d_name, ".")) && \ - (strcmp(sys_dirent.d_name, ".."))) - -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, - sys_dir->d_name, evt_dir->d_name); - fd = open(evt_path, O_RDONLY); - if (fd < 0) - return -EINVAL; - close(fd); - - return 0; -} - -#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \ - while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ - if (evt_dirent.d_type == DT_DIR && \ - (strcmp(evt_dirent.d_name, ".")) && \ - (strcmp(evt_dirent.d_name, "..")) && \ - (!tp_event_has_id(&sys_dirent, &evt_dirent))) - -#define MAX_EVENT_LENGTH 512 - - -struct tracepoint_path *tracepoint_id_to_path(u64 config) -{ - struct tracepoint_path *path = NULL; - DIR *sys_dir, *evt_dir; - struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; - char id_buf[4]; - int fd; - u64 id; - char evt_path[MAXPATHLEN]; - char dir_path[MAXPATHLEN]; - - if (debugfs_valid_mountpoint(debugfs_path)) - return NULL; - - sys_dir = opendir(debugfs_path); - if (!sys_dir) - return NULL; - - for_each_subsystem(sys_dir, sys_dirent, sys_next) { - - snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, - sys_dirent.d_name); - evt_dir = opendir(dir_path); - if (!evt_dir) - continue; - - for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { - - snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, - evt_dirent.d_name); - fd = open(evt_path, O_RDONLY); - if (fd < 0) - continue; - if (read(fd, id_buf, sizeof(id_buf)) < 0) { - close(fd); - continue; - } - close(fd); - id = atoll(id_buf); - if (id == config) { - closedir(evt_dir); - closedir(sys_dir); - path = zalloc(sizeof(*path)); - path->system = malloc(MAX_EVENT_LENGTH); - if (!path->system) { - free(path); - return NULL; - } - path->name = malloc(MAX_EVENT_LENGTH); - if (!path->name) { - free(path->system); - free(path); - return NULL; - } - strncpy(path->system, sys_dirent.d_name, - MAX_EVENT_LENGTH); - strncpy(path->name, evt_dirent.d_name, - MAX_EVENT_LENGTH); - return path; - } - } - closedir(evt_dir); - } - - closedir(sys_dir); - return NULL; -} - -#define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1) static const char *tracepoint_id_to_name(u64 config) { static char buf[TP_PATH_LEN]; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index c29c407..946dc44 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -23,7 +23,6 @@ struct tracepoint_path { struct tracepoint_path *next; }; -extern struct tracepoint_path *tracepoint_id_to_path(u64 config); extern bool have_tracepoints(struct list_head *evsel_list); extern int nr_counters; diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h index abc31a1..6bcb9a4 100644 --- a/tools/perf/util/parse-options.h +++ b/tools/perf/util/parse-options.h @@ -3,6 +3,7 @@ #include #include +#include enum parse_opt_type { /* special types */ -- 1.7.4.rc2