linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/8] perf: Follow-up patches to improve time slice
@ 2018-01-10 15:00 Jin Yao
  2018-01-10 15:00 ` [PATCH v1 1/8] perf report: Improve error msg when no first/last sample time found Jin Yao
                   ` (8 more replies)
  0 siblings, 9 replies; 22+ messages in thread
From: Jin Yao @ 2018-01-10 15:00 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

It's follow-up patches to improve the perf time slice feature
(perf report/script --time xxx)

1. Improve the error message
   perf report: Improve error msg when no first/last sample time found
   perf script: Improve error msg when no first/last sample time found

2. Fix an issue that illegal percent was accepted previously (e.g. 1abc%)
   perf util: Improve error checking for time percent input

3. Omit the slice index if possible. For example,
   perf report --stdio --time 10%/1 is equivalent to
   perf report --stdio --time 10%

   perf util: Support no index time percent slice 

4. Add indication of time slices in perf report header.
   perf report: Add an indication of what time slices are used

5. Remove the time slices number limitation in perf report/script
   perf util: Allocate time slices buffer according to number of comma
   perf report: Remove the time slices number limitation
   perf script: Remove the time slices number limitation

Jin Yao (8):
  perf report: Improve error msg when no first/last sample time found
  perf script: Improve error msg when no first/last sample time found
  perf util: Improve error checking for time percent input
  perf util: Support no index time percent slice
  perf report: Add an indication of what time slices are used
  perf util: Allocate time slices buffer according to number of comma
  perf report: Remove the time slices number limitation
  perf script: Remove the time slices number limitation

 tools/perf/Documentation/perf-report.txt |  2 +-
 tools/perf/Documentation/perf-script.txt | 10 ++---
 tools/perf/builtin-report.c              | 30 +++++++++----
 tools/perf/builtin-script.c              | 21 +++++++---
 tools/perf/util/time-utils.c             | 72 +++++++++++++++++++++++++++++++-
 tools/perf/util/time-utils.h             |  2 +
 6 files changed, 117 insertions(+), 20 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v1 1/8] perf report: Improve error msg when no first/last sample time found
  2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
@ 2018-01-10 15:00 ` Jin Yao
  2018-01-17 16:34   ` [tip:perf/core] " tip-bot for Jin Yao
  2018-01-10 15:00 ` [PATCH v1 2/8] perf script: " Jin Yao
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 22+ messages in thread
From: Jin Yao @ 2018-01-10 15:00 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

The following message will be returned to user when executing
'perf report --time' if perf data file doesn't contain the
first/last sample time.

"HINT: no first/last sample time found in perf data.
 Please use latest perf binary to execute 'perf record'
 (if '--buildid-all' is enabled, needs to set '--timestamp-boundary')."

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/builtin-report.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index dd4df9a..a6c5cf2 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1299,7 +1299,9 @@ int cmd_report(int argc, const char **argv)
 	if (perf_time__parse_str(report.ptime_range, report.time_str) != 0) {
 		if (session->evlist->first_sample_time == 0 &&
 		    session->evlist->last_sample_time == 0) {
-			pr_err("No first/last sample time in perf data\n");
+			pr_err("HINT: no first/last sample time found in perf data.\n"
+			       "Please use latest perf binary to execute 'perf record'\n"
+			       "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n");
 			return -EINVAL;
 		}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v1 2/8] perf script: Improve error msg when no first/last sample time found
  2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
  2018-01-10 15:00 ` [PATCH v1 1/8] perf report: Improve error msg when no first/last sample time found Jin Yao
@ 2018-01-10 15:00 ` Jin Yao
  2018-01-17 16:35   ` [tip:perf/core] " tip-bot for Jin Yao
  2018-01-10 15:00 ` [PATCH v1 3/8] perf util: Improve error checking for time percent input Jin Yao
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 22+ messages in thread
From: Jin Yao @ 2018-01-10 15:00 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

The following message will be returned to user when executing
'perf script --time' if perf data file doesn't contain the
first/last sample time.

"HINT: no first/last sample time found in perf data.
 Please use latest perf binary to execute 'perf record'
 (if '--buildid-all' is enabled, needs to set '--timestamp-boundary')."

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/builtin-script.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c1cce47..4f691af 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3448,7 +3448,9 @@ int cmd_script(int argc, const char **argv)
 	if (perf_time__parse_str(script.ptime_range, script.time_str) != 0) {
 		if (session->evlist->first_sample_time == 0 &&
 		    session->evlist->last_sample_time == 0) {
-			pr_err("No first/last sample time in perf data\n");
+			pr_err("HINT: no first/last sample time found in perf data.\n"
+			       "Please use latest perf binary to execute 'perf record'\n"
+			       "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n");
 			err = -EINVAL;
 			goto out_delete;
 		}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v1 3/8] perf util: Improve error checking for time percent input
  2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
  2018-01-10 15:00 ` [PATCH v1 1/8] perf report: Improve error msg when no first/last sample time found Jin Yao
  2018-01-10 15:00 ` [PATCH v1 2/8] perf script: " Jin Yao
@ 2018-01-10 15:00 ` Jin Yao
  2018-01-17 16:35   ` [tip:perf/core] " tip-bot for Jin Yao
  2018-01-10 15:00 ` [PATCH v1 4/8] perf util: Support no index time percent slice Jin Yao
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 22+ messages in thread
From: Jin Yao @ 2018-01-10 15:00 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

The command line like 'perf report --stdio --time 1abc%/1' could be
accepted by perf. It looks not very good.

This patch uses strtod() to replace original atof() and check the
entire string. Now for the same command line, it would return error
message "Invalid time string".

root@skl:/tmp# perf report --stdio --time 1abc%/1
Invalid time string

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/util/time-utils.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 3f7f18f..88510ab 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -116,7 +116,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr)
 
 static int parse_percent(double *pcnt, char *str)
 {
-	char *c;
+	char *c, *endptr;
+	double d;
 
 	c = strchr(str, '%');
 	if (c)
@@ -124,8 +125,11 @@ static int parse_percent(double *pcnt, char *str)
 	else
 		return -1;
 
-	*pcnt = atof(str) / 100.0;
+	d = strtod(str, &endptr);
+	if (endptr != str + strlen(str))
+		return -1;
 
+	*pcnt = d / 100.0;
 	return 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v1 4/8] perf util: Support no index time percent slice
  2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
                   ` (2 preceding siblings ...)
  2018-01-10 15:00 ` [PATCH v1 3/8] perf util: Improve error checking for time percent input Jin Yao
