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

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>

authored by

Jin Yao and committed by
Arnaldo Carvalho de Melo
5a031f88 7425664b

+30
+28
tools/perf/util/time-utils.c
··· 325 325 return -1; 326 326 } 327 327 328 + struct perf_time_interval *perf_time__range_alloc(const char *ostr, int *size) 329 + { 330 + const char *p1, *p2; 331 + int i = 1; 332 + struct perf_time_interval *ptime; 333 + 334 + /* 335 + * At least allocate one time range. 336 + */ 337 + if (!ostr) 338 + goto alloc; 339 + 340 + p1 = ostr; 341 + while (p1 < ostr + strlen(ostr)) { 342 + p2 = strchr(p1, ','); 343 + if (!p2) 344 + break; 345 + 346 + p1 = p2 + 1; 347 + i++; 348 + } 349 + 350 + alloc: 351 + *size = i; 352 + ptime = calloc(i, sizeof(*ptime)); 353 + return ptime; 354 + } 355 + 328 356 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp) 329 357 { 330 358 /* if time is not set don't drop sample */
+2
tools/perf/util/time-utils.h
··· 16 16 int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num, 17 17 const char *ostr, u64 start, u64 end); 18 18 19 + struct perf_time_interval *perf_time__range_alloc(const char *ostr, int *size); 20 + 19 21 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); 20 22 21 23 bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,