linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 3/5] trace-cmd library: Store the timestamp of the first event when reading a trace file
Date: Wed, 28 Apr 2021 15:28:37 +0300	[thread overview]
Message-ID: <20210428122839.805296-4-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210428122839.805296-1-tz.stoyanov@gmail.com>

When reading a trace file, detect and store the timestamp of the first
recorded event. A new API is introduced to get the first ts from an input
handler:
 tracecmd_get_first_ts()
The first ts can be used by the library users to align timestamps of the
events, when displaying them.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/trace-cmd/trace-cmd.h |  1 +
 lib/trace-cmd/trace-input.c   | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index 162cd318..022720b0 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -37,6 +37,7 @@ int tracecmd_get_guest_cpumap(struct tracecmd_input *handle,
 			      unsigned long long trace_id,
 			      const char **name,
 			      int *vcpu_count, const int **cpu_pid);
+unsigned long long tracecmd_get_first_ts(struct tracecmd_input *handle);
 int tracecmd_buffer_instances(struct tracecmd_input *handle);
 const char *tracecmd_buffer_instance_name(struct tracecmd_input *handle, int indx);
 struct tracecmd_input *tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx);
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index bacf9ccf..284f25e8 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -61,6 +61,7 @@ struct cpu_data {
 	unsigned long long	offset;
 	unsigned long long	size;
 	unsigned long long	timestamp;
+	unsigned long long	first_ts;
 	struct list_head	page_maps;
 	struct page_map		*page_map;
 	struct page		**pages;
@@ -2273,6 +2274,7 @@ static int init_cpu(struct tracecmd_input *handle, int cpu)
 
 	if (update_page_info(handle, cpu))
 		goto fail;
+	cpu_data->first_ts = cpu_data->timestamp;
 
 	return 0;
  fail:
@@ -4072,6 +4074,27 @@ unsigned long long tracecmd_get_traceid(struct tracecmd_input *handle)
 	return handle->trace_id;
 }
 
+/**
+ * tracecmd_get_first_ts - get the timestamp of the first recorded event
+ * @handle: input handle for the trace.dat file
+ *
+ * Returns the timestamp of the first recorded event
+ */
+unsigned long long tracecmd_get_first_ts(struct tracecmd_input *handle)
+{
+	unsigned long long ts = 0;
+	bool first = true;
+	int i;
+
+	for (i = 0; i < handle->cpus; i++) {
+		if (first || ts > handle->cpu_data[i].first_ts)
+			ts = handle->cpu_data[i].first_ts;
+		first = false;
+	}
+
+	return ts;
+}
+
 /**
  * tracecmd_get_guest_cpumap - get the mapping of guest VCPU to host process
  * @handle: input handle for the trace.dat file
-- 
2.30.2


  parent reply	other threads:[~2021-04-28 12:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 12:28 RFC [PATCH 0/5] tsc2nsec fixes Tzvetomir Stoyanov (VMware)
2021-04-28 12:28 ` [PATCH 1/5] trace-cmd: Remove ts offset from tsc2nsec conversion Tzvetomir Stoyanov (VMware)
2021-04-28 12:28 ` [PATCH 2/5] trace-cmd library: Remove useless check before applying ts offset Tzvetomir Stoyanov (VMware)
2021-04-28 12:28 ` Tzvetomir Stoyanov (VMware) [this message]
2021-04-28 12:28 ` [PATCH 4/5] trace-cmd library: New API for modifyning the timestamp offset Tzvetomir Stoyanov (VMware)
2021-04-28 12:28 ` [PATCH 5/5] trace-cmd report: New option --align-ts 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=20210428122839.805296-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).