From: Borislav Petkov <bp@amd64.org>
To: <peterz@infradead.org>, <mingo@elte.hu>
Cc: <tony.luck@intel.com>, <acme@infradead.org>,
<rostedt@goodmis.org>, <fweisbec@gmail.com>,
<linux-edac@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Borislav Petkov <borislav.petkov@amd.com>
Subject: [PATCH 11/12] perf: Export tracepoint_id_to_path
Date: Fri, 21 Jan 2011 16:09:34 +0100 [thread overview]
Message-ID: <1295622575-18607-12-git-send-email-bp@amd64.org> (raw)
In-Reply-To: <1295622575-18607-1-git-send-email-bp@amd64.org>
From: Borislav Petkov <borislav.petkov@amd.com>
This is needed when linking against libtrace.a so move it to
<lib/trace/trace-event-info.c> and adjust all headers accordingly.
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
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 <dirent.h>
#include <mntent.h>
#include <stdio.h>
@@ -26,6 +25,7 @@
#include <string.h>
#include <stdarg.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <pthread.h>
@@ -39,9 +39,11 @@
#include "../../perf/perf.h"
#include "trace-event.h"
-#include <lk/debugfs.h>
#include "../../perf/util/evsel.h"
+#include <lk/util.h>
+#include <lk/debugfs.h>
+
#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 <stdbool.h>
+#include <dirent.h>
#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 <lk/util.h>
#include "../perf.h"
#include "evsel.h"
#include "parse-options.h"
@@ -9,7 +8,10 @@
#include "symbol.h"
#include "cache.h"
#include "header.h"
+
#include <lk/debugfs.h>
+#include <lk/util.h>
+#include <trace/trace-event.h>
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 <linux/kernel.h>
#include <stdbool.h>
+#include <lk/util.h>
enum parse_opt_type {
/* special types */
--
1.7.4.rc2
next prev parent reply other threads:[~2011-01-21 15:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
2011-01-21 15:09 ` [PATCH 01/12] perf: Start the massive restructuring Borislav Petkov
2011-01-21 15:09 ` [PATCH 02/12] perf: Add persistent event facilities Borislav Petkov
2011-01-21 15:09 ` [PATCH 03/12] x86, mce: Add persistent MCE event Borislav Petkov
2011-01-21 15:09 ` [PATCH 04/12] perf: Add Makefile.lib Borislav Petkov
2011-01-21 15:09 ` [PATCH 05/12] perf: Export trace-event utils Borislav Petkov
2011-01-21 15:09 ` [PATCH 06/12] perf: Remove duplicate enum trace_flag_type Borislav Petkov
2011-01-21 15:09 ` [PATCH 07/12] perf: Export debugfs utilities Borislav Petkov
2011-01-21 15:09 ` [PATCH 08/12] perf: Carve out mmap helpers for general use Borislav Petkov
2011-01-21 17:29 ` Arnaldo Carvalho de Melo
2011-01-24 9:04 ` Borislav Petkov
2011-01-24 12:39 ` Arnaldo Carvalho de Melo
2011-01-26 1:00 ` Borislav Petkov
2011-01-26 13:13 ` Arnaldo Carvalho de Melo
2011-01-21 15:09 ` [PATCH 09/12] perf: Export util.ch into library Borislav Petkov
2011-01-21 15:09 ` [PATCH 10/12] perf: Export ctype.c Borislav Petkov
2011-01-21 15:09 ` Borislav Petkov [this message]
2011-01-21 15:09 ` [PATCH] ras: Add RAS daemon Borislav Petkov
2011-01-21 17:54 ` Tony Luck
2011-01-21 18:06 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1295622575-18607-12-git-send-email-bp@amd64.org \
--to=bp@amd64.org \
--cc=acme@infradead.org \
--cc=borislav.petkov@amd.com \
--cc=fweisbec@gmail.com \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.