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.

Signed-off-by: Howard Cochran <hcoch...@kernelspring.com>
---
 Documentation/trace-cmd-extract.1.txt | 16 +++++++
 trace-local.h                         |  2 +-
 trace-record.c                        | 81 +++++++++++++++++++++++++++++++++--
 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 ea98c20..73eda4e 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 ab2bd34..fb2ce71 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);
 
diff --git a/trace-record.c b/trace-record.c
index 8340416..4a78fff 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -294,18 +294,91 @@ 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;
 }
 
 /**
+ * add_all_instances - Add all pre-existing instances to the internal list
+ * @tracing_dir: The top-level tracing directory
+ *
+ * Returns whether the operation succeeded
+ */
+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;
+}
+
+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.
  * @cpu: the CPU to stat
@@ -3887,7 +3960,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 a708a85..39de386 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",
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to