@ 2018-01-10 15:00 ` Jin Yao
  2018-01-17 16:36   ` [tip:perf/core] " tip-bot for Jin Yao
  2018-01-10 15:00 ` [PATCH v1 5/8] perf report: Add an indication of what time slices are used Jin Yao
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 22+ messages in thread
From: Jin Yao @ 2018-01-10 15:00 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

Previously, the time percent slice needs an index to specify
which one the user wants.

While it may be easy for using if the index can be omitted.
So with this patch, for example,

perf report --stdio --time 10%/1 should be equivalent to
perf report --stdio --time 10%

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/util/time-utils.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 88510ab..5769f97 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -261,6 +261,37 @@ static int percent_comma_split(struct perf_time_interval *ptime_buf, int num,
 	return i;
 }
 
+static int one_percent_convert(struct perf_time_interval *ptime_buf,
+			       const char *ostr, u64 start, u64 end, char *c)
+{
+	char *str;
+	int len = strlen(ostr), ret;
+
+	/*
+	 * c points to '%'.
+	 * '%' should be the last character
+	 */
+	if (ostr + len - 1 != c)
+		return -1;
+
+	/*
+	 * Construct a string like "xx%/1"
+	 */
+	str = malloc(len + 3);
+	if (str == NULL)
+		return -ENOMEM;
+
+	memcpy(str, ostr, len);
+	strcpy(str + len, "/1");
+
+	ret = percent_slash_split(str, ptime_buf, start, end);
+	if (ret == 0)
+		ret = 1;
+
+	free(str);
+	return ret;
+}
+
 int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 				 const char *ostr, u64 start, u64 end)
 {
@@ -270,6 +301,7 @@ int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 	 * ostr example:
 	 * 10%/2,10%/3: select the second 10% slice and the third 10% slice
 	 * 0%-10%,30%-40%: multiple time range
+	 * 50%: just one percent
 	 */
 
 	memset(ptime_buf, 0, sizeof(*ptime_buf) * num);
@@ -286,6 +318,10 @@ int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 					   end, percent_dash_split);
 	}
 
+	c = strchr(ostr, '%');
+	if (c)
+		return one_percent_convert(ptime_buf, ostr, start, end, c);
+
 	return -1;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v1 5/8] perf report: Add an indication of what time slices are used
  2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
                   ` (3 preceding siblings ...)
  2018-01-10 15:00 ` [PATCH v1 4/8] perf util: Support no index time percent slice Jin Yao
@ 2018-01-10 15:00 ` Jin Yao
  2018-01-17 16:36   ` [tip:perf/core] " tip-bot for Jin Yao
  2018-01-10 15:00 ` [PATCH v1 6/8] perf util: Allocate time slices buffer according to number of comma Jin Yao
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 22+ messages in thread
From: Jin Yao @ 2018-01-10 15:00 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

Add a time slices indication to the perf report header.

For example,

  # perf report --stdio --time 10%

  # Total Lost Samples: 0
  #
  # Samples: 9K of event 'cycles:ppp' (time slices: 10%)
  # Event count (approx.): 8951288803

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/builtin-report.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index a6c5cf2..77c954c 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -403,6 +403,9 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
 	if (evname != NULL)
 		ret += fprintf(fp, " of event '%s'", evname);
 
+	if (rep->time_str)
+		ret += fprintf(fp, " (time slices: %s)", rep->time_str);
+
 	if (symbol_conf.show_ref_callgraph &&
 	    strstr(evname, "call-graph=no")) {
 		ret += fprintf(fp, ", show reference callgraph");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v1 6/8] perf util: Allocate time slices buffer according to number of comma
  2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
                   ` (4 preceding siblings ...)
  2018-01-10 15:00 ` [PATCH v1 5/8] perf report: Add an indication of what time slices are used Jin Yao
