Skip to contentSkip to conversation

perf: Follow-up patches to improve time slice

PATCH In review Jin Yao 4 participants 22 messages Jan 10, 2018 – Jan 17, 2018 perf events

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

cover perf: Follow-up patches to improve time slice

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(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/8 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')."

---
 tools/perf/builtin-report.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-report.c +3 -1
index dd4df9a..a6c5cf2 100644
@@ -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;
 		}
 
Signature · 1 line
2.7.4
#2 lore raw

[tip:perf/core] perf report: Improve error msg when no first/last sample time found

perf report: Improve error msg when no first/last sample time found
Commit-ID:  eb0b419eff8cf51af8e16cc8c5d2a92d19824266
Gitweb:     https://git.kernel.org/tip/eb0b419eff8cf51af8e16cc8c5d2a92d19824266
Author:     Jin Yao <[email protected]>
AuthorDate: Wed, 10 Jan 2018 23:00:26 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
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')."

---
 tools/perf/builtin-report.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-report.c +3 -1
index 6593779..7d4f0a5 100644
@@ -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;
 		}
 
author
#3 lore raw

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

In reply to 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')."

---
 tools/perf/builtin-script.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +3 -1
index c1cce47..4f691af 100644
@@ -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;
 		}
Signature · 1 line
2.7.4
#4 lore raw

[tip:perf/core] perf script: Improve error msg when no first/last sample time found

perf script: Improve error msg when no first/last sample time found
Commit-ID:  1e2778e91616086177a255f3fc8c72ecaa564ae6
Gitweb:     https://git.kernel.org/tip/1e2778e91616086177a255f3fc8c72ecaa564ae6
Author:     Jin Yao <[email protected]>
AuthorDate: Wed, 10 Jan 2018 23:00:27 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
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')."

---
 tools/perf/builtin-script.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +3 -1
index 08bc818..ac78191 100644
@@ -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;
 		}
author
#5 lore raw

PATCH 3/8 perf util: Improve error checking for time percent input

In reply to 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
---
 tools/perf/util/time-utils.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/time-utils.c +6 -2
index 3f7f18f..88510ab 100644
@@ -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;
 }
 
Signature · 1 line
2.7.4
#6 lore raw

[tip:perf/core] perf util: Improve error checking for time percent input

perf util: Improve error checking for time percent input
Commit-ID:  6e761cbc9127fb8fc609aea2265ee8279b8d6c55
Gitweb:     https://git.kernel.org/tip/6e761cbc9127fb8fc609aea2265ee8279b8d6c55
Author:     Jin Yao <[email protected]>
AuthorDate: Wed, 10 Jan 2018 23:00:28 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
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
---
 tools/perf/util/time-utils.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/time-utils.c +6 -2
index 3f7f18f..88510ab 100644
@@ -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;
 }
 
author
#7 lore raw

PATCH 4/8 perf util: Support no index time percent slice

In reply to 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%

---
 tools/perf/util/time-utils.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tools/perf/util/time-utils.c +36 -0
index 88510ab..5769f97 100644
@@ -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;
 }
 
Signature · 1 line
2.7.4
#8 lore raw

[tip:perf/core] perf util: Support no index time percent slice

perf util: Support no index time percent slice
Commit-ID:  3002812e602d3f991a5b8cdc0499e63e13ff65c4
Gitweb:     https://git.kernel.org/tip/3002812e602d3f991a5b8cdc0499e63e13ff65c4
Author:     Jin Yao <[email protected]>
AuthorDate: Wed, 10 Jan 2018 23:00:29 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
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%

---
 tools/perf/util/time-utils.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tools/perf/util/time-utils.c +36 -0
index 88510ab..5769f97 100644
@@ -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;
 }
 
author
#9 lore raw

PATCH 5/8 perf report: Add an indication of what time slices are used

In reply to 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

---
 tools/perf/builtin-report.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/builtin-report.c +3 -0
index a6c5cf2..77c954c 100644
@@ -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");
Signature · 1 line
2.7.4
#10 lore raw

[tip:perf/core] perf report: Add an indication of what time slices are used

perf report: Add an indication of what time slices are used
Commit-ID:  7425664bbd3174814500c7ab8740cbb9bb25396c
Gitweb:     https://git.kernel.org/tip/7425664bbd3174814500c7ab8740cbb9bb25396c
Author:     Jin Yao <[email protected]>
AuthorDate: Wed, 10 Jan 2018 23:00:30 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
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

---
 tools/perf/builtin-report.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/builtin-report.c +3 -0
index 7d4f0a5..4aaaa37 100644
@@ -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");
author
#11 lore raw

PATCH 6/8 perf util: Allocate time slices buffer according to number of comma

In reply to 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.

---
 tools/perf/util/time-utils.c | 28 ++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h |  2 ++
 2 files changed, 30 insertions(+)
tools/perf/util/time-utils.c +28 -0
index 5769f97..6193b46 100644
@@ -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 */
tools/perf/util/time-utils.h +2 -0
index 34d5eba..70b177d 100644
@@ -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,
Signature · 1 line
2.7.4
#12 lore raw

[tip:perf/core] perf util: Allocate time slices buffer according to number of comma

