aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2010-04-30 21:08:46 -0400
committerFrederic Weisbecker <fweisbec@gmail.com>2010-04-30 22:31:48 -0400
commitd00a47cce569a3e660a8c9de5d57af28d6a9f0f7 (patch)
tree0993bc6584d8726a7a921f9a13ce11f7c560cdb0 /tools/perf/util
parente5a5f1f015cf435eb3d2f5712ba51ffdbb92cbef (diff)
perf: Fix warning while reading ring buffer headers
commit e9e94e3bd862d31777335722e747e97d9821bc1d "perf trace: Ignore "overwrite" field if present in /events/header_page" makes perf trace launching spurious warnings about unexpected tokens read: Warning: Error: expected type 6 but read 4 This change tries to handle the overcommit field in the header_page file whenever this field is present or not. The problem is that if this field is not present, we try to find it and give up in the middle of the line when we realize we are actually dealing with another field, which is the "data" one. And this failure abandons the file pointer in the middle of the "data" description line: field: u64 timestamp; offset:0; size:8; signed:0; field: local_t commit; offset:8; size:8; signed:1; field: char data; offset:16; size:4080; signed:1; ^^^ Here What happens next is that we want to read this line to parse the data field, but we fail because the pointer is not in the beginning of the line. We could probably fix that by rewinding the pointer. But in fact we don't care much about these headers that only concern the ftrace ring-buffer. We don't use them from perf. Just skip this part of perf.data, but don't remove it from recording to stay compatible with olders perf.data Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Stephane Eranian <eranian@google.com> Cc: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/trace-event-parse.c89
-rw-r--r--tools/perf/util/trace-event-read.c12
-rw-r--r--tools/perf/util/trace-event.h1
3 files changed, 7 insertions, 95 deletions
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index d6ef414075a6..069f261b225c 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -691,11 +691,6 @@ static int __read_expected(enum event_type expect, const char *str,
691 return ret; 691 return ret;
692} 692}
693 693
694static int read_expected_warn(enum event_type expect, const char *str, bool warn)
695{
696 return __read_expected(expect, str, 1, warn);
697}
698
699static int read_expected(enum event_type expect, const char *str) 694static int read_expected(enum event_type expect, const char *str)
700{ 695{
701 return __read_expected(expect, str, 1, true); 696 return __read_expected(expect, str, 1, true);
@@ -3104,90 +3099,6 @@ static void print_args(struct print_arg *args)
3104 } 3099 }
3105} 3100}
3106 3101
3107static void parse_header_field(const char *field,
3108 int *offset, int *size, bool warn)
3109{
3110 char *token;
3111 int type;
3112
3113 if (read_expected(EVENT_ITEM, "field") < 0)
3114 return;
3115 if (read_expected(EVENT_OP, ":") < 0)
3116 return;
3117
3118 /* type */
3119 if (read_expect_type(EVENT_ITEM, &token) < 0)
3120 goto fail;
3121 free_token(token);
3122
3123 if (read_expected_warn(EVENT_ITEM, field, warn) < 0)
3124 return;
3125 if (read_expected(EVENT_OP, ";") < 0)
3126 return;
3127 if (read_expected(EVENT_ITEM, "offset") < 0)
3128 return;
3129 if (read_expected(EVENT_OP, ":") < 0)
3130 return;
3131 if (read_expect_type(EVENT_ITEM, &token) < 0)
3132 goto fail;
3133 *offset = atoi(token);
3134 free_token(token);
3135 if (read_expected(EVENT_OP, ";") < 0)
3136 return;
3137 if (read_expected(EVENT_ITEM, "size") < 0)
3138 return;
3139 if (read_expected(EVENT_OP, ":") < 0)
3140 return;
3141 if (read_expect_type(EVENT_ITEM, &token) < 0)
3142 goto fail;
3143 *size = atoi(token);
3144 free_token(token);
3145 if (read_expected(EVENT_OP, ";") < 0)
3146 return;
3147 type = read_token(&token);
3148 if (type != EVENT_NEWLINE) {
3149 /* newer versions of the kernel have a "signed" type */
3150 if (type != EVENT_ITEM)
3151 goto fail;
3152
3153 if (strcmp(token, "signed") != 0)
3154 goto fail;
3155
3156 free_token(token);
3157
3158 if (read_expected(EVENT_OP, ":") < 0)
3159 return;
3160
3161 if (read_expect_type(EVENT_ITEM, &token))
3162 goto fail;
3163
3164 free_token(token);
3165 if (read_expected(EVENT_OP, ";") < 0)
3166 return;
3167
3168 if (read_expect_type(EVENT_NEWLINE, &token))
3169 goto fail;
3170 }
3171 fail:
3172 free_token(token);
3173}
3174
3175int parse_header_page(char *buf, unsigned long size)
3176{
3177 init_input_buf(buf, size);
3178
3179 parse_header_field("timestamp", &header_page_ts_offset,
3180 &header_page_ts_size, true);
3181 parse_header_field("commit", &header_page_size_offset,
3182 &header_page_size_size, true);
3183 parse_header_field("overwrite", &header_page_overwrite_offset,
3184 &header_page_overwrite_size, false);
3185 parse_header_field("data", &header_page_data_offset,
3186 &header_page_data_size, true);
3187
3188 return 0;
3189}
3190
3191int parse_ftrace_file(char *buf, unsigned long size) 3102int parse_ftrace_file(char *buf, unsigned long size)
3192{ 3103{
3193 struct format_field *field; 3104 struct format_field *field;
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index 44889c9b5630..46066391288a 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -52,6 +52,12 @@ static unsigned long page_size;
52 52
53static ssize_t calc_data_size; 53static ssize_t calc_data_size;
54 54
55/* If it fails, the next read will report it */
56static void skip(int size)
57{
58 lseek(input_fd, size, SEEK_CUR);
59}
60
55static int do_read(int fd, void *buf, int size) 61static int do_read(int fd, void *buf, int size)
56{ 62{
57 int rsize = size; 63 int rsize = size;
@@ -169,7 +175,6 @@ static void read_ftrace_printk(void)
169static void read_header_files(void) 175static void read_header_files(void)
170{ 176{
171 unsigned long long size; 177 unsigned long long size;
172 char *header_page;
173 char *header_event; 178 char *header_event;
174 char buf[BUFSIZ]; 179 char buf[BUFSIZ];
175 180
@@ -179,10 +184,7 @@ static void read_header_files(void)
179 die("did not read header page"); 184 die("did not read header page");
180 185
181 size = read8(); 186 size = read8();
182 header_page = malloc_or_die(size); 187 skip(size);
183 read_or_die(header_page, size);
184 parse_header_page(header_page, size);
185 free(header_page);
186 188
187 /* 189 /*
188 * The size field in the page is of type long, 190 * The size field in the page is of type long,
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 1f45d468fd9a..4e1acc31ebaa 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -244,7 +244,6 @@ extern int header_page_data_size;
244 244
245extern bool latency_format; 245extern bool latency_format;
246 246
247int parse_header_page(char *buf, unsigned long size);
248int trace_parse_common_type(void *data); 247int trace_parse_common_type(void *data);
249int trace_parse_common_pid(void *data); 248int trace_parse_common_pid(void *data);
250int parse_common_pc(void *data); 249int parse_common_pc(void *data);