All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Adrian Hunter <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: jolsa@redhat.com, mingo@kernel.org, linux-kernel@vger.kernel.org,
	tglx@linutronix.de, adrian.hunter@intel.com, hpa@zytor.com,
	acme@redhat.com, yao.jin@linux.intel.com
Subject: [tip:perf/core] perf time-utils: Add support for multiple explicit time intervals
Date: Mon, 17 Jun 2019 12:50:49 -0700	[thread overview]
Message-ID: <tip-a77a05e2337df1347f4de96bfa313db7008fe8bd@git.kernel.org> (raw)
In-Reply-To: <20190604130017.31207-20-adrian.hunter@intel.com>

Commit-ID:  a77a05e2337df1347f4de96bfa313db7008fe8bd
Gitweb:     https://git.kernel.org/tip/a77a05e2337df1347f4de96bfa313db7008fe8bd
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 4 Jun 2019 16:00:17 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 10 Jun 2019 16:20:13 -0300

perf time-utils: Add support for multiple explicit time intervals

Currently only a single explicit time range is accepted. Add support for
multiple ranges separated by spaces, which requires the string to be
quoted. Update the time utils test accordingly.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190604130017.31207-20-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-diff.txt   |  8 ++--
 tools/perf/Documentation/perf-report.txt |  3 +-
 tools/perf/Documentation/perf-script.txt |  3 +-
 tools/perf/tests/time-utils-test.c       | 17 ++++++++
 tools/perf/util/time-utils.c             | 74 +++++++++++++++++++++++++++++---
 5 files changed, 94 insertions(+), 11 deletions(-)

diff --git a/tools/perf/Documentation/perf-diff.txt b/tools/perf/Documentation/perf-diff.txt
index 5732f69580ab..facd91e4e945 100644
--- a/tools/perf/Documentation/perf-diff.txt
+++ b/tools/perf/Documentation/perf-diff.txt
@@ -145,9 +145,11 @@ OPTIONS
 	<start>,<stop>. Times have the format seconds.nanoseconds. If 'start'
 	is not given (i.e. time string is ',x.y') then analysis starts at
 	the beginning of the file. If stop time is not given (i.e. time
-	string is 'x.y,') then analysis goes to the end of the file. Time string is
-	'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different
-	perf.data files.
+	string is 'x.y,') then analysis goes to the end of the file.
+	Multiple ranges can be separated by spaces, which requires the argument
+	to be quoted e.g. --time "1234.567,1234.789 1235,"
+	Time string is'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps
+	for different perf.data files.
 
 	For example, we get the timestamp information from 'perf script'.
 
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 3de029f6881d..8c4372819e11 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -415,7 +415,8 @@ OPTIONS
 	have the format seconds.nanoseconds. If start is not given (i.e. time
 	string is ',x.y') then analysis starts at the beginning of the file. If
 	stop time is not given (i.e. time string is 'x.y,') then analysis goes
-	to end of file.
+	to end of file. Multiple ranges can be separated by spaces, which
+	requires the argument to be quoted e.g. --time "1234.567,1234.789 1235,"
 
 	Also support time percent with multiple time ranges. Time string is
 	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 878349cce968..d4e2e18a5881 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -364,7 +364,8 @@ include::itrace.txt[]
 	have the format seconds.nanoseconds. If start is not given (i.e. time
 	string is ',x.y') then analysis starts at the beginning of the file. If
 	stop time is not given (i.e. time string is 'x.y,') then analysis goes
-	to end of file.
+	to end of file. Multiple ranges can be separated by spaces, which
+	requires the argument to be quoted e.g. --time "1234.567,1234.789 1235,"
 
 	Also support time percent with multiple time ranges. Time string is
 	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
diff --git a/tools/perf/tests/time-utils-test.c b/tools/perf/tests/time-utils-test.c
index 7504046b111c..4f53006233a1 100644
--- a/tools/perf/tests/time-utils-test.c
+++ b/tools/perf/tests/time-utils-test.c
@@ -168,6 +168,23 @@ int test__time_utils(struct test *t __maybe_unused, int subtest __maybe_unused)
 		pass &= test__perf_time__parse_for_ranges(&d);
 	}
 
+	{
+		u64 b = 1234567123456789ULL;
+		u64 c = 7654321987654321ULL;
+		u64 e = 8000000000000000ULL;
+		struct test_data d = {
+			.str   = "1234567.123456789,1234567.123456790 "
+				 "7654321.987654321,7654321.987654444 "
+				 "8000000,8000000.000000005",
+			.ptime = { {b, b + 1}, {c, c + 123}, {e, e + 5}, },
+			.num = 3,
+			.skip = { b - 1, b + 2, c - 1, c + 124, e - 1, e + 6 },
+			.noskip = { b, b + 1, c, c + 123, e, e + 5 },
+		};
+
+		pass &= test__perf_time__parse_for_ranges(&d);
+	}
+
 	{
 		u64 b = 7654321ULL * NSEC_PER_SEC;
 		struct test_data d = {
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index d942840356e3..2b48816a2d2e 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -7,6 +7,7 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <math.h>
+#include <ctype.h>
 
 #include "perf.h"
 #include "debug.h"
@@ -116,6 +117,69 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr)
 	return rc;
 }
 
