linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jin Yao <yao.jin@linux.intel.com>
To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org,
	mingo@redhat.com, alexander.shishkin@linux.intel.com
Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com,
	kan.liang@intel.com, yao.jin@intel.com,
	Jin Yao <yao.jin@linux.intel.com>
Subject: [PATCH v1 4/8] perf util: Support no index time percent slice
Date: Wed, 10 Jan 2018 23:00:29 +0800	[thread overview]
Message-ID: <1515596433-24653-5-git-send-email-yao.jin@linux.intel.com> (raw)
In-Reply-To: <1515596433-24653-1-git-send-email-yao.jin@linux.intel.com>

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

  parent reply	other threads:[~2018-01-10  7:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Jin Yao [this message]
2018-01-17 16:36   ` [tip:perf/core] perf util: Support no index time percent slice 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1515596433-24653-5-git-send-email-yao.jin@linux.intel.com \
    --to=yao.jin@linux.intel.com \
    --cc=Linux-kernel@vger.kernel.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=yao.jin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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).