diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-12-28 19:48:33 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-12-30 05:59:57 -0500 |
commit | ae99fb2c335ef018520950ddc9692faacab39cf2 (patch) | |
tree | 9476516a203657b118f878d8ca6b4d0793a12c1e /tools/perf/util | |
parent | 769885f372300a7fcfb9e54e4e2990718d40b529 (diff) |
perf header: perf_header__push_event() shouldn't die
Just propagate eventual errors.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1262047716-23171-2-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/header.c | 16 | ||||
-rw-r--r-- | tools/perf/util/header.h | 2 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 18 |
3 files changed, 22 insertions, 14 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 6b3cb94e8a2b..709e3252f049 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -105,24 +105,28 @@ struct perf_trace_event_type { | |||
105 | static int event_count; | 105 | static int event_count; |
106 | static struct perf_trace_event_type *events; | 106 | static struct perf_trace_event_type *events; |
107 | 107 | ||
108 | void perf_header__push_event(u64 id, const char *name) | 108 | int perf_header__push_event(u64 id, const char *name) |
109 | { | 109 | { |
110 | if (strlen(name) > MAX_EVENT_NAME) | 110 | if (strlen(name) > MAX_EVENT_NAME) |
111 | pr_warning("Event %s will be truncated\n", name); | 111 | pr_warning("Event %s will be truncated\n", name); |
112 | 112 | ||
113 | if (!events) { | 113 | if (!events) { |
114 | events = malloc(sizeof(struct perf_trace_event_type)); | 114 | events = malloc(sizeof(struct perf_trace_event_type)); |
115 | if (!events) | 115 | if (events == NULL) |
116 | die("nomem"); | 116 | return -ENOMEM; |
117 | } else { | 117 | } else { |
118 | events = realloc(events, (event_count + 1) * sizeof(struct perf_trace_event_type)); | 118 | struct perf_trace_event_type *nevents; |
119 | if (!events) | 119 | |
120 | die("nomem"); | 120 | nevents = realloc(events, (event_count + 1) * sizeof(*events)); |
121 | if (nevents == NULL) | ||
122 | return -ENOMEM; | ||
123 | events = nevents; | ||
121 | } | 124 | } |
122 | memset(&events[event_count], 0, sizeof(struct perf_trace_event_type)); | 125 | memset(&events[event_count], 0, sizeof(struct perf_trace_event_type)); |
123 | events[event_count].event_id = id; | 126 | events[event_count].event_id = id; |
124 | strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1); | 127 | strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1); |
125 | event_count++; | 128 | event_count++; |
129 | return 0; | ||
126 | } | 130 | } |
127 | 131 | ||
128 | char *perf_header__find_event(u64 id) | 132 | char *perf_header__find_event(u64 id) |
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index d118d05d3abe..2b69aab67e35 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
@@ -64,7 +64,7 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit); | |||
64 | int perf_header__add_attr(struct perf_header *self, | 64 | int perf_header__add_attr(struct perf_header *self, |
65 | struct perf_header_attr *attr); | 65 | struct perf_header_attr *attr); |
66 | 66 | ||
67 | void perf_header__push_event(u64 id, const char *name); | 67 | int perf_header__push_event(u64 id, const char *name); |
68 | char *perf_header__find_event(u64 id); | 68 | char *perf_header__find_event(u64 id); |
69 | 69 | ||
70 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr); | 70 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr); |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index dc585a835cab..609d5a9470c5 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -753,11 +753,11 @@ modifier: | |||
753 | return ret; | 753 | return ret; |
754 | } | 754 | } |
755 | 755 | ||
756 | static void store_event_type(const char *orgname) | 756 | static int store_event_type(const char *orgname) |
757 | { | 757 | { |
758 | char filename[PATH_MAX], *c; | 758 | char filename[PATH_MAX], *c; |
759 | FILE *file; | 759 | FILE *file; |
760 | int id; | 760 | int id, n; |
761 | 761 | ||
762 | sprintf(filename, "%s/", debugfs_path); | 762 | sprintf(filename, "%s/", debugfs_path); |
763 | strncat(filename, orgname, strlen(orgname)); | 763 | strncat(filename, orgname, strlen(orgname)); |
@@ -769,11 +769,14 @@ static void store_event_type(const char *orgname) | |||
769 | 769 | ||
770 | file = fopen(filename, "r"); | 770 | file = fopen(filename, "r"); |
771 | if (!file) | 771 | if (!file) |
772 | return; | 772 | return 0; |
773 | if (fscanf(file, "%i", &id) < 1) | 773 | n = fscanf(file, "%i", &id); |
774 | die("cannot store event ID"); | ||
775 | fclose(file); | 774 | fclose(file); |
776 | perf_header__push_event(id, orgname); | 775 | if (n < 1) { |
776 | pr_err("cannot store event ID\n"); | ||
777 | return -EINVAL; | ||
778 | } | ||
779 | return perf_header__push_event(id, orgname); | ||
777 | } | 780 | } |
778 | 781 | ||
779 | int parse_events(const struct option *opt __used, const char *str, int unset __used) | 782 | int parse_events(const struct option *opt __used, const char *str, int unset __used) |
@@ -782,7 +785,8 @@ int parse_events(const struct option *opt __used, const char *str, int unset __u | |||
782 | enum event_result ret; | 785 | enum event_result ret; |
783 | 786 | ||
784 | if (strchr(str, ':')) | 787 | if (strchr(str, ':')) |
785 | store_event_type(str); | 788 | if (store_event_type(str) < 0) |
789 | return -1; | ||
786 | 790 | ||
787 | for (;;) { | 791 | for (;;) { |
788 | if (nr_counters == MAX_COUNTERS) | 792 | if (nr_counters == MAX_COUNTERS) |