Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jin Yao and committed by
Arnaldo Carvalho de Melo
3002812e 6e761cbc

+36
+36
tools/perf/util/time-utils.c
··· 261 261 return i; 262 262 } 263 263 264 + static int one_percent_convert(struct perf_time_interval *ptime_buf, 265 + const char *ostr, u64 start, u64 end, char *c) 266 + { 267 + char *str; 268 + int len = strlen(ostr), ret; 269 + 270 + /* 271 + * c points to '%'. 272 + * '%' should be the last character 273 + */ 274 + if (ostr + len - 1 != c) 275 + return -1; 276 + 277 + /* 278 + * Construct a string like "xx%/1" 279 + */ 280 + str = malloc(len + 3); 281 + if (str == NULL) 282 + return -ENOMEM; 283 + 284 + memcpy(str, ostr, len); 285 + strcpy(str + len, "/1"); 286 + 287 + ret = percent_slash_split(str, ptime_buf, start, end); 288 + if (ret == 0) 289 + ret = 1; 290 + 291 + free(str); 292 + return ret; 293 + } 294 + 264 295 int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num, 265 296 const char *ostr, u64 start, u64 end) 266 297 { ··· 301 270 * ostr example: 302 271 * 10%/2,10%/3: select the second 10% slice and the third 10% slice 303 272 * 0%-10%,30%-40%: multiple time range 273 + * 50%: just one percent 304 274 */ 305 275 306 276 memset(ptime_buf, 0, sizeof(*ptime_buf) * num); ··· 317 285 return percent_comma_split(ptime_buf, num, ostr, start, 318 286 end, percent_dash_split); 319 287 } 288 + 289 + c = strchr(ostr, '%'); 290 + if (c) 291 + return one_percent_convert(ptime_buf, ostr, start, end, c); 320 292 321 293 return -1; 322 294 }