All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jin Yao <yao.jin@linux.intel.com>
To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org,
	mingo@redhat.com, alexander.shishkin@linux.intel.com
Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com,
	kan.liang@intel.com, yao.jin@intel.com,
	Jin Yao <yao.jin@linux.intel.com>
Subject: [PATCH v7 2/6] perf record: Get the first sample time and last sample time
Date: Fri,  8 Dec 2017 21:13:42 +0800	[thread overview]
Message-ID: <1512738826-2628-3-git-send-email-yao.jin@linux.intel.com> (raw)
In-Reply-To: <1512738826-2628-1-git-send-email-yao.jin@linux.intel.com>

In the default 'perf record' configuration, all samples are processed,
to create the HEADER_BUILD_ID table. So it's very easy to get the
first/last samples and save the time to perf file header via the
function write_sample_time().

Later, at post processing time, perf report/script will fetch
the time from perf file header.

Change log:
-----------
v7: Just update the patch description according to Arnaldo's suggestion.

v6: Currently '--buildid-all' is not enabled at default. So the walking
    on all samples is the default operation. There is no big overhead
    to calculate the timestamp boundary in process_sample_event handler
    once we already go through all samples. So the timestamp boundary
    calculation is enabled by default when '--buildid-all' is not enabled.

    While if '--buildid-all' is enabled, we creates a new option
    "--timestamp-boundary" for user to decide if it enables the
    timestamp boundary calculation.

v5: There is an issue that the sample walking can only work when
    '--buildid-all' is not enabled. So we need to let the walking
    be able to work even if '--buildid-all' is enabled and let the
    processing skips the dso hit marking for this case.

    At first, I want to provide a new option "--record-time-boundaries".
    While after consideration, I think a new option is not very
    necessary.

v3: Remove the definitions of first_sample_time and last_sample_time
    from struct record and directly save them in perf_evlist.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/Documentation/perf-record.txt |  3 +++
 tools/perf/builtin-record.c              | 18 +++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 5a626ef..3eea6de 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -430,6 +430,9 @@ Configure all used events to run in user space.
 --timestamp-filename
 Append timestamp to output file name.
 
+--timestamp-boundary::
+Record timestamp boundary (time of first/last samples).
+
 --switch-output[=mode]::
 Generate multiple perf.data files, timestamp prefixed, switching to a new one
 based on 'mode' value:
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 98da8cb..6db7b5a 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -78,6 +78,7 @@ struct record {
 	bool			no_buildid_cache_set;
 	bool			buildid_all;
 	bool			timestamp_filename;
+	bool			timestamp_boundary;
 	struct switch_output	switch_output;
 	unsigned long long	samples;
 };
@@ -409,8 +410,15 @@ static int process_sample_event(struct perf_tool *tool,
 {
 	struct record *rec = container_of(tool, struct record, tool);
 
-	rec->samples++;
+	if (rec->evlist->first_sample_time == 0)
+		rec->evlist->first_sample_time = sample->time;
+
+	rec->evlist->last_sample_time = sample->time;
 
+	if (rec->buildid_all)
+		return 0;
+
+	rec->samples++;
 	return build_id__mark_dso_hit(tool, event, sample, evsel, machine);
 }
 
@@ -435,9 +443,11 @@ static int process_buildids(struct record *rec)
 
 	/*
 	 * If --buildid-all is given, it marks all DSO regardless of hits,
-	 * so no need to process samples.
+	 * so no need to process samples. But if timestamp_boundary is enabled,
+	 * it still needs to walk on all samples to get the timestamps of
+	 * first/last samples.
 	 */
-	if (rec->buildid_all)
+	if (rec->buildid_all && !rec->timestamp_boundary)
 		rec->tool.sample = NULL;
 
 	return perf_session__process_events(session);
@@ -1621,6 +1631,8 @@ static struct option __record_options[] = {
 		    "Record build-id of all DSOs regardless of hits"),
 	OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
 		    "append timestamp to output filename"),
+	OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary,
+		    "Record timestamp boundary (time of first/last samples)"),
 	OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str,
 			  &record.switch_output.set, "signal,size,time",
 			  "Switch output when receive SIGUSR2 or cross size,time threshold",
-- 
2.7.4

  parent reply	other threads:[~2017-12-08  5:28 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 13:13 [PATCH v7 0/6] perf report/script: Support percent and multiple range in --time option Jin Yao
2017-12-08 13:13 ` [PATCH v7 1/6] perf header: Record first sample time and last sample time in perf file header Jin Yao
2018-01-11  6:21   ` [tip:perf/core] perf header: Add infrastructure to record first and last sample time tip-bot for Jin Yao
2017-12-08 13:13 ` Jin Yao [this message]
2018-01-04 19:09   ` [PATCH v7 2/6] perf record: Get the first sample time " Arnaldo Carvalho de Melo
2018-01-05  1:15     ` Jin, Yao
2018-01-05 12:53       ` Arnaldo Carvalho de Melo
2018-01-05 22:55         ` Jin, Yao
2018-01-11  6:22   ` [tip:perf/core] perf record: Record the first and last sample time in the header tip-bot for Jin Yao
2017-12-08 13:13 ` [PATCH v7 3/6] perf util: Create function to parse time percent Jin Yao
2018-01-08 14:31   ` Arnaldo Carvalho de Melo
2018-01-08 14:38     ` Arnaldo Carvalho de Melo
2018-01-09  1:18       ` Jin, Yao
2018-01-11  6:22   ` [tip:perf/core] perf tools: " tip-bot for Jin Yao
2017-12-08 13:13 ` [PATCH v7 4/6] perf util: Create function to perform multiple time range checking Jin Yao
2018-01-11  6:22   ` [tip:perf/core] perf tools: " tip-bot for Jin Yao
2017-12-08 13:13 ` [PATCH v7 5/6] perf report: support time percent and multiple time ranges Jin Yao
2018-01-08 14:45   ` Arnaldo Carvalho de Melo
2018-01-08 14:48     ` Arnaldo Carvalho de Melo
2018-01-08 14:53   ` Arnaldo Carvalho de Melo
2018-01-08 15:02     ` Arnaldo Carvalho de Melo
2018-01-08 15:04       ` Arnaldo Carvalho de Melo
2018-01-09  2:02         ` Jin, Yao
2018-01-11  6:23   ` [tip:perf/core] perf report: Support " tip-bot for Jin Yao
2017-12-08 13:13 ` [PATCH v7 6/6] perf script: support " Jin Yao
2018-01-11  6:23   ` [tip:perf/core] perf script: Support " tip-bot for Jin Yao
2017-12-13 14:28 ` [PATCH v7 0/6] perf report/script: Support percent and multiple range in --time option Arnaldo Carvalho de Melo
2017-12-14  0:48   ` Jin, Yao
2017-12-14 14:08 ` Jiri Olsa

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=1512738826-2628-3-git-send-email-yao.jin@linux.intel.com \
    --to=yao.jin@linux.intel.com \
    --cc=Linux-kernel@vger.kernel.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=yao.jin@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.