[PATCH 04/11] libtraceeval task-eval: Add way to read trace.dat buffer instances

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>

If a trace.dat file has data in a buffer instance, then task-eval should
be able to read that too. Add a "-B foo" option to task-eval that lets the
user specify a buffer instance that is within a trace.dat file.

This is used for when the trace.dat file is recorded as:

  trace-cmd record -B foo ...

The "foo" buffer is stored separately in the trace.dat file and requires
to be retrieved to be seen by libtracecmd.

Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
---
 samples/task-eval.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/samples/task-eval.c b/samples/task-eval.c
index ad3e2424acc8..40e7345a27c4 100644
--- a/samples/task-eval.c
+++ b/samples/task-eval.c
@@ -41,6 +41,7 @@ static void usage(void)
 	       "  Run this on the resulting trace.dat file\n"
 	       "\n"
 	       "-c comm - to look at only a specific process called 'comm'\n"
+	       "-B instance - read a buffer instance in the trace.dat file\n"
 	       "\n",p);
 	exit(-1);
 }
@@ -975,17 +976,21 @@ int main (int argc, char **argv)
 {
 	struct tracecmd_input *handle;
 	struct task_data data;
+	const char *buffer = NULL;
 	int c;
 
 	memset(&data, 0, sizeof(data));
 
 	argv0 = argv[0];
 
-	while ((c = getopt(argc, argv, "c:h")) >= 0) {
+	while ((c = getopt(argc, argv, "c:B:h")) >= 0) {
 		switch (c) {
 		case 'c':
 			data.comm = optarg;
 			break;
+		case 'B':
+			buffer = optarg;
+			break;
 		case 'h':
 		default:
 			usage();
@@ -1002,6 +1007,24 @@ int main (int argc, char **argv)
 	if (!handle)
 		pdie("Error opening %s", argv[0]);
 
+	if (buffer) {
+		int bufs;
+		int i;
+
+		bufs = tracecmd_buffer_instances(handle);
+		for (i = 0; i < bufs; i++) {
+			const char *name;
+
+			name = tracecmd_buffer_instance_name(handle, i);
+			if (name && strcmp(name, buffer) == 0) {
+				handle = tracecmd_buffer_instance_handle(handle, i);
+				break;
+			}
+		}
+		if (i == bufs)
+			die("Can not find instance %s\n", buffer);
+	}
+
 	data.teval_tasks = traceeval_init(task_keys, task_vals);
 	if (!data.teval_tasks)
 		pdie("Creating trace eval processe data");
-- 
2.42.0





[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux