From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 15/25] trace-cmd library: Initialize internal sections database on file read
Date: Mon, 13 Sep 2021 15:29:37 +0300 [thread overview]
Message-ID: <20210913122947.3673239-16-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210913122947.3673239-1-tz.stoyanov@gmail.com>
Add sections in internal database on file reading and parsing.
In trace file version 7, sections are initialized when parsing
corresponding trace options. In version 6 files, sections are retrieved
on file reading, as there they are in a fixed position in the file.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
.../include/private/trace-cmd-private.h | 1 +
lib/trace-cmd/trace-input.c | 65 +++++++++++++++----
2 files changed, 52 insertions(+), 14 deletions(-)
diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index d8a981af..a08890df 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -153,6 +153,7 @@ enum {
TRACECMD_FL_BUFFER_INSTANCE = (1 << 1),
TRACECMD_FL_IN_USECS = (1 << 2),
TRACECMD_FL_RAW_TS = (1 << 3),
+ TRACECMD_FL_SECTIONED = (1 << 4),
};
struct tracecmd_ftrace {
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 978758c0..bc3bc5d2 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -164,8 +164,7 @@ struct tracecmd_input {
struct file_section *sections;
size_t header_files_start;
size_t ftrace_files_start;
- size_t event_files_start;
- size_t options_start;
+ unsigned long long options_start;
size_t total_file_size;
/* For custom profilers. */
@@ -175,6 +174,7 @@ struct tracecmd_input {
__thread struct tracecmd_input *tracecmd_curr_thread_handle;
#define CHECK_READ_STATE(H, S) ((H)->file_version < FILE_VERSION_SECTIONS && (H)->file_state >= (S))
+#define HAS_SECTIONS(H) ((H)->flags & TRACECMD_FL_SECTIONED)
static int read_options_type(struct tracecmd_input *handle);
@@ -447,6 +447,10 @@ static int read_header_files(struct tracecmd_input *handle)
if (CHECK_READ_STATE(handle, TRACECMD_FILE_HEADERS))
return 0;
+ if (!HAS_SECTIONS(handle))
+ section_add_or_update(handle, TRACECMD_OPTION_HEADER_INFO, 0, 0,
+ lseek64(handle->fd, 0, SEEK_CUR));
+
if (do_read_check(handle, buf, 12))
return -1;
@@ -490,9 +494,6 @@ static int read_header_files(struct tracecmd_input *handle)
free(header);
- handle->ftrace_files_start =
- lseek64(handle->fd, 0, SEEK_CUR);
-
handle->file_state = TRACECMD_FILE_HEADERS;
return 0;
@@ -653,6 +654,10 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex)
if (CHECK_READ_STATE(handle, TRACECMD_FILE_FTRACE_EVENTS))
return 0;
+ if (!HAS_SECTIONS(handle))
+ section_add_or_update(handle, TRACECMD_OPTION_FTRACE_EVENTS, 0, 0,
+ lseek64(handle->fd, 0, SEEK_CUR));
+
if (regex) {
sreg = &spreg;
ereg = &epreg;
@@ -693,8 +698,6 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex)
goto out;
}
- handle->event_files_start =
- lseek64(handle->fd, 0, SEEK_CUR);
handle->file_state = TRACECMD_FILE_FTRACE_EVENTS;
ret = 0;
out:
@@ -726,6 +729,10 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex)
if (CHECK_READ_STATE(handle, TRACECMD_FILE_ALL_EVENTS))
return 0;
+ if (!HAS_SECTIONS(handle))
+ section_add_or_update(handle, TRACECMD_OPTION_EVENT_FORMATS, 0, 0,
+ lseek64(handle->fd, 0, SEEK_CUR));
+
if (regex) {
sreg = &spreg;
ereg = &epreg;
@@ -811,6 +818,10 @@ static int read_proc_kallsyms(struct tracecmd_input *handle)
if (CHECK_READ_STATE(handle, TRACECMD_FILE_KALLSYMS))
return 0;
+ if (!HAS_SECTIONS(handle))
+ section_add_or_update(handle, TRACECMD_OPTION_KALLSYMS, 0, 0,
+ lseek64(handle->fd, 0, SEEK_CUR));
+
ret = read4(handle, &size);
if (ret < 0)
goto out;
@@ -847,6 +858,10 @@ static int read_ftrace_printk(struct tracecmd_input *handle)
if (CHECK_READ_STATE(handle, TRACECMD_FILE_PRINTK))
return 0;
+ if (!HAS_SECTIONS(handle))
+ section_add_or_update(handle, TRACECMD_OPTION_PRINTK, 0, 0,
+ lseek64(handle->fd, 0, SEEK_CUR));
+
ret = read4(handle, &size);
if (ret < 0)
goto out;
@@ -2885,6 +2900,18 @@ static int handle_options(struct tracecmd_input *handle)
handle->tsc_calc.offset = tep_read_number(handle->pevent,
buf + 8, 8);
break;
+ case TRACECMD_OPTION_HEADER_INFO:
+ case TRACECMD_OPTION_FTRACE_EVENTS:
+ case TRACECMD_OPTION_EVENT_FORMATS:
+ case TRACECMD_OPTION_KALLSYMS:
+ case TRACECMD_OPTION_PRINTK:
+ case TRACECMD_OPTION_CMDLINES:
+ if (size < 8)
+ break;
+ section_add_or_update(handle, option, -1,
+ tep_read_number(handle->pevent, buf, 8), 0);
+ break;
+
default:
tracecmd_warning("unknown option %d", option);
break;
@@ -3070,6 +3097,10 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle)
if (CHECK_READ_STATE(handle, TRACECMD_FILE_CMD_LINES))
return 0;
+ if (!HAS_SECTIONS(handle))
+ section_add_or_update(handle, TRACECMD_OPTION_CMDLINES, 0, 0,
+ lseek64(handle->fd, 0, SEEK_CUR));
+
ret = read_data_and_size(handle, &cmdlines, &size);
if (ret < 0)
goto out;
@@ -3364,6 +3395,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)
struct tracecmd_input *handle;
char test[] = TRACECMD_MAGIC;
unsigned int page_size;
+ size_t offset;
char *version;
char buf[BUFSIZ];
unsigned long ver;
@@ -3403,6 +3435,9 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)
handle->file_version = ver;
free(version);
+ if (handle->file_version >= FILE_VERSION_SECTIONS)
+ handle->flags |= TRACECMD_FL_SECTIONED;
+
if (do_read_check(handle, buf, 1))
goto failed_read;
@@ -3427,14 +3462,16 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)
read4(handle, &page_size);
handle->page_size = page_size;
- handle->header_files_start =
- lseek64(handle->fd, 0, SEEK_CUR);
-
- handle->total_file_size =
- lseek64(handle->fd, 0, SEEK_END);
+ offset = lseek64(handle->fd, 0, SEEK_CUR);
+ handle->total_file_size = lseek64(handle->fd, 0, SEEK_END);
+ lseek64(handle->fd, offset, SEEK_SET);
- handle->header_files_start =
- lseek64(handle->fd, handle->header_files_start, SEEK_SET);
+ if (HAS_SECTIONS(handle)) {
+ if (read8(handle, &(handle->options_start))) {
+ tracecmd_warning("Filed to read the offset of the first option section");
+ goto failed_read;
+ }
+ }
handle->file_state = TRACECMD_FILE_INIT;
--
2.31.1
next prev parent reply other threads:[~2021-09-13 12:30 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 12:29 [PATCH v2 00/25] Trace file version 7 - sections Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 01/25] trace-cmd library: Define trace file version 7 Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 02/25] trace-cmd library: Add cache functionality to network message handler Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 03/25] trace-cmd library: New APIs to get and set version of output handler Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 04/25] trace-cmd library: Add internal helper function for writing headers before file sections Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 05/25] trace-cmd library: Write header " Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 06/25] trace-cmd library: Add multiple options sections in trace file version 7 Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 07/25] trace-cmd library: Do not write CPU count section in trace files " Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 08/25] trace-cmd library: Move CPU flyrecord trace metadata into the buffer option, for trace file " Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 09/25] trace-cmd record: Append trace options after the trace data are written Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 10/25] trace-cmd library: Add section header before flyrecord trace data Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 11/25] trace-cmd library: Fit CPU latency trace data in the new trace file version 7 format Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 12/25] trace-cmd library: Do not write CPUs with empty trace data Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 13/25] trace-cmd library: Add macro to check file state on reading Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 14/25] trace-cmd library: Introduce sections in trace file reading logic Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` Tzvetomir Stoyanov (VMware) [this message]
2021-09-13 12:29 ` [PATCH v2 16/25] trace-cmd library: Use sections database when reading parts of the trace file Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 17/25] trace-cmd library: Read headers from trace file version 7 Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 18/25] trace-cmd library: Read extended BUFFER option Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 19/25] trace-cmd library: Handle the extended DONE option Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 20/25] trace-cmd library: Initialize CPU data for reading from version 7 trace files Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 21/25] trace-cmd library: Handle latency trace in version 7 files Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 22/25] trace-cmd library: Handle buffer trace data init for " Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 23/25] trace-cmd report: Use the new latency API to read data Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 24/25] trace-cmd: Call additional APIs when creating trace file Tzvetomir Stoyanov (VMware)
2021-09-13 12:29 ` [PATCH v2 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=20210913122947.3673239-16-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).