lkml.org 
[lkml]   [2011]   [Aug]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/5] trace-cmd: Load plugins before parsing events in check-events
Date
The target check-events parses the event format strings on the local
machine and returns whether they can be parsed or not. The parsing
functionality is extended by loading plugins, if available.

This patch loads the plugins before starting parsing of the event
formats.

Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
---
trace-cmd.c | 21 ++++++++++++++++++---
trace-cmd.h | 1 +
trace-usage.c | 3 ++-
trace-util.c | 47 +++++++++++++++++++++++++++++++----------------
4 files changed, 52 insertions(+), 20 deletions(-)
diff --git a/trace-cmd.c b/trace-cmd.c
index 5cfd97f..b5bcbb3 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -162,7 +162,19 @@ int main (int argc, char **argv)
char *tracing;
int ret;
struct pevent *pevent = NULL;
+ struct plugin_list *list = NULL;

+ while ((c = getopt(argc-1, argv+1, "+hN")) >= 0) {
+ switch (c) {
+ case 'h':
+ default:
+ usage(argv);
+ break;
+ case 'N':
+ tracecmd_disable_plugins = 1;
+ break;
+ }
+ }
tracing = tracecmd_find_tracing_dir();

if (!tracing) {
@@ -175,11 +187,14 @@ int main (int argc, char **argv)
}

ret = 0;
- pevent = tracecmd_local_events(tracing);
+ pevent = pevent_alloc();
if (!pevent)
exit(EINVAL);
- if (pevent->parsing_failures)
+ list = tracecmd_load_plugins(pevent);
+ ret = tracecmd_fill_local_events(tracing, pevent);
+ if (ret || pevent->parsing_failures)
ret = EINVAL;
+ tracecmd_unload_plugins(list);
pevent_free(pevent);
exit(ret);

diff --git a/trace-cmd.h b/trace-cmd.h
index 66cdb28..d2d0cef 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -38,6 +38,7 @@ void tracecmd_unload_plugins(struct plugin_list *list);
char **tracecmd_event_systems(const char *tracing_dir);
char **tracecmd_system_events(const char *tracing_dir, const char *system);
struct pevent *tracecmd_local_events(const char *tracing_dir);
+int tracecmd_fill_local_events(const char *tracing_dir, struct pevent *pevent);
char **tracecmd_local_plugins(const char *tracing_dir);

char **tracecmd_add_list(char **list, const char *name, int len);
diff --git a/trace-usage.c b/trace-usage.c
index 58ef167..7314657 100644
--- a/trace-usage.c
+++ b/trace-usage.c
@@ -152,7 +152,8 @@ static struct usage_help usage_help[] = {
{
"check-events",
"parse trace event formats",
- " %s check-format\n"
+ " %s check-format [-N]\n"
+ " -N do not load any plugins\n"
},
{
NULL, NULL, NULL
diff --git a/trace-util.c b/trace-util.c
index 01894f8..e128188 100644
--- a/trace-util.c
+++ b/trace-util.c
@@ -714,6 +714,28 @@ static int read_header(struct pevent *pevent, const char *events_dir)
struct pevent *tracecmd_local_events(const char *tracing_dir)
{
struct pevent *pevent = NULL;
+
+ pevent = pevent_alloc();
+ if (!pevent)
+ return NULL;
+
+ if (tracecmd_fill_local_events(tracing_dir, pevent)) {
+ pevent_free(pevent);
+ pevent = NULL;
+ }
+
+ return pevent;
+}
+
+/**
+ * tracecmd_fill_local_events - Fill a pevent with the events on system
+ * @tracing_dir: The directory that contains the events.
+ * @pevent: Allocated pevent which will be filled
+ *
+ * Returns whether the operation succeeded
+ */
+int tracecmd_fill_local_events(const char *tracing_dir, struct pevent *pevent)
+{
struct dirent *dent;
char *events_dir;
struct stat st;
@@ -721,35 +743,27 @@ struct pevent *tracecmd_local_events(const char *tracing_dir)
int ret, failure = 0;

if (!tracing_dir)
- return NULL;
+ return -1;

events_dir = append_file(tracing_dir, "events");
if (!events_dir)
- return NULL;
+ return -1;

ret = stat(events_dir, &st);
if (ret < 0 || !S_ISDIR(st.st_mode)) {
- failure = 1;
+ ret = -1;
goto out_free;
}

dir = opendir(events_dir);
if (!dir) {
- failure = 1;
- goto out_free;
- }
-
- pevent = pevent_alloc();
- if (!pevent) {
- failure = 1;
+ ret = -1;
goto out_free;
}

ret = read_header(pevent, events_dir);
if (ret < 0) {
- pevent_free(pevent);
- pevent = NULL;
- failure = 1;
+ ret = -1;
goto out_free;
}

@@ -777,14 +791,15 @@ struct pevent *tracecmd_local_events(const char *tracing_dir)
}

closedir(dir);
+ /* always succeed because parsing failures are not critical */
+ ret = 0;

out_free:
free(events_dir);

- if (pevent)
- pevent->parsing_failures = failure;
+ pevent->parsing_failures = failure;

- return pevent;
+ return ret;
}

/**
--
1.7.3.1


\
 
 \ /
  Last update: 2011-08-11 21:41    [W:0.164 / U:0.036 seconds]
©2003-2014 Jasper Spaans. Advertise on this site