+static int perf_time__parse_strs(struct perf_time_interval *ptime,
+				 const char *ostr, int size)
+{
+	const char *cp;
+	char *str, *arg, *p;
+	int i, num = 0, rc = 0;
+
+	/* Count the commas */
+	for (cp = ostr; *cp; cp++)
+		num += !!(*cp == ',');
+
+	if (!num)
+		return -EINVAL;
+
+	BUG_ON(num > size);
+
+	str = strdup(ostr);
+	if (!str)
+		return -ENOMEM;
+
+	/* Split the string and parse each piece, except the last */
+	for (i = 0, p = str; i < num - 1; i++) {
+		arg = p;
+		/* Find next comma, there must be one */
+		p = strchr(p, ',') + 1;
+		/* Skip white space */
+		while (isspace(*p))
+			p++;
+		/* Skip the value, must not contain space or comma */
+		while (*p && !isspace(*p)) {
+			if (*p++ == ',') {
+				rc = -EINVAL;
+				goto out;
+			}
+		}
+		/* Split and parse */
+		if (*p)
+			*p++ = 0;
+		rc = perf_time__parse_str(ptime + i, arg);
+		if (rc < 0)
+			goto out;
+	}
+
+	/* Parse the last piece */
+	rc = perf_time__parse_str(ptime + i, p);
+	if (rc < 0)
+		goto out;
+
+	/* Check there is no overlap */
+	for (i = 0; i < num - 1; i++) {
+		if (ptime[i].end >= ptime[i + 1].start) {
+			rc = -EINVAL;
+			goto out;
+		}
+	}
+
+	rc = num;
+out:
+	free(str);
+
+	return rc;
+}
+
 static int parse_percent(double *pcnt, char *str)
 {
 	char *c, *endptr;
@@ -424,15 +488,13 @@ int perf_time__parse_for_ranges(const char *time_str,
 				time_str,
 				session->evlist->first_sample_time,
 				session->evlist->last_sample_time);
-
-		if (num < 0)
-			goto error_invalid;
 	} else {
-		if (perf_time__parse_str(ptime_range, time_str))
-			goto error_invalid;
-		num = 1;
+		num = perf_time__parse_strs(ptime_range, time_str, size);
 	}
 
+	if (num < 0)
+		goto error_invalid;
+
 	*range_size = size;
 	*range_num = num;
 	*ranges = ptime_range;

  reply	other threads:[~2019-06-17 19:52 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 12:59 [PATCH 00/19] perf intel-pt: Add support for efficient time interval filtering Adrian Hunter
2019-06-04 12:59 ` [PATCH 01/19] perf auxtrace: Add perf time interval to itrace_synth_ops Adrian Hunter
2019-06-17 19:38   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 02/19] perf script: Set perf time interval in itrace_synth_ops Adrian Hunter
2019-06-17 19:38   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 03/19] perf report: " Adrian Hunter
2019-06-17 19:39   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 04/19] perf intel-pt: Add lookahead callback Adrian Hunter
2019-06-17 19:40   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 05/19] perf intel-pt: Factor out intel_pt_8b_tsc() Adrian Hunter
2019-06-17 19:41   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 06/19] perf intel-pt: Factor out intel_pt_reposition() Adrian Hunter
2019-06-17 19:41   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 07/19] perf intel-pt: Add reposition parameter to intel_pt_get_data() Adrian Hunter
2019-06-17 19:42   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 08/19] perf intel-pt: Add intel_pt_fast_forward() Adrian Hunter
2019-06-17 19:43   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 09/19] perf intel-pt: Factor out intel_pt_get_buffer() Adrian Hunter
2019-06-17 19:43   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 10/19] perf intel-pt: Add support for lookahead Adrian Hunter
2019-06-17 19:44   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 11/19] perf intel-pt: Add support for efficient time interval filtering Adrian Hunter
2019-06-17 19:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 12/19] perf time-utils: Treat time ranges consistently Adrian Hunter
2019-06-17 19:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 13/19] perf time-utils: Factor out set_percent_time() Adrian Hunter
2019-06-17 19:46   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 14/19] perf time-utils: Prevent percentage time range overlap Adrian Hunter
2019-06-17 19:47   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 15/19] perf time-utils: Fix --time documentation Adrian Hunter
2019-06-17 19:47   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 16/19] perf time-utils: Simplify perf_time__parse_for_ranges() error paths slightly Adrian Hunter
2019-06-17 19:48   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 17/19] perf time-utils: Make perf_time__parse_for_ranges() more logical Adrian Hunter
2019-06-17 19:49   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 18/19] perf tests: Add a test for time-utils Adrian Hunter
2019-06-17 19:50   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 19/19] perf time-utils: Add support for multiple explicit time intervals Adrian Hunter
2019-06-17 19:50   ` tip-bot for Adrian Hunter [this message]
2019-06-07 19:49 ` [PATCH 00/19] perf intel-pt: Add support for efficient time interval filtering Arnaldo Carvalho de Melo

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=tip-a77a05e2337df1347f4de96bfa313db7008fe8bd@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=yao.jin@linux.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.