@ 2018-01-10 15:00 ` Jin Yao
  2018-01-17 16:37   ` [tip:perf/core] " tip-bot for Jin Yao
  2018-01-10 15:00 ` [PATCH v1 7/8] perf report: Remove the time slices number limitation Jin Yao
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 22+ messages in thread
From: Jin Yao @ 2018-01-10 15:00 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

Previously we use a magic number 10 to limit the number of
time slices. It's not very good.

This patch creates a new function perf_time__range_alloc()
to allocate time slices buffer. The number of buffer entries is
determined by the number of comma in string but at least it will
allocate one entry even if no comma is found.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/util/time-utils.c | 28 ++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h |  2 ++
 2 files changed, 30 insertions(+)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 5769f97..6193b46 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -325,6 +325,34 @@ int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 	return -1;
 }
 
+struct perf_time_interval *perf_time__range_alloc(const char *ostr, int *size)
+{
+	const char *p1, *p2;
+	int i = 1;
+	struct perf_time_interval *ptime;
+
+	/*
+	 * At least allocate one time range.
+	 */
+	if (!ostr)
+		goto alloc;
+
+	p1 = ostr;
+	while (p1 < ostr + strlen(ostr)) {
+		p2 = strchr(p1, ',');
+		if (!p2)
+			break;
+
+		p1 = p2 + 1;
+		i++;
+	}
+
+alloc:
+	*size = i;
+	ptime = calloc(i, sizeof(*ptime));
+	return ptime;
+}
+
 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp)
 {
 	/* if time is not set don't drop sample */
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index 34d5eba..70b177d 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -16,6 +16,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
 int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 				 const char *ostr, u64 start, u64 end);
 
+struct perf_time_interval *perf_time__range_alloc(const char *ostr, int *size);
+
 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
 
 bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v1 7/8] perf report: Remove the time slices number limitation
  2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
                   ` (5 preceding siblings ...)
  2018-01-10 15:00 ` [PATCH v1 6/8] perf util: Allocate time slices buffer according to number of comma Jin Yao
@ 2018-01-10 15:00 ` Jin Yao
  2018-01-16 14:45   ` Arnaldo Carvalho de Melo
  2018-01-17 16:37   ` [tip:perf/core] " tip-bot for Jin Yao
  2018-01-10 15:00 ` [PATCH v1 8/8] perf script: " Jin Yao
  2018-01-16 11:55 ` [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jiri Olsa
  8 siblings, 2 replies; 22+ messages in thread
From: Jin Yao @ 2018-01-10 15:00 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

Previously it was only allowed to use at most 10 time slices
in 'perf report --time'.

This patch removes this limitation.
For example, following command line is OK (12 time slices)

perf report --stdio --time 1%/1,1%/2,1%/3,1%/4,1%/5,1%/6,1%/7,1%/8,1%/9,1%/10,1%/11,1%/12

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

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 5522ce0..1940c4f 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -403,7 +403,7 @@ OPTIONS
 	to end of file.
 
 	Also support time percent with multiple time range. Time string is
-	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. The maximum number of slices is 10.
+	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
 
 	For example:
 	Select the second 10% time slice:
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 77c954c..fe89021 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -54,8 +54,6 @@
 #include <unistd.h>
 #include <linux/mman.h>
 
-#define PTIME_RANGE_MAX	10
-
 struct report {
 	struct perf_tool	tool;
 	struct perf_session	*session;
@@ -76,7 +74,8 @@ struct report {
 	const char		*cpu_list;
 	const char		*symbol_filter_str;
 	const char		*time_str;
-	struct perf_time_interval ptime_range[PTIME_RANGE_MAX];
+	struct perf_time_interval *ptime_range;
+	int			range_size;
 	int			range_num;
 	float			min_percent;
 	u64			nr_entries;
@@ -1299,24 +1298,33 @@ int cmd_report(int argc, const char **argv)
 	if (symbol__init(&session->header.env) < 0)
 		goto error;
 
+	report.ptime_range = perf_time__range_alloc(report.time_str,
+						    &report.range_size);
+	if (!report.ptime_range) {
+		ret = -ENOMEM;
+		goto error;
+	}
+
 	if (perf_time__parse_str(report.ptime_range, report.time_str) != 0) {
 		if (session->evlist->first_sample_time == 0 &&
 		    session->evlist->last_sample_time == 0) {
 			pr_err("HINT: no first/last sample time found in perf data.\n"
 			       "Please use latest perf binary to execute 'perf record'\n"
 			       "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n");
-			return -EINVAL;
+			ret = -EINVAL;
+			goto error;
 		}
 
 		report.range_num = perf_time__percent_parse_str(
-					report.ptime_range, PTIME_RANGE_MAX,
+					report.ptime_range, report.range_size,
 					report.time_str,
 					session->evlist->first_sample_time,
 					session->evlist->last_sample_time);
 
 		if (report.range_num < 0) {
 			pr_err("Invalid time string\n");
-			return -EINVAL;
+			ret = -EINVAL;
+			goto error;
 		}
 	} else {
 		report.range_num = 1;
@@ -1332,6 +1340,9 @@ int cmd_report(int argc, const char **argv)
 		ret = 0;
 
 error:
+	if (report.ptime_range)
+		free(report.ptime_range);
+
 	perf_session__delete(session);
 	return ret;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v1 8/8] perf script: Remove the time slices number limitation
  2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
                   ` (6 preceding siblings ...)
  2018-01-10 15:00 ` [PATCH v1 7/8] perf report: Remove the time slices number limitation Jin Yao
@ 2018-01-10 15:00 ` Jin Yao
  2018-01-17 16:37   ` [tip:perf/core] " tip-bot for Jin Yao
  2018-01-16 11:55 ` [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jiri Olsa
  8 siblings, 1 reply; 22+ messages in thread
From: Jin Yao @ 2018-01-10 15:00 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

Previously it was only allowed to use at most 10 time slices
in 'perf script --time'.

This patch removes this limitation.
For example, following command line is OK (12 time slices)

perf script --time 1%/1,1%/2,1%/3,1%/4,1%/5,1%/6,1%/7,1%/8,1%/9,1%/10,1%/11,1%/12

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

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 806ec63..7730c1d 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -351,19 +351,19 @@ include::itrace.txt[]
 	to end of file.
 
 	Also support time percent with multipe time range. Time string is
-	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. The maximum number of slices is 10.
+	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
 
 	For example:
-	Select the second 10% time slice
+	Select the second 10% time slice:
 	perf script --time 10%/2
 
-	Select from 0% to 10% time slice
+	Select from 0% to 10% time slice:
 	perf script --time 0%-10%
 
-	Select the first and second 10% time slices
+	Select the first and second 10% time slices:
 	perf script --time 10%/1,10%/2
 
-	Select from 0% to 10% and 30% to 40% slices
+	Select from 0% to 10% and 30% to 40% slices:
 	perf script --time 0%-10%,30%-40%
 
 --max-blocks::
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 4f691af..f116a31 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1480,8 +1480,6 @@ static int perf_sample__fprintf_synth(struct perf_sample *sample,
 	return 0;
 }
 
-#define PTIME_RANGE_MAX	10
-
 struct perf_script {
 	struct perf_tool	tool;
 	struct perf_session	*session;
@@ -1496,7 +1494,8 @@ struct perf_script {
 	struct thread_map	*threads;
 	int			name_width;
 	const char              *time_str;
-	struct perf_time_interval ptime_range[PTIME_RANGE_MAX];
+	struct perf_time_interval *ptime_range;
+	int			range_size;
 	int			range_num;
 };
 
@@ -3444,6 +3443,13 @@ int cmd_script(int argc, const char **argv)
 	if (err < 0)
 		goto out_delete;
 
+	script.ptime_range = perf_time__range_alloc(script.time_str,
+						    &script.range_size);
+	if (!script.ptime_range) {
+		err = -ENOMEM;
+		goto out_delete;
+	}
+
 	/* needs to be parsed after looking up reference time */
 	if (perf_time__parse_str(script.ptime_range, script.time_str) != 0) {
 		if (session->evlist->first_sample_time == 0 &&
@@ -3456,7 +3462,7 @@ int cmd_script(int argc, const char **argv)
 		}
 
 		script.range_num = perf_time__percent_parse_str(
-					script.ptime_range, PTIME_RANGE_MAX,
+					script.ptime_range, script.range_size,
 					script.time_str,
 					session->evlist->first_sample_time,
 					session->evlist->last_sample_time);
@@ -3475,6 +3481,9 @@ int cmd_script(int argc, const char **argv)
 	flush_scripting();
 
 out_delete:
+	if (script.ptime_range)
+		free(script.ptime_range);
+
 	perf_evlist__free_stats(session->evlist);
 	perf_session__delete(session);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 0/8] perf: Follow-up patches to improve time slice
  2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
                   ` (7 preceding siblings ...)
  2018-01-10 15:00 ` [PATCH v1 8/8] perf script: " Jin Yao
@ 2018-01-16 11:55 ` Jiri Olsa
  2018-01-16 12:31   ` Jin, Yao
  2018-01-16 14:48   ` Arnaldo Carvalho de Melo
  8 siblings, 2 replies; 22+ messages in thread
From: Jiri Olsa @ 2018-01-16 11:55 UTC (permalink / raw)
  To: Jin Yao
  Cc: acme, jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin

On Wed, Jan 10, 2018 at 11:00:25PM +0800, Jin Yao wrote:
> It's follow-up patches to improve the perf time slice feature
> (perf report/script --time xxx)
> 
> 1. Improve the error message
>    perf report: Improve error msg when no first/last sample time found
>    perf script: Improve error msg when no first/last sample time found
> 
> 2. Fix an issue that illegal percent was accepted previously (e.g. 1abc%)
>    perf util: Improve error checking for time percent input
> 
> 3. Omit the slice index if possible. For example,
>    perf report --stdio --time 10%/1 is equivalent to
>    perf report --stdio --time 10%
> 
>    perf util: Support no index time percent slice 
> 
> 4. Add indication of time slices in perf report header.
>    perf report: Add an indication of what time slices are used
> 
> 5. Remove the time slices number limitation in perf report/script
>    perf util: Allocate time slices buffer according to number of comma
>    perf report: Remove the time slices number limitation
>    perf script: Remove the time slices number limitation
> 
> Jin Yao (8):
>   perf report: Improve error msg when no first/last sample time found
>   perf script: Improve error msg when no first/last sample time found
>   perf util: Improve error checking for time percent input
>   perf util: Support no index time percent slice
>   perf report: Add an indication of what time slices are used
>   perf util: Allocate time slices buffer according to number of comma
>   perf report: Remove the time slices number limitation
>   perf script: Remove the time slices number limitation

from quick look it looks ok

Reviewed-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 0/8] perf: Follow-up patches to improve time slice
  2018-01-16 11:55 ` [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jiri Olsa
@ 2018-01-16 12:31   ` Jin, Yao
  2018-01-16 14:48   ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 22+ messages in thread
From: Jin, Yao @ 2018-01-16 12:31 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: acme, jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin



On 1/16/2018 7:55 PM, Jiri Olsa wrote:
> On Wed, Jan 10, 2018 at 11:00:25PM +0800, Jin Yao wrote:
>> It's follow-up patches to improve the perf time slice feature
>> (perf report/script --time xxx)
>>
>> 1. Improve the error message
>>     perf report: Improve error msg when no first/last sample time found
>>     perf script: Improve error msg when no first/last sample time found
>>
>> 2. Fix an issue that illegal percent was accepted previously (e.g. 1abc%)
>>     perf util: Improve error checking for time percent input
>>
>> 3. Omit the slice index if possible. For example,
>>     perf report --stdio --time 10%/1 is equivalent to
>>     perf report --stdio --time 10%
>>
>>     perf util: Support no index time percent slice
>>
>> 4. Add indication of time slices in perf report header.
>>     perf report: Add an indication of what time slices are used
>>
>> 5. Remove the time slices number limitation in perf report/script
>>     perf util: Allocate time slices buffer according to number of comma
>>     perf report: Remove the time slices number limitation
>>     perf script: Remove the time slices number limitation
>>
>> Jin Yao (8):
>>    perf report: Improve error msg when no first/last sample time found
>>    perf script: Improve error msg when no first/last sample time found
>>    perf util: Improve error checking for time percent input
>>    perf util: Support no index time percent slice
>>    perf report: Add an indication of what time slices are used
>>    perf util: Allocate time slices buffer according to number of comma
>>    perf report: Remove the time slices number limitation
>>    perf script: Remove the time slices number limitation
> 
> from quick look it looks ok
> 
> Reviewed-by: Jiri Olsa <jolsa@redhat.com>
> 
> thanks,
> jirka
> 

Hi Jiri,

Thanks so much for reviewing the patch.

Thanks
Jin Yao

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 7/8] perf report: Remove the time slices number limitation
  2018-01-10 15:00 ` [PATCH v1 7/8] perf report: Remove the time slices number limitation Jin Yao
@ 2018-01-16 14:45   ` Arnaldo Carvalho de Melo
  2018-01-17 16:37   ` [tip:perf/core] " tip-bot for Jin Yao
  1 sibling, 0 replies; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-16 14:45 UTC (permalink / raw)
  To: Jin Yao
  Cc: jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin

Em Wed, Jan 10, 2018 at 11:00:32PM +0800, Jin Yao escreveu:
>  error:
> +	if (report.ptime_range)
> +		free(report.ptime_range);
> +

You don't need to check if it is NULL, free(NULL) is ok and more
compact, I'm fixing this.

- Arnaldo

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 0/8] perf: Follow-up patches to improve time slice
  2018-01-16 11:55 ` [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jiri Olsa
  2018-01-16 12:31   ` Jin, Yao
@ 2018-01-16 14:48   ` Arnaldo Carvalho de Melo
  2018-01-17  1:18     ` Jin, Yao
  1 sibling, 1 reply; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-16 14:48 UTC (permalink / raw)
  To: Jin Yao
  Cc: jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin

Em Tue, Jan 16, 2018 at 12:55:19PM +0100, Jiri Olsa escreveu:
> On Wed, Jan 10, 2018 at 11:00:25PM +0800, Jin Yao wrote:
> > It's follow-up patches to improve the perf time slice feature
> > (perf report/script --time xxx)
> > 
> > 1. Improve the error message
> >    perf report: Improve error msg when no first/last sample time found
> >    perf script: Improve error msg when no first/last sample time found
> > 
> > 2. Fix an issue that illegal percent was accepted previously (e.g. 1abc%)
> >    perf util: Improve error checking for time percent input
> > 
> > 3. Omit the slice index if possible. For example,
> >    perf report --stdio --time 10%/1 is equivalent to
> >    perf report --stdio --time 10%
> > 
> >    perf util: Support no index time percent slice 
> > 
> > 4. Add indication of time slices in perf report header.
> >    perf report: Add an indication of what time slices are used
> > 
> > 5. Remove the time slices number limitation in perf report/script
> >    perf util: Allocate time slices buffer according to number of comma
> >    perf report: Remove the time slices number limitation
> >    perf script: Remove the time slices number limitation
> > 
> > Jin Yao (8):
> >   perf report: Improve error msg when no first/last sample time found
> >   perf script: Improve error msg when no first/last sample time found
> >   perf util: Improve error checking for time percent input
> >   perf util: Support no index time percent slice
> >   perf report: Add an indication of what time slices are used
> >   perf util: Allocate time slices buffer according to number of comma
> >   perf report: Remove the time slices number limitation
> >   perf script: Remove the time slices number limitation
> 
> from quick look it looks ok
> 
> Reviewed-by: Jiri Olsa <jolsa@redhat.com>

Thanks, applied, now test building with 'make -C tools/perf build-test',
containers, etc.

- Arnaldo

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 0/8] perf: Follow-up patches to improve time slice
  2018-01-16 14:48   ` Arnaldo Carvalho de Melo
@ 2018-01-17  1:18     ` Jin, Yao
  0 siblings, 0 replies; 22+ messages in thread
From: Jin, Yao @ 2018-01-17  1:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin



On 1/16/2018 10:48 PM, Arnaldo Carvalho de Melo wrote:
> Em Tue, Jan 16, 2018 at 12:55:19PM +0100, Jiri Olsa escreveu:
>> On Wed, Jan 10, 2018 at 11:00:25PM +0800, Jin Yao wrote:
>>> It's follow-up patches to improve the perf time slice feature
>>> (perf report/script --time xxx)
>>>
>>> 1. Improve the error message
>>>     perf report: Improve error msg when no first/last sample time found
>>>     perf script: Improve error msg when no first/last sample time found
>>>
>>> 2. Fix an issue that illegal percent was accepted previously (e.g. 1abc%)
>>>     perf util: Improve error checking for time percent input
>>>
>>> 3. Omit the slice index if possible. For example,
>>>     perf report --stdio --time 10%/1 is equivalent to
>>>     perf report --stdio --time 10%
>>>
>>>     perf util: Support no index time percent slice
>>>
>>> 4. Add indication of time slices in perf report header.
>>>     perf report: Add an indication of what time slices are used
>>> >>> 5. Remove the time slices number limitation in perf report/script
>>>     perf util: Allocate time slices buffer according to number of comma
>>>     perf report: Remove the time slices number limitation
>>>     perf script: Remove the time slices number limitation
>>>
>>> Jin Yao (8):
>>>    perf report: Improve error msg when no first/last sample time found
>>>    perf script: Improve error msg when no first/last sample time found
>>>    perf util: Improve error checking for time percent input
>>>    perf util: Support no index time percent slice
>>>    perf report: Add an indication of what time slices are used
>>>    perf util: Allocate time slices buffer according to number of comma
>>>    perf report: Remove the time slices number limitation
>>>    perf script: Remove the time slices number limitation
>>
>> from quick look it looks ok
>>
>> Reviewed-by: Jiri Olsa <jolsa@redhat.com>
> 
> Thanks, applied, now test building with 'make -C tools/perf build-test',
> containers, etc.
> 
> - Arnaldo
> 

Thanks Arnaldo!

Thanks
Jin Yao

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [tip:perf/core] perf report: Improve error msg when no first/last sample time found
  2018-01-10 15:00 ` [PATCH v1 1/8] perf report: Improve error msg when no first/last sample time found Jin Yao
@ 2018-01-17 16:34   ` tip-bot for Jin Yao
  0 siblings, 0 replies; 22+ messages in thread
From: tip-bot for Jin Yao @ 2018-01-17 16:34 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, tglx, ak, yao.jin, hpa, linux-kernel, kan.liang, acme,
	alexander.shishkin, jolsa, mingo

Commit-ID:  eb0b419eff8cf51af8e16cc8c5d2a92d19824266
Gitweb:     https://git.kernel.org/tip/eb0b419eff8cf51af8e16cc8c5d2a92d19824266
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Wed, 10 Jan 2018 23:00:26 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 17 Jan 2018 10:23:34 -0300

perf report: Improve error msg when no first/last sample time found

The following message will be returned to user when executing
'perf report --time' if perf data file doesn't contain the
first/last sample time.

"HINT: no first/last sample time found in perf data.
 Please use latest perf binary to execute 'perf record'
 (if '--buildid-all' is enabled, needs to set '--timestamp-boundary')."

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1515596433-24653-2-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-report.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 6593779..7d4f0a5 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1300,7 +1300,9 @@ repeat:
 	if (perf_time__parse_str(report.ptime_range, report.time_str) != 0) {
 		if (session->evlist->first_sample_time == 0 &&
 		    session->evlist->last_sample_time == 0) {
-			pr_err("No first/last sample time in perf data\n");
+			pr_err("HINT: no first/last sample time found in perf data.\n"
+			       "Please use latest perf binary to execute 'perf record'\n"
+			       "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n");
 			return -EINVAL;
 		}
 

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [tip:perf/core] perf script: Improve error msg when no first/last sample time found
  2018-01-10 15:00 ` [PATCH v1 2/8] perf script: " Jin Yao
@ 2018-01-17 16:35   ` tip-bot for Jin Yao
  0 siblings, 0 replies; 22+ messages in thread
From: tip-bot for Jin Yao @ 2018-01-17 16:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, kan.liang, hpa, jolsa, mingo, yao.jin, acme, linux-kernel,
	ak, peterz, alexander.shishkin

Commit-ID:  1e2778e91616086177a255f3fc8c72ecaa564ae6
Gitweb:     https://git.kernel.org/tip/1e2778e91616086177a255f3fc8c72ecaa564ae6
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Wed, 10 Jan 2018 23:00:27 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 17 Jan 2018 10:23:34 -0300

perf script: Improve error msg when no first/last sample time found

The following message will be returned to user when executing 'perf
script --time' if perf data file doesn't contain the first/last sample
time.

"HINT: no first/last sample time found in perf data.
 Please use latest perf binary to execute 'perf record'
 (if '--buildid-all' is enabled, needs to set '--timestamp-boundary')."

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1515596433-24653-3-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-script.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 08bc818..ac78191 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3449,7 +3449,9 @@ int cmd_script(int argc, const char **argv)
 	if (perf_time__parse_str(script.ptime_range, script.time_str) != 0) {
 		if (session->evlist->first_sample_time == 0 &&
 		    session->evlist->last_sample_time == 0) {
-			pr_err("No first/last sample time in perf data\n");
+			pr_err("HINT: no first/last sample time found in perf data.\n"
+			       "Please use latest perf binary to execute 'perf record'\n"
+			       "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n");
 			err = -EINVAL;
 			goto out_delete;
 		}

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [tip:perf/core] perf util: Improve error checking for time percent input
  2018-01-10 15:00 ` [PATCH v1 3/8] perf util: Improve error checking for time percent input Jin Yao
@ 2018-01-17 16:35   ` tip-bot for Jin Yao
  0 siblings, 0 replies; 22+ messages in thread
From: tip-bot for Jin Yao @ 2018-01-17 16:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, kan.liang, acme, peterz, hpa, mingo, yao.jin,
	alexander.shishkin, tglx, ak, jolsa

Commit-ID:  6e761cbc9127fb8fc609aea2265ee8279b8d6c55
Gitweb:     https://git.kernel.org/tip/6e761cbc9127fb8fc609aea2265ee8279b8d6c55
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Wed, 10 Jan 2018 23:00:28 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 17 Jan 2018 10:23:35 -0300

perf util: Improve error checking for time percent input

The command line like 'perf report --stdio --time 1abc%/1' could be
accepted by perf. It looks not very good.

This patch uses strtod() to replace original atof() and check the entire
string. Now for the same command line, it would return error message
"Invalid time string".

root@skl:/tmp# perf report --stdio --time 1abc%/1
Invalid time string

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1515596433-24653-4-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/time-utils.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 3f7f18f..88510ab 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -116,7 +116,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr)
 
 static int parse_percent(double *pcnt, char *str)
 {
-	char *c;
+	char *c, *endptr;
+	double d;
 
 	c = strchr(str, '%');
 	if (c)
@@ -124,8 +125,11 @@ static int parse_percent(double *pcnt, char *str)
 	else
 		return -1;
 
-	*pcnt = atof(str) / 100.0;
+	d = strtod(str, &endptr);
+	if (endptr != str + strlen(str))
+		return -1;
 
+	*pcnt = d / 100.0;
 	return 0;
 }
 

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [tip:perf/core] perf util: Support no index time percent slice
  2018-01-10 15:00 ` [PATCH v1 4/8] perf util: Support no index time percent slice Jin Yao
@ 2018-01-17 16:36   ` tip-bot for Jin Yao
  0 siblings, 0 replies; 22+ messages in thread
From: tip-bot for Jin Yao @ 2018-01-17 16:36 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, ak, jolsa, yao.jin, kan.liang, acme, hpa,
	alexander.shishkin, linux-kernel, tglx, mingo

Commit-ID:  3002812e602d3f991a5b8cdc0499e63e13ff65c4
Gitweb:     https://git.kernel.org/tip/3002812e602d3f991a5b8cdc0499e63e13ff65c4
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Wed, 10 Jan 2018 23:00:29 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 17 Jan 2018 10:23:35 -0300

perf util: Support no index time percent slice

Previously, the time percent slice needs an index to specify which one
the user wants.

It may be easier to use if the index can be omitted.  So with this
patch, for example,

perf report --stdio --time 10%/1 should be equivalent to
perf report --stdio --time 10%

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1515596433-24653-5-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/time-utils.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 88510ab..5769f97 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -261,6 +261,37 @@ static int percent_comma_split(struct perf_time_interval *ptime_buf, int num,
 	return i;
 }
 
+static int one_percent_convert(struct perf_time_interval *ptime_buf,
+			       const char *ostr, u64 start, u64 end, char *c)
+{
+	char *str;
+	int len = strlen(ostr), ret;
+
+	/*
+	 * c points to '%'.
+	 * '%' should be the last character
+	 */
+	if (ostr + len - 1 != c)
+		return -1;
+
+	/*
+	 * Construct a string like "xx%/1"
+	 */
+	str = malloc(len + 3);
+	if (str == NULL)
+		return -ENOMEM;
+
+	memcpy(str, ostr, len);
+	strcpy(str + len, "/1");
+
+	ret = percent_slash_split(str, ptime_buf, start, end);
+	if (ret == 0)
+		ret = 1;
+
+	free(str);
+	return ret;
+}
+
 int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 				 const char *ostr, u64 start, u64 end)
 {
@@ -270,6 +301,7 @@ int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 	 * ostr example:
 	 * 10%/2,10%/3: select the second 10% slice and the third 10% slice
 	 * 0%-10%,30%-40%: multiple time range
+	 * 50%: just one percent
 	 */
 
 	memset(ptime_buf, 0, sizeof(*ptime_buf) * num);
@@ -286,6 +318,10 @@ int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 					   end, percent_dash_split);
 	}
 
+	c = strchr(ostr, '%');
+	if (c)
+		return one_percent_convert(ptime_buf, ostr, start, end, c);
+
 	return -1;
 }
 

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [tip:perf/core] perf report: Add an indication of what time slices are used
  2018-01-10 15:00 ` [PATCH v1 5/8] perf report: Add an indication of what time slices are used Jin Yao
@ 2018-01-17 16:36   ` tip-bot for Jin Yao
  0 siblings, 0 replies; 22+ messages in thread
From: tip-bot for Jin Yao @ 2018-01-17 16:36 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: yao.jin, tglx, ak, jolsa, peterz, acme, hpa, alexander.shishkin,
	mingo, linux-kernel, kan.liang

Commit-ID:  7425664bbd3174814500c7ab8740cbb9bb25396c
Gitweb:     https://git.kernel.org/tip/7425664bbd3174814500c7ab8740cbb9bb25396c
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Wed, 10 Jan 2018 23:00:30 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 17 Jan 2018 10:23:36 -0300

perf report: Add an indication of what time slices are used

Add a time slices indication to the perf report header.

For example,

  # perf report --stdio --time 10%

  # Total Lost Samples: 0
  #
  # Samples: 9K of event 'cycles:ppp' (time slices: 10%)
  # Event count (approx.): 8951288803

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Suggested--by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1515596433-24653-6-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-report.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 7d4f0a5..4aaaa37 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -404,6 +404,9 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
 	if (evname != NULL)
 		ret += fprintf(fp, " of event '%s'", evname);
 
+	if (rep->time_str)
+		ret += fprintf(fp, " (time slices: %s)", rep->time_str);
+
 	if (symbol_conf.show_ref_callgraph &&
 	    strstr(evname, "call-graph=no")) {
 		ret += fprintf(fp, ", show reference callgraph");

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [tip:perf/core] perf util: Allocate time slices buffer according to number of comma
  2018-01-10 15:00 ` [PATCH v1 6/8] perf util: Allocate time slices buffer according to number of comma Jin Yao
@ 2018-01-17 16:37   ` tip-bot for Jin Yao
  0 siblings, 0 replies; 22+ messages in thread
From: tip-bot for Jin Yao @ 2018-01-17 16:37 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: kan.liang, alexander.shishkin, hpa, tglx, jolsa, linux-kernel,
	acme, peterz, mingo, ak, yao.jin

Commit-ID:  5a031f887cb8d60fe87d21159c3cf82c38f55679
Gitweb:     https://git.kernel.org/tip/5a031f887cb8d60fe87d21159c3cf82c38f55679
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Wed, 10 Jan 2018 23:00:31 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 17 Jan 2018 10:23:36 -0300

perf util: Allocate time slices buffer according to number of comma

Previously we use a magic number 10 to limit the number of time slices.
It's not very good.

This patch creates a new function perf_time__range_alloc() to allocate
time slices buffer. The number of buffer entries is determined by the
number of comma in string but at least it will allocate one entry even
if no comma is found.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1515596433-24653-7-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/time-utils.c | 28 ++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h |  2 ++
 2 files changed, 30 insertions(+)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 5769f97..6193b46 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -325,6 +325,34 @@ int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 	return -1;
 }
 
+struct perf_time_interval *perf_time__range_alloc(const char *ostr, int *size)
+{
+	const char *p1, *p2;
+	int i = 1;
+	struct perf_time_interval *ptime;
+
+	/*
+	 * At least allocate one time range.
+	 */
+	if (!ostr)
+		goto alloc;
+
+	p1 = ostr;
+	while (p1 < ostr + strlen(ostr)) {
+		p2 = strchr(p1, ',');
+		if (!p2)
+			break;
+
+		p1 = p2 + 1;
+		i++;
+	}
+
+alloc:
+	*size = i;
+	ptime = calloc(i, sizeof(*ptime));
+	return ptime;
+}
+
 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp)
 {
 	/* if time is not set don't drop sample */
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index 34d5eba..70b177d 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -16,6 +16,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
 int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 				 const char *ostr, u64 start, u64 end);
 
+struct perf_time_interval *perf_time__range_alloc(const char *ostr, int *size);
+
 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
 
 bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [tip:perf/core] perf report: Remove the time slices number limitation
  2018-01-10 15:00 ` [PATCH v1 7/8] perf report: Remove the time slices number limitation Jin Yao
  2018-01-16 14:45   ` Arnaldo Carvalho de Melo
@ 2018-01-17 16:37   ` tip-bot for Jin Yao
  1 sibling, 0 replies; 22+ messages in thread
From: tip-bot for Jin Yao @ 2018-01-17 16:37 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, jolsa, kan.liang, yao.jin, alexander.shishkin,
	jolsa, ak, peterz, acme, tglx, hpa, mingo

Commit-ID:  0a3cc3ae05c363dabd891ed5f918c62197de8c7f
Gitweb:     https://git.kernel.org/tip/0a3cc3ae05c363dabd891ed5f918c62197de8c7f
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Wed, 10 Jan 2018 23:00:32 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 17 Jan 2018 10:23:37 -0300

perf report: Remove the time slices number limitation

Previously it was only allowed to use at most 10 time slices in 'perf
report --time'.

This patch removes this limitation.
For example, following command line is OK (12 time slices)

perf report --stdio --time 1%/1,1%/2,1%/3,1%/4,1%/5,1%/6,1%/7,1%/8,1%/9,1%/10,1%/11,1%/12

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1515596433-24653-8-git-send-email-yao.jin@linux.intel.com
[ No need to check for NULL to call free, use zfree ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-report.txt |  2 +-
 tools/perf/builtin-report.c              | 22 ++++++++++++++++------
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 63d0db3..907e505 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -403,7 +403,7 @@ OPTIONS
 	to end of file.
 
 	Also support time percent with multiple time range. Time string is
-	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. The maximum number of slices is 10.
+	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
 
 	For example:
 	Select the second 10% time slice:
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 4aaaa37..42a52dc 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -54,8 +54,6 @@
 #include <unistd.h>
 #include <linux/mman.h>
 
-#define PTIME_RANGE_MAX	10
-
 struct report {
 	struct perf_tool	tool;
 	struct perf_session	*session;
@@ -76,7 +74,8 @@ struct report {
 	const char		*cpu_list;
 	const char		*symbol_filter_str;
 	const char		*time_str;
-	struct perf_time_interval ptime_range[PTIME_RANGE_MAX];
+	struct perf_time_interval *ptime_range;
+	int			range_size;
 	int			range_num;
 	float			min_percent;
 	u64			nr_entries;
@@ -1300,24 +1299,33 @@ repeat:
 	if (symbol__init(&session->header.env) < 0)
 		goto error;
 
+	report.ptime_range = perf_time__range_alloc(report.time_str,
+						    &report.range_size);
+	if (!report.ptime_range) {
+		ret = -ENOMEM;
+		goto error;
+	}
+
 	if (perf_time__parse_str(report.ptime_range, report.time_str) != 0) {
 		if (session->evlist->first_sample_time == 0 &&
 		    session->evlist->last_sample_time == 0) {
 			pr_err("HINT: no first/last sample time found in perf data.\n"
 			       "Please use latest perf binary to execute 'perf record'\n"
 			       "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n");
-			return -EINVAL;
+			ret = -EINVAL;
+			goto error;
 		}
 
 		report.range_num = perf_time__percent_parse_str(
-					report.ptime_range, PTIME_RANGE_MAX,
+					report.ptime_range, report.range_size,
 					report.time_str,
 					session->evlist->first_sample_time,
 					session->evlist->last_sample_time);
 
 		if (report.range_num < 0) {
 			pr_err("Invalid time string\n");
-			return -EINVAL;
+			ret = -EINVAL;
+			goto error;
 		}
 	} else {
 		report.range_num = 1;
@@ -1333,6 +1341,8 @@ repeat:
 		ret = 0;
 
 error:
+	zfree(&report.ptime_range);
+
 	perf_session__delete(session);
 	return ret;
 }

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [tip:perf/core] perf script: Remove the time slices number limitation
  2018-01-10 15:00 ` [PATCH v1 8/8] perf script: " Jin Yao
@ 2018-01-17 16:37   ` tip-bot for Jin Yao
  0 siblings, 0 replies; 22+ messages in thread
From: tip-bot for Jin Yao @ 2018-01-17 16:37 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, peterz, mingo, yao.jin, ak, alexander.shishkin,
	hpa, tglx, acme, jolsa, kan.liang

Commit-ID:  cc2ef584a863b7c8033b78723cd253ca47e9a589
Gitweb:     https://git.kernel.org/tip/cc2ef584a863b7c8033b78723cd253ca47e9a589
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Wed, 10 Jan 2018 23:00:33 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 17 Jan 2018 10:23:37 -0300

perf script: Remove the time slices number limitation

Previously it was only allowed to use at most 10 time slices in 'perf
script --time'.

This patch removes this limitation.
For example, following command line is OK (12 time slices)

perf script --time 1%/1,1%/2,1%/3,1%/4,1%/5,1%/6,1%/7,1%/8,1%/9,1%/10,1%/11,1%/12

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1515596433-24653-9-git-send-email-yao.jin@linux.intel.com
[ No need to check for NULL to call free, use zfree ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-script.txt | 10 +++++-----
 tools/perf/builtin-script.c              | 16 ++++++++++++----
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 806ec63..7730c1d 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -351,19 +351,19 @@ include::itrace.txt[]
 	to end of file.
 
 	Also support time percent with multipe time range. Time string is
-	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. The maximum number of slices is 10.
+	'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
 
 	For example:
-	Select the second 10% time slice
+	Select the second 10% time slice:
 	perf script --time 10%/2
 
-	Select from 0% to 10% time slice
+	Select from 0% to 10% time slice:
 	perf script --time 0%-10%
 
-	Select the first and second 10% time slices
+	Select the first and second 10% time slices:
 	perf script --time 10%/1,10%/2
 
-	Select from 0% to 10% and 30% to 40% slices
+	Select from 0% to 10% and 30% to 40% slices:
 	perf script --time 0%-10%,30%-40%
 
 --max-blocks::
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index ac78191..3499d68 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1480,8 +1480,6 @@ static int perf_sample__fprintf_synth(struct perf_sample *sample,
 	return 0;
 }
 
-#define PTIME_RANGE_MAX	10
-
 struct perf_script {
 	struct perf_tool	tool;
 	struct perf_session	*session;
@@ -1496,7 +1494,8 @@ struct perf_script {
 	struct thread_map	*threads;
 	int			name_width;
 	const char              *time_str;
-	struct perf_time_interval ptime_range[PTIME_RANGE_MAX];
+	struct perf_time_interval *ptime_range;
+	int			range_size;
 	int			range_num;
 };
 
@@ -3445,6 +3444,13 @@ int cmd_script(int argc, const char **argv)
 	if (err < 0)
 		goto out_delete;
 
+	script.ptime_range = perf_time__range_alloc(script.time_str,
+						    &script.range_size);
+	if (!script.ptime_range) {
+		err = -ENOMEM;
+		goto out_delete;
+	}
+
 	/* needs to be parsed after looking up reference time */
 	if (perf_time__parse_str(script.ptime_range, script.time_str) != 0) {
 		if (session->evlist->first_sample_time == 0 &&
@@ -3457,7 +3463,7 @@ int cmd_script(int argc, const char **argv)
 		}
 
 		script.range_num = perf_time__percent_parse_str(
-					script.ptime_range, PTIME_RANGE_MAX,
+					script.ptime_range, script.range_size,
 					script.time_str,
 					session->evlist->first_sample_time,
 					session->evlist->last_sample_time);
@@ -3476,6 +3482,8 @@ int cmd_script(int argc, const char **argv)
 	flush_scripting();
 
 out_delete:
+	zfree(&script.ptime_range);
+
 	perf_evlist__free_stats(session->evlist);
 	perf_session__delete(session);
 

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2018-01-17 16:40 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-10 15:00 [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jin Yao
2018-01-10 15:00 ` [PATCH v1 1/8] perf report: Improve error msg when no first/last sample time found Jin Yao
2018-01-17 16:34   ` [tip:perf/core] " tip-bot for Jin Yao
2018-01-10 15:00 ` [PATCH v1 2/8] perf script: " Jin Yao
2018-01-17 16:35   ` [tip:perf/core] " tip-bot for Jin Yao
2018-01-10 15:00 ` [PATCH v1 3/8] perf util: Improve error checking for time percent input Jin Yao
2018-01-17 16:35   ` [tip:perf/core] " tip-bot for Jin Yao
2018-01-10 15:00 ` [PATCH v1 4/8] perf util: Support no index time percent slice Jin Yao
2018-01-17 16:36   ` [tip:perf/core] " tip-bot for Jin Yao
2018-01-10 15:00 ` [PATCH v1 5/8] perf report: Add an indication of what time slices are used Jin Yao
2018-01-17 16:36   ` [tip:perf/core] " tip-bot for Jin Yao
2018-01-10 15:00 ` [PATCH v1 6/8] perf util: Allocate time slices buffer according to number of comma Jin Yao
2018-01-17 16:37   ` [tip:perf/core] " tip-bot for Jin Yao
2018-01-10 15:00 ` [PATCH v1 7/8] perf report: Remove the time slices number limitation Jin Yao
2018-01-16 14:45   ` Arnaldo Carvalho de Melo
2018-01-17 16:37   ` [tip:perf/core] " tip-bot for Jin Yao
2018-01-10 15:00 ` [PATCH v1 8/8] perf script: " Jin Yao
2018-01-17 16:37   ` [tip:perf/core] " tip-bot for Jin Yao
2018-01-16 11:55 ` [PATCH v1 0/8] perf: Follow-up patches to improve time slice Jiri Olsa
2018-01-16 12:31   ` Jin, Yao
2018-01-16 14:48   ` Arnaldo Carvalho de Melo
2018-01-17  1:18     ` Jin, Yao

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).