diff options
| -rw-r--r-- | tools/perf/util/evsel.h | 1 | ||||
| -rw-r--r-- | tools/perf/util/parse-events.c | 1 | ||||
| -rw-r--r-- | tools/perf/util/pmu.c | 47 | ||||
| -rw-r--r-- | tools/perf/util/pmu.h | 2 |
4 files changed, 40 insertions, 11 deletions
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 792b0ea8a8b8..b18d58da580b 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
| @@ -73,6 +73,7 @@ struct perf_evsel { | |||
| 73 | char *name; | 73 | char *name; |
| 74 | double scale; | 74 | double scale; |
| 75 | const char *unit; | 75 | const char *unit; |
| 76 | bool snapshot; | ||
| 76 | struct event_format *tp_format; | 77 | struct event_format *tp_format; |
| 77 | union { | 78 | union { |
| 78 | void *priv; | 79 | void *priv; |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 5a373483f0e4..77b43fe43d55 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
| @@ -682,6 +682,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx, | |||
| 682 | evsel->unit = info.unit; | 682 | evsel->unit = info.unit; |
| 683 | evsel->scale = info.scale; | 683 | evsel->scale = info.scale; |
| 684 | evsel->per_pkg = info.per_pkg; | 684 | evsel->per_pkg = info.per_pkg; |
| 685 | evsel->snapshot = info.snapshot; | ||
| 685 | } | 686 | } |
| 686 | 687 | ||
| 687 | return evsel ? 0 : -ENOMEM; | 688 | return evsel ? 0 : -ENOMEM; |
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index f003b5a9e059..5c9c4947cfb4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
| @@ -181,6 +181,23 @@ perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name) | |||
| 181 | return 0; | 181 | return 0; |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias, | ||
| 185 | char *dir, char *name) | ||
| 186 | { | ||
| 187 | char path[PATH_MAX]; | ||
| 188 | int fd; | ||
| 189 | |||
| 190 | snprintf(path, PATH_MAX, "%s/%s.snapshot", dir, name); | ||
| 191 | |||
| 192 | fd = open(path, O_RDONLY); | ||
| 193 | if (fd == -1) | ||
| 194 | return -1; | ||
| 195 | |||
| 196 | alias->snapshot = true; | ||
| 197 | close(fd); | ||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | |||
| 184 | static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file) | 201 | static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file) |
| 185 | { | 202 | { |
| 186 | struct perf_pmu_alias *alias; | 203 | struct perf_pmu_alias *alias; |
| @@ -214,6 +231,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI | |||
| 214 | perf_pmu__parse_unit(alias, dir, name); | 231 | perf_pmu__parse_unit(alias, dir, name); |
| 215 | perf_pmu__parse_scale(alias, dir, name); | 232 | perf_pmu__parse_scale(alias, dir, name); |
| 216 | perf_pmu__parse_per_pkg(alias, dir, name); | 233 | perf_pmu__parse_per_pkg(alias, dir, name); |
| 234 | perf_pmu__parse_snapshot(alias, dir, name); | ||
| 217 | 235 | ||
| 218 | list_add_tail(&alias->list, list); | 236 | list_add_tail(&alias->list, list); |
| 219 | 237 | ||
| @@ -231,6 +249,8 @@ static inline bool pmu_alias_info_file(char *name) | |||
| 231 | return true; | 249 | return true; |
| 232 | if (len > 8 && !strcmp(name + len - 8, ".per-pkg")) | 250 | if (len > 8 && !strcmp(name + len - 8, ".per-pkg")) |
| 233 | return true; | 251 | return true; |
| 252 | if (len > 9 && !strcmp(name + len - 9, ".snapshot")) | ||
| 253 | return true; | ||
| 234 | 254 | ||
| 235 | return false; | 255 | return false; |
| 236 | } | 256 | } |
| @@ -639,23 +659,27 @@ static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu, | |||
| 639 | } | 659 | } |
| 640 | 660 | ||
| 641 | 661 | ||
| 642 | static int check_unit_scale(struct perf_pmu_alias *alias, | 662 | static int check_info_data(struct perf_pmu_alias *alias, |
| 643 | const char **unit, double *scale) | 663 | struct perf_pmu_info *info) |
| 644 | { | 664 | { |
| 645 | /* | 665 | /* |
| 646 | * Only one term in event definition can | 666 | * Only one term in event definition can |
| 647 | * define unit and scale, fail if there's | 667 | * define unit, scale and snapshot, fail |
| 648 | * more than one. | 668 | * if there's more than one. |
| 649 | */ | 669 | */ |
| 650 | if ((*unit && alias->unit) || | 670 | if ((info->unit && alias->unit) || |
| 651 | (*scale && alias->scale)) | 671 | (info->scale && alias->scale) || |
| 672 | (info->snapshot && alias->snapshot)) | ||
| 652 | return -EINVAL; | 673 | return -EINVAL; |
| 653 | 674 | ||
| 654 | if (alias->unit) | 675 | if (alias->unit) |
| 655 | *unit = alias->unit; | 676 | info->unit = alias->unit; |
| 656 | 677 | ||
| 657 | if (alias->scale) | 678 | if (alias->scale) |
| 658 | *scale = alias->scale; | 679 | info->scale = alias->scale; |
| 680 | |||
| 681 | if (alias->snapshot) | ||
| 682 | info->snapshot = alias->snapshot; | ||
| 659 | 683 | ||
| 660 | return 0; | 684 | return 0; |
| 661 | } | 685 | } |
| @@ -677,8 +701,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, | |||
| 677 | * Mark unit and scale as not set | 701 | * Mark unit and scale as not set |
| 678 | * (different from default values, see below) | 702 | * (different from default values, see below) |
| 679 | */ | 703 | */ |
| 680 | info->unit = NULL; | 704 | info->unit = NULL; |
| 681 | info->scale = 0.0; | 705 | info->scale = 0.0; |
| 706 | info->snapshot = false; | ||
| 682 | 707 | ||
| 683 | list_for_each_entry_safe(term, h, head_terms, list) { | 708 | list_for_each_entry_safe(term, h, head_terms, list) { |
| 684 | alias = pmu_find_alias(pmu, term); | 709 | alias = pmu_find_alias(pmu, term); |
| @@ -688,7 +713,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, | |||
| 688 | if (ret) | 713 | if (ret) |
| 689 | return ret; | 714 | return ret; |
| 690 | 715 | ||
| 691 | ret = check_unit_scale(alias, &info->unit, &info->scale); | 716 | ret = check_info_data(alias, info); |
| 692 | if (ret) | 717 | if (ret) |
| 693 | return ret; | 718 | return ret; |
| 694 | 719 | ||
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index c3a74e0e17a2..6b1249fbdb5f 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h | |||
| @@ -30,6 +30,7 @@ struct perf_pmu_info { | |||
| 30 | const char *unit; | 30 | const char *unit; |
| 31 | double scale; | 31 | double scale; |
| 32 | bool per_pkg; | 32 | bool per_pkg; |
| 33 | bool snapshot; | ||
| 33 | }; | 34 | }; |
| 34 | 35 | ||
| 35 | #define UNIT_MAX_LEN 31 /* max length for event unit name */ | 36 | #define UNIT_MAX_LEN 31 /* max length for event unit name */ |
| @@ -41,6 +42,7 @@ struct perf_pmu_alias { | |||
| 41 | char unit[UNIT_MAX_LEN+1]; | 42 | char unit[UNIT_MAX_LEN+1]; |
| 42 | double scale; | 43 | double scale; |
| 43 | bool per_pkg; | 44 | bool per_pkg; |
| 45 | bool snapshot; | ||
| 44 | }; | 46 | }; |
| 45 | 47 | ||
| 46 | struct perf_pmu *perf_pmu__find(const char *name); | 48 | struct perf_pmu *perf_pmu__find(const char *name); |
