Skip to content

Commit 5a031f8

Browse files
Jin Yaoacmel
authored andcommitted
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 <[email protected]> Suggested-by: Arnaldo Carvalho de Melo <[email protected]> Reviewed-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Kan Liang <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7425664 commit 5a031f8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tools/perf/util/time-utils.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,34 @@ int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
325325
return -1;
326326
}
327327

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+
328356
bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp)
329357
{
330358
/* if time is not set don't drop sample */

tools/perf/util/time-utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
1616
int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
1717
const char *ostr, u64 start, u64 end);
1818

19+
struct perf_time_interval *perf_time__range_alloc(const char *ostr, int *size);
20+
1921
bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
2022

2123
bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,

0 commit comments

Comments
 (0)