From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v3 20/25] trace-cmd library: Initialize CPU data for reading from version 7 trace files
Date: Tue, 14 Sep 2021 16:14:33 +0300 [thread overview]
Message-ID: <20210914131438.3965484-21-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com>
In version 7 trace files, CPU trace data is written in slightly
different way than in version 6 files. Added new CPU data initialization
flow, to handle version 7 files:
- the top trace instance is saved in the same way as the other trace
instances.
- per CPU trace metadata is stored in the buffer option.
- trace data section has section header.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-input.c | 178 +++++++++++++++++++++++++-----------
1 file changed, 123 insertions(+), 55 deletions(-)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index d9ec9c73..87c33423 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -3203,34 +3203,18 @@ static int read_options_type(struct tracecmd_input *handle)
return 0;
}
-static int read_cpu_data(struct tracecmd_input *handle)
+static int init_cpu_data(struct tracecmd_input *handle)
{
- struct tep_handle *pevent = handle->pevent;
enum kbuffer_long_size long_size;
enum kbuffer_endian endian;
- unsigned long long size;
unsigned long long max_size = 0;
unsigned long long pages;
- int cpus;
int cpu;
- /*
- * Check if this is a latency report or not.
- */
- if (handle->file_state == TRACECMD_FILE_CPU_LATENCY)
- return 1;
-
/* We expect this to be flyrecord */
if (handle->file_state != TRACECMD_FILE_CPU_FLYRECORD)
return -1;
- cpus = handle->cpus;
-
- handle->cpu_data = malloc(sizeof(*handle->cpu_data) * handle->cpus);
- if (!handle->cpu_data)
- return -1;
- memset(handle->cpu_data, 0, sizeof(*handle->cpu_data) * handle->cpus);
-
if (force_read)
handle->read_page = true;
@@ -3245,32 +3229,14 @@ static int read_cpu_data(struct tracecmd_input *handle)
endian = KBUFFER_ENDIAN_LITTLE;
for (cpu = 0; cpu < handle->cpus; cpu++) {
- unsigned long long offset;
-
- handle->cpu_data[cpu].cpu = cpu;
-
handle->cpu_data[cpu].kbuf = kbuffer_alloc(long_size, endian);
if (!handle->cpu_data[cpu].kbuf)
goto out_free;
- if (tep_is_old_format(pevent))
+ if (tep_is_old_format(handle->pevent))
kbuffer_set_old_format(handle->cpu_data[cpu].kbuf);
- read8(handle, &offset);
- read8(handle, &size);
-
- handle->cpu_data[cpu].file_offset = offset;
- handle->cpu_data[cpu].file_size = size;
- if (size > max_size)
- max_size = size;
-
- if (size && (offset + size > handle->total_file_size)) {
- /* this happens if the file got truncated */
- printf("File possibly truncated. "
- "Need at least %llu, but file size is %zu.\n",
- offset + size, handle->total_file_size);
- errno = EINVAL;
- goto out_free;
- }
+ if (handle->cpu_data[cpu].file_size > max_size)
+ max_size = handle->cpu_data[cpu].file_size;
}
/* Calculate about a meg of pages for buffering */
@@ -3288,6 +3254,101 @@ static int read_cpu_data(struct tracecmd_input *handle)
goto out_free;
}
+ return 0;
+
+ out_free:
+ for ( ; cpu >= 0; cpu--) {
+ free_page(handle, cpu);
+ kbuffer_free(handle->cpu_data[cpu].kbuf);
+ handle->cpu_data[cpu].kbuf = NULL;
+ }
+ return -1;
+}
+
+static int init_buffer_cpu_data(struct tracecmd_input *handle, struct input_buffer_instance *buffer)
+{
+ unsigned long long offset;
+ unsigned long long size;
+ unsigned short id, flags;
+ int cpu;
+
+ if (handle->cpu_data)
+ return -1;
+
+ if (lseek64(handle->fd, buffer->offset, SEEK_SET) == (off_t)-1)
+ return -1;
+ if (read_section_header(handle, &id, &flags, NULL, NULL))
+ return -1;
+
+ handle->file_state = TRACECMD_FILE_CPU_FLYRECORD;
+ handle->cpus = buffer->cpus;
+ if (handle->max_cpu < handle->cpus)
+ handle->max_cpu = handle->cpus;
+
+ handle->cpu_data = calloc(handle->cpus, sizeof(*handle->cpu_data));
+ if (!handle->cpu_data)
+ return -1;
+
+ for (cpu = 0; cpu < handle->cpus; cpu++) {
+ handle->cpu_data[cpu].cpu = buffer->cpu_data[cpu].cpu;
+ offset = buffer->cpu_data[cpu].offset;
+ size = buffer->cpu_data[cpu].size;
+ handle->cpu_data[cpu].file_offset = offset;
+ handle->cpu_data[cpu].file_size = size;
+ if (size && (offset + size > handle->total_file_size)) {
+ /* this happens if the file got truncated */
+ printf("File possibly truncated. "
+ "Need at least %llu, but file size is %zu.\n",
+ offset + size, handle->total_file_size);
+ errno = EINVAL;
+ return -1;
+ }
+ }
+
+ return init_cpu_data(handle);
+}
+
+static int read_cpu_data(struct tracecmd_input *handle)
+{
+ unsigned long long size;
+ int cpus;
+ int cpu;
+
+ /*
+ * Check if this is a latency report or not.
+ */
+ if (handle->file_state == TRACECMD_FILE_CPU_LATENCY)
+ return 1;
+
+ /* We expect this to be flyrecord */
+ if (handle->file_state != TRACECMD_FILE_CPU_FLYRECORD)
+ return -1;
+
+ cpus = handle->cpus;
+
+ handle->cpu_data = malloc(sizeof(*handle->cpu_data) * handle->cpus);
+ if (!handle->cpu_data)
+ return -1;
+ memset(handle->cpu_data, 0, sizeof(*handle->cpu_data) * handle->cpus);
+
+ for (cpu = 0; cpu < handle->cpus; cpu++) {
+ unsigned long long offset;
+
+ handle->cpu_data[cpu].cpu = cpu;
+ read8(handle, &offset);
+ read8(handle, &size);
+ handle->cpu_data[cpu].file_offset = offset;
+ handle->cpu_data[cpu].file_size = size;
+ if (size && (offset + size > handle->total_file_size)) {
+ /* this happens if the file got truncated */
+ printf("File possibly truncated. "
+ "Need at least %llu, but file size is %zu.\n",
+ offset + size, handle->total_file_size);
+ errno = EINVAL;
+ return -1;
+ }
+ }
+
/*
* It is possible that an option changed the number of CPUs.
* If that happened, then there's "empty" cpu data saved for
@@ -3307,15 +3368,7 @@ static int read_cpu_data(struct tracecmd_input *handle)
}
}
- return 0;
-
- out_free:
- for ( ; cpu >= 0; cpu--) {
- free_page(handle, cpu);
- kbuffer_free(handle->cpu_data[cpu].kbuf);
- handle->cpu_data[cpu].kbuf = NULL;
- }
- return -1;
+ return init_cpu_data(handle);
}
static int read_data_and_size(struct tracecmd_input *handle,
@@ -3418,14 +3471,7 @@ static int read_and_parse_trace_clock(struct tracecmd_input *handle,
return 0;
}
-/**
- * tracecmd_init_data - prepare reading the data from trace.dat
- * @handle: input handle for the trace.dat file
- *
- * This prepares reading the data from trace.dat. This is called
- * after tracecmd_read_headers() and before tracecmd_read_data().
- */
-int tracecmd_init_data(struct tracecmd_input *handle)
+static int init_data_v6(struct tracecmd_input *handle)
{
struct tep_handle *pevent = handle->pevent;
int ret;
@@ -3447,7 +3493,29 @@ int tracecmd_init_data(struct tracecmd_input *handle)
tracecmd_parse_trace_clock(handle, clock, 8);
}
}
+ return ret;
+}
+
+static int init_data_v7(struct tracecmd_input *handle)
+{
+ return init_buffer_cpu_data(handle, &handle->top_buffer);
+}
+/**
+ * tracecmd_init_data - prepare reading the data from trace.dat
+ * @handle: input handle for the trace.dat file
+ *
+ * This prepares reading the data from trace.dat. This is called
+ * after tracecmd_read_headers() and before tracecmd_read_data().
+ */
+int tracecmd_init_data(struct tracecmd_input *handle)
+{
+ int ret;
+
+ if (!HAS_SECTIONS(handle))
+ ret = init_data_v6(handle);
+ else
+ ret = init_data_v7(handle);
tracecmd_blk_hack(handle);
return ret;
--
2.31.1
next prev parent reply other threads:[~2021-09-14 13:15 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-14 13:14 [PATCH v3 00/25] Trace file version 7 - sections Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 01/25] trace-cmd library: Define trace file version 7 Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 02/25] trace-cmd library: Add cache functionality to network message handler Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 03/25] trace-cmd library: New APIs to get and set version of output handler Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 04/25] trace-cmd library: Add internal helper function for writing headers before file sections Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 05/25] trace-cmd library: Write header " Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 06/25] trace-cmd library: Add multiple options sections in trace file version 7 Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 07/25] trace-cmd library: Do not write CPU count section in trace files " Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 08/25] trace-cmd library: Move CPU flyrecord trace metadata into the buffer option, for trace file " Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 09/25] trace-cmd record: Append trace options after the trace data are written Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 10/25] trace-cmd library: Add section header before flyrecord trace data Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 11/25] trace-cmd library: Fit CPU latency trace data in the new trace file version 7 format Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 12/25] trace-cmd library: Do not write CPUs with empty trace data Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 13/25] trace-cmd library: Add macro to check file state on reading Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 14/25] trace-cmd library: Introduce sections in trace file reading logic Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 15/25] trace-cmd library: Initialize internal sections database on file read Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 16/25] trace-cmd library: Use sections database when reading parts of the trace file Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 17/25] trace-cmd library: Read headers from trace file version 7 Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 18/25] trace-cmd library: Read extended BUFFER option Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 19/25] trace-cmd library: Handle the extended DONE option Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` Tzvetomir Stoyanov (VMware) [this message]
2021-09-14 13:14 ` [PATCH v3 21/25] trace-cmd library: Handle latency trace in version 7 files Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 22/25] trace-cmd library: Handle buffer trace data init for " Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 23/25] trace-cmd report: Use the new latency API to read data Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 24/25] trace-cmd: Call additional APIs when creating trace file Tzvetomir Stoyanov (VMware)
2021-09-14 13:14 ` [PATCH v3 25/25] trace-cmd report: Add new parameter for trace file version Tzvetomir Stoyanov (VMware)
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=20210914131438.3965484-21-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@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;
as well as URLs for NNTP newsgroup(s).