diff options
author | Howard Cochran <hcochran@kernelspring.com> | 2015-04-21 02:10:50 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2015-06-10 15:09:35 -0400 |
commit | 1ccedcd4333a789f34d476ce74571ccb8d4f68d3 (patch) | |
tree | 184f99c8284a82a4d04f203f83000ce82a9901dd | |
parent | 7927947958d1a12efd6f9fe7707f937bb908ddbf (diff) | |
download | trace-cmd-1ccedcd4333a789f34d476ce74571ccb8d4f68d3.tar.gz |
trace-cmd extract: Add -a option for all instances
This option will extract all instances that currently exist in the
system, including the top instance. This differs from the meaning of -a
for record and stream (enable all events), which would have no purpose
for extract. Such difference in meaning already exists for -s, so this
seemed reasonable.
Had to fix a bug in create_instance(), in which it ignored its parameter.
Link: http://lkml.kernel.org/r/444ea8355d8c0013ec9d35155d4ea83ec1a7bbab.1429677461.git.hcochran@kernelspring.com
Signed-off-by: Howard Cochran <hcochran@kernelspring.com>
[ Fixed compile error to use different __add_all_instances() ]
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | Documentation/trace-cmd-extract.1.txt | 16 | ||||
-rw-r--r-- | trace-local.h | 2 | ||||
-rw-r--r-- | trace-record.c | 81 | ||||
-rw-r--r-- | trace-usage.c | 5 |
4 files changed, 98 insertions, 6 deletions
diff --git a/Documentation/trace-cmd-extract.1.txt b/Documentation/trace-cmd-extract.1.txt index ea98c209..73eda4ed 100644 --- a/Documentation/trace-cmd-extract.1.txt +++ b/Documentation/trace-cmd-extract.1.txt @@ -52,6 +52,22 @@ OPTIONS does cause the extract routine to disable all tracing. That is, the end of the extract will perform something similar to trace-cmd-reset(1). +*-B* 'buffer-name':: + If the kernel supports multiple buffers, this will extract the trace for + only the given buffer. It does not affect any other buffer. This may be + used multiple times to specify different buffers. When this option is + used, the top level instance will not be extracted unless *-t* is given. + +*-a*:: + Extract all existing buffer instances. When this option is used, the + top level instance will not be extracted unless *-t* is given. + +*-t*:: + Extracts the top level instance buffer. Without the *-B* or *-a* option + this is the same as the default. But if *-B* or *-a* is used, this is + required if the top level instance buffer should also be extracted. + + SEE ALSO -------- trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1), diff --git a/trace-local.h b/trace-local.h index cbdac8e0..06989a7d 100644 --- a/trace-local.h +++ b/trace-local.h @@ -176,7 +176,7 @@ extern struct buffer_instance *first_instance; #define for_all_instances(i) for (i = first_instance; i; \ i = i == &top_instance ? buffer_instances : (i)->next) -struct buffer_instance *create_instance(char *name); +struct buffer_instance *create_instance(const char *name); void add_instance(struct buffer_instance *instance); char *get_instance_file(struct buffer_instance *instance, const char *file); void update_first_instance(struct buffer_instance *instance, int topt); diff --git a/trace-record.c b/trace-record.c index 9dc0effb..ebfa520a 100644 --- a/trace-record.c +++ b/trace-record.c @@ -296,17 +296,90 @@ void add_instance(struct buffer_instance *instance) * Returns a newly allocated instance. Note that @name will not be * copied, and the instance buffer will point to the string itself. */ -struct buffer_instance *create_instance(char *name) +struct buffer_instance *create_instance(const char *name) { struct buffer_instance *instance; instance = malloc_or_die(sizeof(*instance)); memset(instance, 0, sizeof(*instance)); - instance->name = optarg; + instance->name = name; return instance; } +static int __add_all_instances(const char *tracing_dir) +{ + struct dirent *dent; + char *instances_dir; + struct stat st; + DIR *dir; + int ret; + + if (!tracing_dir) + return -1; + + instances_dir = append_file(tracing_dir, "instances"); + if (!instances_dir) + return -1; + + ret = stat(instances_dir, &st); + if (ret < 0 || !S_ISDIR(st.st_mode)) { + ret = -1; + goto out_free; + } + + dir = opendir(instances_dir); + if (!dir) { + ret = -1; + goto out_free; + } + + while ((dent = readdir(dir))) { + const char *name = strdup(dent->d_name); + char *instance_path; + struct buffer_instance *instance; + + if (strcmp(name, ".") == 0 || + strcmp(name, "..") == 0) + continue; + + instance_path = append_file(instances_dir, name); + ret = stat(instance_path, &st); + if (ret < 0 || !S_ISDIR(st.st_mode)) { + free(instance_path); + continue; + } + free(instance_path); + + instance = create_instance(name); + add_instance(instance); + } + + closedir(dir); + ret = 0; + + out_free: + free(instances_dir); + return ret; +} + +/** + * add_all_instances - Add all pre-existing instances to the internal list + * @tracing_dir: The top-level tracing directory + * + * Returns whether the operation succeeded + */ +void add_all_instances(void) +{ + char *tracing_dir = tracecmd_find_tracing_dir(); + if (!tracing_dir) + die("malloc"); + + __add_all_instances(tracing_dir); + + tracecmd_put_tracing_file(tracing_dir); +} + /** * tracecmd_stat_cpu - show the buffer stats of a particular CPU * @s: the trace_seq to record the data in. @@ -3889,7 +3962,9 @@ void trace_record (int argc, char **argv) usage(argv); break; case 'a': - if (!extract) { + if (extract) { + add_all_instances(); + } else { record_all = 1; record_all_events(); } diff --git a/trace-usage.c b/trace-usage.c index a708a851..39de3862 100644 --- a/trace-usage.c +++ b/trace-usage.c @@ -62,11 +62,12 @@ static struct usage_help usage_help[] = { { "extract", "extract a trace from the kernel", - " %s extract [-p plugin][-O option][-o file][-B buf][-s][-t]\n" + " %s extract [-p plugin][-O option][-o file][-B buf][-s][-a][-t]\n" " Uses similar options as record, but only reads an existing trace.\n" " -s : extract the snapshot instead of the main buffer\n" " -B : extract a given buffer (more than one may be specified)\n" - " -t : include the top level buffer (useful with -B)\n" + " -a : extract all buffers (except top one)\n" + " -t : extract the top level buffer (useful with -B and -a)\n" }, { "stop", |