From patchwork Fri Jan 12 08:39:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 13518027 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACE0A537E4 for ; Fri, 12 Jan 2024 08:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1C5A42F4; Fri, 12 Jan 2024 00:40:44 -0800 (PST) Received: from e126645.arm.com (unknown [10.57.77.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EE1CE3F64C; Fri, 12 Jan 2024 00:39:56 -0800 (PST) From: Pierre Gondois To: Linux Trace Devel Cc: Steven Rostedt , Pierre Gondois Subject: [PATCH 1/5] trace-cmd: split: Small fixes Date: Fri, 12 Jan 2024 09:39:41 +0100 Message-Id: <20240112083945.1361293-2-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240112083945.1361293-1-pierre.gondois@arm.com> References: <20240112083945.1361293-1-pierre.gondois@arm.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Small fixes: - Remove a useless assignment to 'current' variable. - Fix returned type of parse_file() Signed-off-by: Pierre Gondois --- tracecmd/trace-split.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c index 4fda7813..6ccda2fc 100644 --- a/tracecmd/trace-split.c +++ b/tracecmd/trace-split.c @@ -347,11 +347,12 @@ static int parse_cpu(struct tracecmd_input *handle, return 0; } -static double parse_file(struct tracecmd_input *handle, - const char *output_file, - unsigned long long start, - unsigned long long end, int percpu, int only_cpu, - int count, enum split_types type) +static unsigned long long parse_file(struct tracecmd_input *handle, + const char *output_file, + unsigned long long start, + unsigned long long end, int percpu, + int only_cpu, int count, + enum split_types type) { unsigned long long current; struct tracecmd_output *ohandle; @@ -551,7 +552,6 @@ void trace_split (int argc, char **argv) strcat(output, ".1"); } - current = start_ns; output_file = malloc(strlen(output) + 50); if (!output_file) die("Failed to allocate for %s", output); From patchwork Fri Jan 12 08:39:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 13518028 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD96B53E14 for ; Fri, 12 Jan 2024 08:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 517CB12FC; Fri, 12 Jan 2024 00:40:45 -0800 (PST) Received: from e126645.arm.com (unknown [10.57.77.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2DFEF3F64C; Fri, 12 Jan 2024 00:39:58 -0800 (PST) From: Pierre Gondois To: Linux Trace Devel Cc: Steven Rostedt , Pierre Gondois Subject: [PATCH 2/5] trace-cmd: usage: Update usage for trace-cmd split Date: Fri, 12 Jan 2024 09:39:42 +0100 Message-Id: <20240112083945.1361293-3-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240112083945.1361293-1-pierre.gondois@arm.com> References: <20240112083945.1361293-1-pierre.gondois@arm.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Update usage for 'trace-cmd split' command. Signed-off-by: Pierre Gondois --- tracecmd/trace-split.c | 21 +++++++++++++-------- tracecmd/trace-usage.c | 3 ++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c index 6ccda2fc..b6c056b5 100644 --- a/tracecmd/trace-split.c +++ b/tracecmd/trace-split.c @@ -198,7 +198,7 @@ static int parse_cpu(struct tracecmd_input *handle, unsigned long long start, unsigned long long end, int count_limit, int percpu, int cpu, - enum split_types type) + enum split_types type, bool *end_reached) { struct tep_record *record; struct tep_handle *pevent; @@ -325,6 +325,9 @@ static int parse_cpu(struct tracecmd_input *handle, } } + if (record && (record->ts > end)) + *end_reached = true; + if (record) tracecmd_free_record(record); @@ -352,7 +355,8 @@ static unsigned long long parse_file(struct tracecmd_input *handle, unsigned long long start, unsigned long long end, int percpu, int only_cpu, int count, - enum split_types type) + enum split_types type, + bool *end_reached) { unsigned long long current; struct tracecmd_output *ohandle; @@ -396,14 +400,14 @@ static unsigned long long parse_file(struct tracecmd_input *handle, if (only_cpu >= 0) { parse_cpu(handle, cpu_data, start, end, count, - 1, only_cpu, type); + 1, only_cpu, type, end_reached); } else if (percpu) { for (cpu = 0; cpu < cpus; cpu++) parse_cpu(handle, cpu_data, start, - end, count, percpu, cpu, type); + end, count, percpu, cpu, type, end_reached); } else parse_cpu(handle, cpu_data, start, - end, count, percpu, -1, type); + end, count, percpu, -1, type, end_reached); cpu_list = malloc(sizeof(*cpu_list) * cpus); if (!cpu_list) @@ -415,7 +419,6 @@ static unsigned long long parse_file(struct tracecmd_input *handle, if (tracecmd_append_cpu_data(ohandle, cpus, cpu_list) < 0) die("Failed to append tracing data\n"); - current = end; for (cpu = 0; cpu < cpus; cpu++) { /* Set the tracecmd cursor to the next set of records */ if (cpu_data[cpu].offset) { @@ -440,6 +443,7 @@ void trace_split (int argc, char **argv) struct tracecmd_input *handle; unsigned long long start_ns = 0, end_ns = 0; unsigned long long current; + bool end_reached = false; double start, end; char *endptr; char *output = NULL; @@ -564,11 +568,12 @@ void trace_split (int argc, char **argv) strcpy(output_file, output); current = parse_file(handle, output_file, start_ns, end_ns, - percpu, cpu, count, type); + percpu, cpu, count, type, &end_reached); + if (!repeat) break; start_ns = 0; - } while (current && (!end_ns || current < end_ns)); + } while (!end_reached && (current && (!end_ns || current < end_ns))); free(output); free(output_file); diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c index 61acce5f..433928d3 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -303,13 +303,14 @@ static struct usage_help usage_help[] = { { "split", "parse a trace.dat file into smaller file(s)", - " %s split [options] -o file [start [end]]\n" + " %s split [-i file] [options] -o file [start [end]]\n" " -o output file to write to (file.1, file.2, etc)\n" " -s n split file up by n seconds\n" " -m n split file up by n milliseconds\n" " -u n split file up by n microseconds\n" " -e n split file up by n events\n" " -p n split file up by n pages\n" + " -C n select CPU n\n" " -r repeat from start to end\n" " -c per cpu, that is -p 2 will be 2 pages for each CPU\n" " if option is specified, it will split the file\n" From patchwork Fri Jan 12 08:39:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 13518029 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E6622482F7 for ; Fri, 12 Jan 2024 08:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BD44A1424; Fri, 12 Jan 2024 00:40:46 -0800 (PST) Received: from e126645.arm.com (unknown [10.57.77.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 82AEB3F64C; Fri, 12 Jan 2024 00:39:59 -0800 (PST) From: Pierre Gondois To: Linux Trace Devel Cc: Steven Rostedt , Pierre Gondois Subject: [PATCH 3/5] trace-cmd: split: Store instances in local list Date: Fri, 12 Jan 2024 09:39:43 +0100 Message-Id: <20240112083945.1361293-4-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240112083945.1361293-1-pierre.gondois@arm.com> References: <20240112083945.1361293-1-pierre.gondois@arm.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To prepare handling of multiple instances, store instance handles in a local list, similarly to what is currently done in tracecmd/trace-read.c. To help achieve this goal, add a 'struct handle_list' and a add_handle() function. Signed-off-by: Pierre Gondois --- tracecmd/trace-split.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c index b6c056b5..f2edfbfc 100644 --- a/tracecmd/trace-split.c +++ b/tracecmd/trace-split.c @@ -19,6 +19,7 @@ #include #include +#include "list.h" #include "trace-local.h" static unsigned int page_size; @@ -49,6 +50,26 @@ struct cpu_data { char *file; }; +struct handle_list { + struct list_head list; + const char *name; + struct tracecmd_input *handle; +}; + +static struct list_head handle_list; + +static void add_handle(struct tracecmd_input *handle, const char *name) +{ + struct handle_list *item; + + item = calloc(1, sizeof(*item)); + if (!item) + die("Failed ot allocate"); + item->handle = handle; + item->name = name; + list_add_tail(&item->list, &handle_list); +} + static int create_type_len(struct tep_handle *pevent, int time, int len) { static int bigendian = -1; @@ -450,6 +471,7 @@ void trace_split (int argc, char **argv) char *output_file; enum split_types split_type = SPLIT_NONE; enum split_types type = SPLIT_NONE; + int instances; int count; int repeat = 0; int percpu = 0; @@ -457,6 +479,8 @@ void trace_split (int argc, char **argv) int ac; int c; + list_head_init(&handle_list); + if (strcmp(argv[1], "split") != 0) usage(argv); @@ -561,6 +585,26 @@ void trace_split (int argc, char **argv) die("Failed to allocate for %s", output); c = 1; + add_handle(handle, NULL); + instances = tracecmd_buffer_instances(handle); + if (instances) { + struct tracecmd_input *new_handle; + const char *name; + int i; + + for (i = 0; i < instances; i++) { + name = tracecmd_buffer_instance_name(handle, i); + if (!name) + die("error in reading buffer instance"); + new_handle = tracecmd_buffer_instance_handle(handle, i); + if (!new_handle) { + warning("could not retrieve handle %s", name); + continue; + } + add_handle(new_handle, name); + } + } + do { if (repeat) sprintf(output_file, "%s.%04d", output, c++); From patchwork Fri Jan 12 08:39:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 13518030 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5A84537F1 for ; Fri, 12 Jan 2024 08:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1B144143D; Fri, 12 Jan 2024 00:40:48 -0800 (PST) Received: from e126645.arm.com (unknown [10.57.77.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EDA563F64C; Fri, 12 Jan 2024 00:40:00 -0800 (PST) From: Pierre Gondois To: Linux Trace Devel Cc: Steven Rostedt , Pierre Gondois Subject: [PATCH 4/5] trace-cmd: split: Add functions to generate temp files Date: Fri, 12 Jan 2024 09:39:44 +0100 Message-Id: <20240112083945.1361293-5-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240112083945.1361293-1-pierre.gondois@arm.com> References: <20240112083945.1361293-1-pierre.gondois@arm.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To prepare handling of multiple instances and storing them in temporary files, add utility functions generating file names, removing files, creating files: - get_temp_file() - delete_temp_file() - put_temp_file() - touch_file() Also make use these functions. Signed-off-by: Pierre Gondois --- tracecmd/trace-split.c | 71 +++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c index f2edfbfc..6ab138a2 100644 --- a/tracecmd/trace-split.c +++ b/tracecmd/trace-split.c @@ -371,6 +371,52 @@ static int parse_cpu(struct tracecmd_input *handle, return 0; } +static char *get_temp_file(const char *output_file, const char *name, int cpu) +{ + const char *dot; + char *file = NULL; + char *output; + char *base; + char *dir; + int ret; + + if (name) + dot = "."; + else + dot = name = ""; + + output = strdup(output_file); + /* Extract basename() first, as dirname() truncates output */ + base = basename(output); + dir = dirname(output); + + ret = asprintf(&file, "%s/.tmp.%s.%s%s%d", dir, base, name, dot, cpu); + if (ret < 0) + die("Failed to allocate file for %s %s %s %d", dir, base, name, cpu); + free(output); + return file; +} + +static void delete_temp_file(const char *name) +{ + unlink(name); +} + +static void put_temp_file(char *file) +{ + free(file); +} + +static void touch_file(const char *file) +{ + int fd; + + fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd < 0) + die("could not create file %s\n", file); + close(fd); +} + static unsigned long long parse_file(struct tracecmd_input *handle, const char *output_file, unsigned long long start, @@ -384,19 +430,12 @@ static unsigned long long parse_file(struct tracecmd_input *handle, struct cpu_data *cpu_data; struct tep_record *record; char **cpu_list; - char *output; - char *base; char *file; - char *dir; int cpus; int cpu; + int ret; int fd; - output = strdup(output_file); - /* Extract basename() first, as dirname() truncates output */ - base = basename(output); - dir = dirname(output); - ohandle = tracecmd_copy(handle, output_file, TRACECMD_FILE_CMD_LINES, 0, NULL); cpus = tracecmd_cpus(handle); @@ -405,11 +444,9 @@ static unsigned long long parse_file(struct tracecmd_input *handle, die("Failed to allocate cpu_data for %d cpus", cpus); for (cpu = 0; cpu < cpus; cpu++) { - int ret; + file = get_temp_file(output_file, NULL, cpu); + touch_file(file); - ret = asprintf(&file, "%s/.tmp.%s.%d", dir, base, cpu); - if (ret < 0) - die("Failed to allocate file for %s %s %d", dir, base, cpu); fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); cpu_data[cpu].cpu = cpu; cpu_data[cpu].fd = fd; @@ -448,12 +485,16 @@ static unsigned long long parse_file(struct tracecmd_input *handle, current = record->ts + 1; tracecmd_free_record(record); } - unlink(cpu_data[cpu].file); - free(cpu_data[cpu].file); + } + + for (cpu = 0; cpu < cpus; cpu++) { + close(cpu_data[cpu].fd); + delete_temp_file(cpu_data[cpu].file); + put_temp_file(cpu_data[cpu].file); } free(cpu_data); free(cpu_list); - free(output); + tracecmd_output_close(ohandle); return current; From patchwork Fri Jan 12 08:39:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 13518031 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E788482F7 for ; Fri, 12 Jan 2024 08:40:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 69A221570; Fri, 12 Jan 2024 00:40:49 -0800 (PST) Received: from e126645.arm.com (unknown [10.57.77.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 231F23F64C; Fri, 12 Jan 2024 00:40:02 -0800 (PST) From: Pierre Gondois To: Linux Trace Devel Cc: Steven Rostedt , Pierre Gondois Subject: [PATCH 5/5] trace-cmd: split: Handle splitting files with multiple instances Date: Fri, 12 Jan 2024 09:39:45 +0100 Message-Id: <20240112083945.1361293-6-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240112083945.1361293-1-pierre.gondois@arm.com> References: <20240112083945.1361293-1-pierre.gondois@arm.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 trace-cmd can record events in multiple instances: $ trace-cmd record -e sched_wakeup -B test_instance -e sched_switch When trying to split a trace.dat file recorded with the above command, only the events located in the main buffer seems to be split. The events recorded in the test_instance buffer seem to be discarded: $ trace-cmd split -i trace.dat -o trace_2.dat 284443 284444 $ trace-cmd report trace_2.dat cpus=8 <...>-525991 [004] 284443.173879: sched_wakeup: [...] <...>-525991 [004] 284443.173879: sched_wakeup: [...] <...>-525990 [007] 284443.173885: sched_wakeup: [...] <...>-525990 [007] 284443.173885: sched_wakeup: [...] (no sign of sched_switch events) Make use of the previous patches to split all the instances of a trace. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=218357 Signed-off-by: Pierre Gondois --- tracecmd/trace-split.c | 109 ++++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 50 deletions(-) diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c index 6ab138a2..37ce4176 100644 --- a/tracecmd/trace-split.c +++ b/tracecmd/trace-split.c @@ -426,6 +426,7 @@ static unsigned long long parse_file(struct tracecmd_input *handle, bool *end_reached) { unsigned long long current; + struct handle_list *handle_entry; struct tracecmd_output *ohandle; struct cpu_data *cpu_data; struct tep_record *record; @@ -437,63 +438,71 @@ static unsigned long long parse_file(struct tracecmd_input *handle, int fd; ohandle = tracecmd_copy(handle, output_file, TRACECMD_FILE_CMD_LINES, 0, NULL); + tracecmd_set_out_clock(ohandle, tracecmd_get_trace_clock(handle)); - cpus = tracecmd_cpus(handle); - cpu_data = malloc(sizeof(*cpu_data) * cpus); - if (!cpu_data) - die("Failed to allocate cpu_data for %d cpus", cpus); - - for (cpu = 0; cpu < cpus; cpu++) { - file = get_temp_file(output_file, NULL, cpu); - touch_file(file); - - fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); - cpu_data[cpu].cpu = cpu; - cpu_data[cpu].fd = fd; - cpu_data[cpu].file = file; - cpu_data[cpu].offset = 0; - if (start) - tracecmd_set_cpu_to_timestamp(handle, cpu, start); - } + list_for_each_entry(handle_entry, &handle_list, list) { + cpus = tracecmd_cpus(handle_entry->handle); + cpu_data = malloc(sizeof(*cpu_data) * cpus); + if (!cpu_data) + die("Failed to allocate cpu_data for %d cpus", cpus); - if (only_cpu >= 0) { - parse_cpu(handle, cpu_data, start, end, count, - 1, only_cpu, type, end_reached); - } else if (percpu) { + for (cpu = 0; cpu < cpus; cpu++) { + file = get_temp_file(output_file, handle_entry->name, cpu); + touch_file(file); + + fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); + cpu_data[cpu].cpu = cpu; + cpu_data[cpu].fd = fd; + cpu_data[cpu].file = file; + cpu_data[cpu].offset = 0; + if (start) + tracecmd_set_cpu_to_timestamp(handle_entry->handle, cpu, start); + } + + if (only_cpu >= 0) { + parse_cpu(handle_entry->handle, cpu_data, start, end, count, + 1, only_cpu, type, end_reached); + } else if (percpu) { + for (cpu = 0; cpu < cpus; cpu++) + parse_cpu(handle_entry->handle, cpu_data, start, + end, count, percpu, cpu, type, end_reached); + } else { + parse_cpu(handle_entry->handle, cpu_data, start, + end, count, percpu, -1, type, end_reached); + } + + cpu_list = malloc(sizeof(*cpu_list) * cpus); + if (!cpu_list) + die("Failed to allocate cpu_list for %d cpus", cpus); for (cpu = 0; cpu < cpus; cpu++) - parse_cpu(handle, cpu_data, start, - end, count, percpu, cpu, type, end_reached); - } else - parse_cpu(handle, cpu_data, start, - end, count, percpu, -1, type, end_reached); - - cpu_list = malloc(sizeof(*cpu_list) * cpus); - if (!cpu_list) - die("Failed to allocate cpu_list for %d cpus", cpus); - for (cpu = 0; cpu < cpus; cpu ++) - cpu_list[cpu] = cpu_data[cpu].file; + cpu_list[cpu] = cpu_data[cpu].file; - tracecmd_set_out_clock(ohandle, tracecmd_get_trace_clock(handle)); - if (tracecmd_append_cpu_data(ohandle, cpus, cpu_list) < 0) - die("Failed to append tracing data\n"); - - for (cpu = 0; cpu < cpus; cpu++) { - /* Set the tracecmd cursor to the next set of records */ - if (cpu_data[cpu].offset) { - record = tracecmd_read_at(handle, cpu_data[cpu].offset, NULL); - if (record && (!current || record->ts > current)) - current = record->ts + 1; - tracecmd_free_record(record); + if (!handle_entry->name) + ret = tracecmd_append_cpu_data(ohandle, cpus, cpu_list); + else + ret = tracecmd_append_buffer_cpu_data(ohandle, handle_entry->name, cpus, + cpu_list); + if (ret < 0) + die("Failed to append tracing data\n"); + + for (cpu = 0; cpu < cpus; cpu++) { + /* Set the tracecmd cursor to the next set of records */ + if (cpu_data[cpu].offset) { + record = tracecmd_read_at(handle, cpu_data[cpu].offset, NULL); + if (record && (!current || record->ts > current)) + current = record->ts + 1; + tracecmd_free_record(record); + } } - } - for (cpu = 0; cpu < cpus; cpu++) { - close(cpu_data[cpu].fd); - delete_temp_file(cpu_data[cpu].file); - put_temp_file(cpu_data[cpu].file); + for (cpu = 0; cpu < cpus; cpu++) { + close(cpu_data[cpu].fd); + delete_temp_file(cpu_data[cpu].file); + put_temp_file(cpu_data[cpu].file); + } + free(cpu_data); + free(cpu_list); } - free(cpu_data); - free(cpu_list); tracecmd_output_close(ohandle);