From: Howard Cochran <hcochran@kernelspring.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Howard Cochran <hcochran@kernelspring.com>,
linux-kernel@vger.kernel.org,
Howard Cochran <cochran@lexmark.com>
Subject: [PATCH v3 2/5] trace-cmd extract: Add -a option for all instances
Date: Wed, 22 Apr 2015 00:55:11 -0400 [thread overview]
Message-ID: <444ea8355d8c0013ec9d35155d4ea83ec1a7bbab.1429677461.git.hcochran@kernelspring.com> (raw)
In-Reply-To: <cover.1429677461.git.hcochran@kernelspring.com>
In-Reply-To: <cover.1429677461.git.hcochran@kernelspring.com>
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 <hcochran@kernelspring.com>
---
| 16 +++++++
trace-local.h | 2 +-
trace-record.c | 81 +++++++++++++++++++++++++++++++++--
trace-usage.c | 5 ++-
4 files changed, 98 insertions(+), 6 deletions(-)
--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
next prev parent reply other threads:[~2015-04-22 4:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-22 4:55 [PATCH v3 0/5] trace-cmd: Improve multi-instance support Howard Cochran
2015-04-22 4:55 ` [PATCH v3 1/5] trace-cmd extract: Add -B and -t for multiple instances Howard Cochran
2015-04-22 4:55 ` Howard Cochran [this message]
2015-04-22 4:55 ` [PATCH v3 3/5] trace-cmd stop, reset, restart: Add -a for all instances Howard Cochran
2015-04-22 4:55 ` [PATCH v3 4/5] trace-cmd snapshot: Fully support multiple instances Howard Cochran
2015-04-22 4:55 ` [PATCH v3 5/5] trace-cmd stat: Support -a for all buffers. Update docs Howard Cochran
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=444ea8355d8c0013ec9d35155d4ea83ec1a7bbab.1429677461.git.hcochran@kernelspring.com \
--to=hcochran@kernelspring.com \
--cc=cochran@lexmark.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®