aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVaibhav Nagarnaik <vnagarnaik@google.com>2011-08-11 15:37:37 -0400
committerSteven Rostedt <rostedt@goodmis.org>2011-08-18 21:36:47 -0400
commit72a8ce0acbe2c51b2a7e9f04f1b47057ba01d62b (patch)
treea930fda943b5cbea57ac7cd28509eefcd85d6a6a
parent01b877d01b85520496873642fb1d6f598796de2b (diff)
trace-cmd: Load plugins before parsing events in check-events
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. Cc: Michael Rubin <mrubin@google.com> Cc: David Sharp <dhsharp@google.com> Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com> Link: http://lkml.kernel.org/r/1313091459-12049-3-git-send-email-vnagarnaik@google.com Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-cmd.c22
-rw-r--r--trace-cmd.h1
-rw-r--r--trace-usage.c3
-rw-r--r--trace-util.c47
4 files changed, 53 insertions, 20 deletions
diff --git a/trace-cmd.c b/trace-cmd.c
index 5407a6c..384e218 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -162,7 +162,19 @@ int main (int argc, char **argv)
162 char *tracing; 162 char *tracing;
163 int ret; 163 int ret;
164 struct pevent *pevent = NULL; 164 struct pevent *pevent = NULL;
165 struct plugin_list *list = NULL;
165 166
167 while ((c = getopt(argc-1, argv+1, "+hN")) >= 0) {
168 switch (c) {
169 case 'h':
170 default:
171 usage(argv);
172 break;
173 case 'N':
174 tracecmd_disable_plugins = 1;
175 break;
176 }
177 }
166 tracing = tracecmd_find_tracing_dir(); 178 tracing = tracecmd_find_tracing_dir();
167 179
168 if (!tracing) { 180 if (!tracing) {
@@ -174,10 +186,14 @@ int main (int argc, char **argv)
174 exit(EINVAL); 186 exit(EINVAL);
175 } 187 }
176 188
177 ret = 0; 189 pevent = pevent_alloc();
178 pevent = tracecmd_local_events(tracing); 190 if (!pevent)
179 if (!pevent || pevent->parsing_failures) 191 exit(EINVAL);
192 list = tracecmd_load_plugins(pevent);
193 ret = tracecmd_fill_local_events(tracing, pevent);
194 if (ret || pevent->parsing_failures)
180 ret = EINVAL; 195 ret = EINVAL;
196 tracecmd_unload_plugins(list);
181 pevent_free(pevent); 197 pevent_free(pevent);
182 exit(ret); 198 exit(ret);
183 199
diff --git a/trace-cmd.h b/trace-cmd.h
index 6f04981..af0645a 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -38,6 +38,7 @@ void tracecmd_unload_plugins(struct plugin_list *list);
38char **tracecmd_event_systems(const char *tracing_dir); 38char **tracecmd_event_systems(const char *tracing_dir);
39char **tracecmd_system_events(const char *tracing_dir, const char *system); 39char **tracecmd_system_events(const char *tracing_dir, const char *system);
40struct pevent *tracecmd_local_events(const char *tracing_dir); 40struct pevent *tracecmd_local_events(const char *tracing_dir);
41int tracecmd_fill_local_events(const char *tracing_dir, struct pevent *pevent);
41char **tracecmd_local_plugins(const char *tracing_dir); 42char **tracecmd_local_plugins(const char *tracing_dir);
42 43
43char **tracecmd_add_list(char **list, const char *name, int len); 44char **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[] = {
152 { 152 {
153 "check-events", 153 "check-events",
154 "parse trace event formats", 154 "parse trace event formats",
155 " %s check-format\n" 155 " %s check-format [-N]\n"
156 " -N do not load any plugins\n"
156 }, 157 },
157 { 158 {
158 NULL, NULL, NULL 159 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)
714struct pevent *tracecmd_local_events(const char *tracing_dir) 714struct pevent *tracecmd_local_events(const char *tracing_dir)
715{ 715{
716 struct pevent *pevent = NULL; 716 struct pevent *pevent = NULL;
717
718 pevent = pevent_alloc();
719 if (!pevent)
720 return NULL;
721
722 if (tracecmd_fill_local_events(tracing_dir, pevent)) {
723 pevent_free(pevent);
724 pevent = NULL;
725 }
726
727 return pevent;
728}
729
730/**
731 * tracecmd_fill_local_events - Fill a pevent with the events on system
732 * @tracing_dir: The directory that contains the events.
733 * @pevent: Allocated pevent which will be filled
734 *
735 * Returns whether the operation succeeded
736 */
737int tracecmd_fill_local_events(const char *tracing_dir, struct pevent *pevent)
738{
717 struct dirent *dent; 739 struct dirent *dent;
718 char *events_dir; 740 char *events_dir;
719 struct stat st; 741 struct stat st;
@@ -721,35 +743,27 @@ struct pevent *tracecmd_local_events(const char *tracing_dir)
721 int ret, failure = 0; 743 int ret, failure = 0;
722 744
723 if (!tracing_dir) 745 if (!tracing_dir)
724 return NULL; 746 return -1;
725 747
726 events_dir = append_file(tracing_dir, "events"); 748 events_dir = append_file(tracing_dir, "events");
727 if (!events_dir) 749 if (!events_dir)
728 return NULL; 750 return -1;
729 751
730 ret = stat(events_dir, &st); 752 ret = stat(events_dir, &st);
731 if (ret < 0 || !S_ISDIR(st.st_mode)) { 753 if (ret < 0 || !S_ISDIR(st.st_mode)) {
732 failure = 1; 754 ret = -1;
733 goto out_free; 755 goto out_free;
734 } 756 }
735 757
736 dir = opendir(events_dir); 758 dir = opendir(events_dir);
737 if (!dir) { 759 if (!dir) {
738 failure = 1; 760 ret = -1;
739 goto out_free;
740 }
741
742 pevent = pevent_alloc();
743 if (!pevent) {
744 failure = 1;
745 goto out_free; 761 goto out_free;
746 } 762 }
747 763
748 ret = read_header(pevent, events_dir); 764 ret = read_header(pevent, events_dir);
749 if (ret < 0) { 765 if (ret < 0) {
750 pevent_free(pevent); 766 ret = -1;
751 pevent = NULL;
752 failure = 1;
753 goto out_free; 767 goto out_free;
754 } 768 }
755 769
@@ -777,14 +791,15 @@ struct pevent *tracecmd_local_events(const char *tracing_dir)
777 } 791 }
778 792
779 closedir(dir); 793 closedir(dir);
794 /* always succeed because parsing failures are not critical */
795 ret = 0;
780 796
781 out_free: 797 out_free:
782 free(events_dir); 798 free(events_dir);
783 799
784 if (pevent) 800 pevent->parsing_failures = failure;
785 pevent->parsing_failures = failure;
786 801
787 return pevent; 802 return ret;
788} 803}
789 804
790/** 805/**