From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 3/4] trace-cmd library: Helper logic to update the trace buffer offset
Date: Fri, 8 Oct 2021 07:15:13 +0300 [thread overview]
Message-ID: <20211008041514.974537-4-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20211008041514.974537-1-tz.stoyanov@gmail.com>
The new helper functions can be used the update the trace buffer
metadata with the real offset within the trace file, where the buffer
data are stored.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-output.c | 49 ++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 1f144d28..17607b93 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -1395,6 +1395,20 @@ int tracecmd_write_buffer_info(struct tracecmd_output *handle)
return 0;
}
+static tsize_t get_buffer_file_offset(struct tracecmd_output *handle, const char *name)
+{
+ struct tracecmd_buffer *buf;
+
+ list_for_each_entry(buf, &handle->buffers, list) {
+ if (!strcmp(name, buf->name)) {
+ if (!buf->option)
+ break;
+ return buf->option->offset;
+ }
+ }
+ return 0;
+}
+
int tracecmd_write_cmdlines(struct tracecmd_output *handle)
{
int ret;
@@ -1487,6 +1501,41 @@ out:
return ret;
}
+static int update_buffer_cpu_offset(struct tracecmd_output *handle,
+ const char *name, tsize_t offset)
+{
+ tsize_t b_offset;
+ tsize_t current;
+
+ if (!name)
+ name = "";
+
+ b_offset = get_buffer_file_offset(handle, name);
+ if (!b_offset) {
+ tracecmd_warning("Cannot find description for buffer %s\n", name);
+ return -1;
+ }
+
+ current = lseek64(handle->fd, 0, SEEK_CUR);
+
+ /* Go to the option data, where will write the offest */
+ if (lseek64(handle->fd, b_offset, SEEK_SET) == (off64_t)-1) {
+ tracecmd_warning("could not seek to %lld\n", b_offset);
+ return -1;
+ }
+
+ if (do_write_check(handle, &offset, 8))
+ return -1;
+
+ /* Go back to end of file */
+ if (lseek64(handle->fd, current, SEEK_SET) == (off64_t)-1) {
+ tracecmd_warning("could not seek to %lld\n", offset);
+ return -1;
+ }
+ return 0;
+}
+
+
static char *get_clock(struct tracecmd_output *handle)
{
struct tracefs_instance *inst;
--
2.31.1
next prev parent reply other threads:[~2021-10-08 4:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-08 4:15 [PATCH 0/4] Refactor the logic for writing trace data in the file Tzvetomir Stoyanov (VMware)
2021-10-08 4:15 ` [PATCH 1/4] trace-cmd library: Add internal database for trace buffers Tzvetomir Stoyanov (VMware)
2021-10-08 4:15 ` [PATCH 2/4] trace-cmd: Use the new trace buffers API Tzvetomir Stoyanov (VMware)
2021-10-08 4:15 ` Tzvetomir Stoyanov (VMware) [this message]
2021-10-08 4:15 ` [PATCH 4/4] trace-cmd library: Refactor the logic for writing trace data in the file 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=20211008041514.974537-4-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).