diff options
-rw-r--r-- | tools/perf/builtin-report.c | 38 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 39 | ||||
-rw-r--r-- | tools/perf/util/time-utils.c | 51 | ||||
-rw-r--r-- | tools/perf/util/time-utils.h | 6 |
4 files changed, 72 insertions, 62 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1532ebde6c4b..ee93c18a6685 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -1375,36 +1375,13 @@ repeat: | |||
1375 | if (symbol__init(&session->header.env) < 0) | 1375 | if (symbol__init(&session->header.env) < 0) |
1376 | goto error; | 1376 | goto error; |
1377 | 1377 | ||
1378 | report.ptime_range = perf_time__range_alloc(report.time_str, | 1378 | if (report.time_str) { |
1379 | &report.range_size); | 1379 | ret = perf_time__parse_for_ranges(report.time_str, session, |
1380 | if (!report.ptime_range) { | 1380 | &report.ptime_range, |
1381 | ret = -ENOMEM; | 1381 | &report.range_size, |
1382 | goto error; | 1382 | &report.range_num); |
1383 | } | 1383 | if (ret < 0) |
1384 | |||
1385 | if (perf_time__parse_str(report.ptime_range, report.time_str) != 0) { | ||
1386 | if (session->evlist->first_sample_time == 0 && | ||
1387 | session->evlist->last_sample_time == 0) { | ||
1388 | pr_err("HINT: no first/last sample time found in perf data.\n" | ||
1389 | "Please use latest perf binary to execute 'perf record'\n" | ||
1390 | "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n"); | ||
1391 | ret = -EINVAL; | ||
1392 | goto error; | ||
1393 | } | ||
1394 | |||
1395 | report.range_num = perf_time__percent_parse_str( | ||
1396 | report.ptime_range, report.range_size, | ||
1397 | report.time_str, | ||
1398 | session->evlist->first_sample_time, | ||
1399 | session->evlist->last_sample_time); | ||
1400 | |||
1401 | if (report.range_num < 0) { | ||
1402 | pr_err("Invalid time string\n"); | ||
1403 | ret = -EINVAL; | ||
1404 | goto error; | 1384 | goto error; |
1405 | } | ||
1406 | } else { | ||
1407 | report.range_num = 1; | ||
1408 | } | 1385 | } |
1409 | 1386 | ||
1410 | if (session->tevent.pevent && | 1387 | if (session->tevent.pevent && |
@@ -1426,7 +1403,8 @@ repeat: | |||
1426 | ret = 0; | 1403 | ret = 0; |
1427 | 1404 | ||
1428 | error: | 1405 | error: |
1429 | zfree(&report.ptime_range); | 1406 | if (report.ptime_range) |
1407 | zfree(&report.ptime_range); | ||
1430 | 1408 | ||
1431 | perf_session__delete(session); | 1409 | perf_session__delete(session); |
1432 | return ret; | 1410 | return ret; |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 2d8cb1d1682c..53f78cf3113f 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -3699,37 +3699,13 @@ int cmd_script(int argc, const char **argv) | |||
3699 | if (err < 0) | 3699 | if (err < 0) |
3700 | goto out_delete; | 3700 | goto out_delete; |
3701 | 3701 | ||
3702 | script.ptime_range = perf_time__range_alloc(script.time_str, | 3702 | if (script.time_str) { |
3703 | &script.range_size); | 3703 | err = perf_time__parse_for_ranges(script.time_str, session, |
3704 | if (!script.ptime_range) { | 3704 | &script.ptime_range, |
3705 | err = -ENOMEM; | 3705 | &script.range_size, |
3706 | goto out_delete; | 3706 | &script.range_num); |
3707 | } | 3707 | if (err < 0) |
3708 | |||
3709 | /* needs to be parsed after looking up reference time */ | ||
3710 | if (perf_time__parse_str(script.ptime_range, script.time_str) != 0) { | ||
3711 | if (session->evlist->first_sample_time == 0 && | ||
3712 | session->evlist->last_sample_time == 0) { | ||
3713 | pr_err("HINT: no first/last sample time found in perf data.\n" | ||
3714 | "Please use latest perf binary to execute 'perf record'\n" | ||
3715 | "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n"); | ||
3716 | err = -EINVAL; | ||
3717 | goto out_delete; | ||
3718 | } | ||
3719 | |||
3720 | script.range_num = perf_time__percent_parse_str( | ||
3721 | script.ptime_range, script.range_size, | ||
3722 | script.time_str, | ||
3723 | session->evlist->first_sample_time, | ||
3724 | session->evlist->last_sample_time); | ||
3725 | |||
3726 | if (script.range_num < 0) { | ||
3727 | pr_err("Invalid time string\n"); | ||
3728 | err = -EINVAL; | ||
3729 | goto out_delete; | 3708 | goto out_delete; |
3730 | } | ||
3731 | } else { | ||
3732 | script.range_num = 1; | ||
3733 | } | 3709 | } |
3734 | 3710 | ||
3735 | err = __cmd_script(&script); | 3711 | err = __cmd_script(&script); |
@@ -3737,7 +3713,8 @@ int cmd_script(int argc, const char **argv) | |||
3737 | flush_scripting(); | 3713 | flush_scripting(); |
3738 | 3714 | ||
3739 | out_delete: | 3715 | out_delete: |
3740 | zfree(&script.ptime_range); | 3716 | if (script.ptime_range) |
3717 | zfree(&script.ptime_range); | ||
3741 | 3718 | ||
3742 | perf_evlist__free_stats(session->evlist); | 3719 | perf_evlist__free_stats(session->evlist); |
3743 | perf_session__delete(session); | 3720 | perf_session__delete(session); |
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c index 6193b46050a5..0f53baec660e 100644 --- a/tools/perf/util/time-utils.c +++ b/tools/perf/util/time-utils.c | |||
@@ -11,6 +11,8 @@ | |||
11 | #include "perf.h" | 11 | #include "perf.h" |
12 | #include "debug.h" | 12 | #include "debug.h" |
13 | #include "time-utils.h" | 13 | #include "time-utils.h" |
14 | #include "session.h" | ||
15 | #include "evlist.h" | ||
14 | 16 | ||
15 | int parse_nsec_time(const char *str, u64 *ptime) | 17 | int parse_nsec_time(const char *str, u64 *ptime) |
16 | { | 18 | { |
@@ -374,7 +376,7 @@ bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf, | |||
374 | struct perf_time_interval *ptime; | 376 | struct perf_time_interval *ptime; |
375 | int i; | 377 | int i; |
376 | 378 | ||
377 | if ((timestamp == 0) || (num == 0)) | 379 | if ((!ptime_buf) || (timestamp == 0) || (num == 0)) |
378 | return false; | 380 | return false; |
379 | 381 | ||
380 | if (num == 1) | 382 | if (num == 1) |
@@ -396,6 +398,53 @@ bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf, | |||
396 | return (i == num) ? true : false; | 398 | return (i == num) ? true : false; |
397 | } | 399 | } |
398 | 400 | ||
401 | int perf_time__parse_for_ranges(const char *time_str, | ||
402 | struct perf_session *session, | ||
403 | struct perf_time_interval **ranges, | ||
404 | int *range_size, int *range_num) | ||
405 | { | ||
406 | struct perf_time_interval *ptime_range; | ||
407 | int size, num, ret; | ||
408 | |||
409 | ptime_range = perf_time__range_alloc(time_str, &size); | ||
410 | if (!ptime_range) | ||
411 | return -ENOMEM; | ||
412 | |||
413 | if (perf_time__parse_str(ptime_range, time_str) != 0) { | ||
414 | if (session->evlist->first_sample_time == 0 && | ||
415 | session->evlist->last_sample_time == 0) { | ||
416 | pr_err("HINT: no first/last sample time found in perf data.\n" | ||
417 | "Please use latest perf binary to execute 'perf record'\n" | ||
418 | "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n"); | ||
419 | ret = -EINVAL; | ||
420 | goto error; | ||
421 | } | ||
422 | |||
423 | num = perf_time__percent_parse_str( | ||
424 | ptime_range, size, | ||
425 | time_str, | ||
426 | session->evlist->first_sample_time, | ||
427 | session->evlist->last_sample_time); | ||
428 | |||
429 | if (num < 0) { | ||
430 | pr_err("Invalid time string\n"); | ||
431 | ret = -EINVAL; | ||
432 | goto error; | ||
433 | } | ||
434 | } else { | ||
435 | num = 1; | ||
436 | } | ||
437 | |||
438 | *range_size = size; | ||
439 | *range_num = num; | ||
440 | *ranges = ptime_range; | ||
441 | return 0; | ||
442 | |||
443 | error: | ||
444 | free(ptime_range); | ||
445 | return ret; | ||
446 | } | ||
447 | |||
399 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) | 448 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) |
400 | { | 449 | { |
401 | u64 sec = timestamp / NSEC_PER_SEC; | 450 | u64 sec = timestamp / NSEC_PER_SEC; |
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h index 70b177d2b98c..b923de44e36f 100644 --- a/tools/perf/util/time-utils.h +++ b/tools/perf/util/time-utils.h | |||
@@ -23,6 +23,12 @@ bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); | |||
23 | bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf, | 23 | bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf, |
24 | int num, u64 timestamp); | 24 | int num, u64 timestamp); |
25 | 25 | ||
26 | struct perf_session; | ||
27 | |||
28 | int perf_time__parse_for_ranges(const char *str, struct perf_session *session, | ||
29 | struct perf_time_interval **ranges, | ||
30 | int *range_size, int *range_num); | ||
31 | |||
26 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); | 32 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); |
27 | 33 | ||
28 | int fetch_current_timestamp(char *buf, size_t sz); | 34 | int fetch_current_timestamp(char *buf, size_t sz); |