From 1943405871c7df43ba08c2af6c2e0b83a3aad9f2 Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Fri, 18 Mar 2011 15:07:16 -0400 Subject: trace-cmd: Add trace-cmd options Add trace-cmd options that reads all the plugins and lists the available options for trace-cmd report. Signed-off-by: Steven Rostedt --- Documentation/trace-cmd-options.1.txt | 35 +++++++++++ Documentation/trace-cmd.1.txt | 2 + Makefile | 2 +- trace-cmd.c | 3 + trace-local.h | 2 + trace-options.c | 113 ++++++++++++++++++++++++++++++++++ trace-usage.c | 5 ++ 7 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 Documentation/trace-cmd-options.1.txt create mode 100644 trace-options.c diff --git a/Documentation/trace-cmd-options.1.txt b/Documentation/trace-cmd-options.1.txt new file mode 100644 index 0000000..2373554 --- /dev/null +++ b/Documentation/trace-cmd-options.1.txt @@ -0,0 +1,35 @@ +TRACE-CMD-OPTIONS(1) +=================== + +NAME +---- +trace-cmd-options - list available options from trace-cmd plugins + +SYNOPSIS +-------- +*trace-cmd options* + +DESCRIPTION +----------- +The trace-cmd(1) options command will examine all the trace-cmd plugins +that are used by *trace-cmd report(1)* and list them. + +SEE ALSO +-------- +trace-cmd(1), trace-cmd-record(1), trace-cmd-start(1), trace-cmd-stop(1), +trace-cmd-extract(1), trace-cmd-reset(1), trace-cmd-split(1), +trace-cmd-list(1), trace-cmd-listen(1) + +AUTHOR +------ +Written by Steven Rostedt, + +RESOURCES +--------- +git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git + +COPYING +------- +Copyright \(C) 2011 Red Hat, Inc. Free use of this software is granted under +the terms of the GNU Public License (GPL). + diff --git a/Documentation/trace-cmd.1.txt b/Documentation/trace-cmd.1.txt index b67c023..f416b74 100644 --- a/Documentation/trace-cmd.1.txt +++ b/Documentation/trace-cmd.1.txt @@ -26,6 +26,8 @@ COMMANDS report - reads a trace.dat file and converts the binary data to a ASCII text readable format. + options - list the plugin options that are available to *report* + start - start the tracing without recording to a trace.dat file. stop - stop tracing (only disables recording, overhead of tracer diff --git a/Makefile b/Makefile index c4cd926..a3f1dd0 100644 --- a/Makefile +++ b/Makefile @@ -276,7 +276,7 @@ $(obj)/%.o: $(src)/%.c TRACE_GUI_OBJS = trace-filter.o trace-compat.o trace-hash.o trace-dialog.o \ trace-xml.o TRACE_CMD_OBJS = trace-cmd.o trace-record.o trace-read.o trace-split.o trace-listen.o \ - trace-stack.o + trace-stack.o trace-options.o TRACE_VIEW_OBJS = trace-view.o trace-view-store.o TRACE_GRAPH_OBJS = trace-graph.o trace-plot.o trace-plot-cpu.o trace-plot-task.o TRACE_VIEW_MAIN_OBJS = trace-view-main.o $(TRACE_VIEW_OBJS) $(TRACE_GUI_OBJS) diff --git a/trace-cmd.c b/trace-cmd.c index c0b564c..02e16c0 100644 --- a/trace-cmd.c +++ b/trace-cmd.c @@ -166,6 +166,9 @@ int main (int argc, char **argv) trace_record(argc, argv); exit(0); + } else if (strcmp(argv[1], "options") == 0) { + trace_option(argc, argv); + exit(0); } else if (strcmp(argv[1], "list") == 0) { int events = 0; int plug = 0; diff --git a/trace-local.h b/trace-local.h index a73377f..5bfa3bd 100644 --- a/trace-local.h +++ b/trace-local.h @@ -48,4 +48,6 @@ void trace_restore(int argc, char **argv); void trace_stack(int argc, char **argv); +void trace_option(int argc, char **argv); + #endif /* __TRACE_LOCAL_H */ diff --git a/trace-options.c b/trace-options.c new file mode 100644 index 0000000..70c6343 --- /dev/null +++ b/trace-options.c @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License (not later!) + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +#define _LARGEFILE64_SOURCE +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "trace-local.h" + +enum { + OPT_kallsyms = 253, + OPT_events = 254, + OPT_cpu = 255, +}; + +struct option_list { + struct option_list *next; + struct plugin_option *op; +}; + +static struct plugin_list { + struct plugin_list *next; + const char *name; + struct option_list *ops; +} *plugin_list; + +static void add_option(struct plugin_option *option) +{ + struct plugin_list *pl; + struct option_list *po; + const char *name; + + name = option->plugin_alias ? : option->file; + + for (pl = plugin_list; pl; pl = pl->next) { + if (strcmp(name, pl->name) == 0) + break; + } + if (!pl) { + pl = malloc_or_die(sizeof(*pl)); + memset(pl, 0, sizeof(*pl)); + pl->name = name; + pl->next = plugin_list; + plugin_list = pl; + }; + po = malloc_or_die(sizeof(*po)); + po->next = pl->ops; + pl->ops = po; + po->op = option; +} + +void trace_option (int argc, char **argv) +{ + struct plugin_option *options; + struct plugin_option *op; + struct plugin_list *pl; + struct plugin_list *npl; + struct option_list *po; + struct option_list *npo; + + if (argc < 2) + usage(argv); + + if (strcmp(argv[1], "options") != 0) + usage(argv); + + options = trace_util_read_plugin_options(); + if (!options) { + printf("No plugin options found\n"); + goto out; + } + + /* Group them up according to aliases */ + for (op = options; op; op = op->next) + add_option(op); + + for (pl = plugin_list; pl; pl = npl) { + npl = pl->next; + printf("%s\n", pl->name); + for (po = pl->ops; po; po = npo) { + npo = po->next; + printf(" %s: %s\n", + po->op->name, po->op->description); + free(po); + } + free(pl); + } + + out: + trace_util_free_options(options); + return; +} diff --git a/trace-usage.c b/trace-usage.c index 1497279..39c8fc1 100644 --- a/trace-usage.c +++ b/trace-usage.c @@ -110,6 +110,11 @@ static struct usage_help usage_help[] = { " if left out, will start at beginning of file\n" " end - decimal end time in seconds\n" }, + { + "options", + "list the plugin options available for trace-cmd report", + " %s options\n" + }, { "listen", "listen on a network socket for trace clients", -- cgit v1.2.2