perf util: Allocate time slices buffer according to number of comma
Commit-ID:  5a031f887cb8d60fe87d21159c3cf82c38f55679
Gitweb:     https://git.kernel.org/tip/5a031f887cb8d60fe87d21159c3cf82c38f55679
Author:     Jin Yao <[email protected]>
AuthorDate: Wed, 10 Jan 2018 23:00:31 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
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.

---
 tools/perf/util/time-utils.c | 28 ++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h |  2 ++
 2 files changed, 30 insertions(+)
tools/perf/util/time-utils.c +28 -0
index 5769f97..6193b46 100644
@@ -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 */
tools/perf/util/time-utils.h +2 -0
index 34d5eba..70b177d 100644
@@ -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,
author
#13 lore raw

PATCH 7/8 perf report: Remove the time slices number limitation

In reply to 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

---
 tools/perf/Documentation/perf-report.txt |  2 +-
 tools/perf/builtin-report.c              | 23 +++++++++++++++++------
 2 files changed, 18 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf-report.txt +1 -1
index 5522ce0..1940c4f 100644
@@ -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:
tools/perf/builtin-report.c +17 -6
index 77c954c..fe89021 100644
@@ -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;
 }
Signature · 1 line
2.7.4
#14 lore raw

Re: [PATCH v1 7/8] perf report: Remove the time slices number limitation

Em Wed, Jan 10, 2018 at 11:00:32PM +0800, Jin Yao escreveu:

tools/perf/builtin-report.c int cmd_report(int argc, const char **argv) · line 1345

Quoted 4 lines

error:

tools/perf/builtin-report.c +3 -0
+	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

#15 lore raw

[tip:perf/core] perf report: Remove the time slices number limitation

In reply to Jin Yao
perf report: Remove the time slices number limitation
Commit-ID:  0a3cc3ae05c363dabd891ed5f918c62197de8c7f
Gitweb:     https://git.kernel.org/tip/0a3cc3ae05c363dabd891ed5f918c62197de8c7f
Author:     Jin Yao <[email protected]>
AuthorDate: Wed, 10 Jan 2018 23:00:32 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
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

Cc Alexander Shishkin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ No need to check for NULL to call free, use zfree ]
---
 tools/perf/Documentation/perf-report.txt |  2 +-
 tools/perf/builtin-report.c              | 22 ++++++++++++++++------
 2 files changed, 17 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf-report.txt +1 -1
index 63d0db3..907e505 100644
@@ -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:
tools/perf/builtin-report.c +16 -6
index 4aaaa37..42a52dc 100644
@@ -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;
 }
author
#16 lore raw

PATCH 8/8 perf script: Remove the time slices number limitation

In reply to 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

---
 tools/perf/Documentation/perf-script.txt | 10 +++++-----
 tools/perf/builtin-script.c              | 17 +++++++++++++----
 2 files changed, 18 insertions(+), 9 deletions(-)
tools/perf/Documentation/perf-script.txt +5 -5
index 806ec63..7730c1d 100644
@@ -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::
tools/perf/builtin-script.c +13 -4
index 4f691af..f116a31 100644
@@ -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);
 
Signature · 1 line
2.7.4
#17 lore raw

[tip:perf/core] perf script: Remove the time slices number limitation

perf script: Remove the time slices number limitation
Commit-ID:  cc2ef584a863b7c8033b78723cd253ca47e9a589
Gitweb:     https://git.kernel.org/tip/cc2ef584a863b7c8033b78723cd253ca47e9a589
Author:     Jin Yao <[email protected]>
AuthorDate: Wed, 10 Jan 2018 23:00:33 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
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

Cc Alexander Shishkin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Kan Liang <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ No need to check for NULL to call free, use zfree ]
---
 tools/perf/Documentation/perf-script.txt | 10 +++++-----
 tools/perf/builtin-script.c              | 16 ++++++++++++----
 2 files changed, 17 insertions(+), 9 deletions(-)
tools/perf/Documentation/perf-script.txt +5 -5
index 806ec63..7730c1d 100644
@@ -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::
tools/perf/builtin-script.c +12 -4
index ac78191..3499d68 100644
@@ -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);
 
Reviewed-by on the v1 series
#18 lore raw
In reply to Jin Yao
Quoted 24 lines · 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

Quoted 9 lines

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

thanks,
jirka

author
#19 lore raw
Quoted 35 lines · Jiri Olsa
Quoted 24 lines · 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

Quoted 9 lines

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

Quoted 7 lines

from quick look it looks ok

thanks,
jirka

Hi Jiri,

Thanks so much for reviewing the patch.

Thanks
Jin Yao

#20 lore raw
In reply to Jiri Olsa

Em Tue, Jan 16, 2018 at 12:55:19PM +0100, Jiri Olsa escreveu:

Quoted 35 lines · Jin Yao
Quoted 24 lines

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

Quoted 9 lines

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

Quoted 3 lines

from quick look it looks ok

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

- Arnaldo

author
#21 lore raw
Quoted 35 lines · Arnaldo Carvalho de Melo

Em Tue, Jan 16, 2018 at 12:55:19PM +0100, Jiri Olsa escreveu:

Quoted 34 lines · Jin Yao
Quoted 32 lines

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

Quoted 1 line
Quoted 1 line
Quoted 1 line

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

Quoted 9 lines
Quoted 3 lines

from quick look it looks ok

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

- Arnaldo

Thanks Arnaldo!

Thanks
Jin Yao