aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-record.c4
-rw-r--r--tools/perf/util/parse-events.c47
-rw-r--r--tools/perf/util/parse-events.h13
-rw-r--r--tools/perf/util/trace-event-info.c72
-rw-r--r--tools/perf/util/trace-event-parse.c1
-rw-r--r--tools/perf/util/trace-event-read.c1
-rw-r--r--tools/perf/util/trace-event.h9
7 files changed, 120 insertions, 27 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index acbe59444385..add514d53d2e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -549,11 +549,11 @@ static int __cmd_record(int argc, const char **argv)
549 549
550 550
551 if (raw_samples) { 551 if (raw_samples) {
552 read_tracing_data(); 552 read_tracing_data(attrs, nr_counters);
553 } else { 553 } else {
554 for (i = 0; i < nr_counters; i++) { 554 for (i = 0; i < nr_counters; i++) {
555 if (attrs[i].sample_type & PERF_SAMPLE_RAW) { 555 if (attrs[i].sample_type & PERF_SAMPLE_RAW) {
556 read_tracing_data(); 556 read_tracing_data(attrs, nr_counters);
557 break; 557 break;
558 } 558 }
559 } 559 }
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 1cda97b39118..89d46c99bc9c 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -158,9 +158,9 @@ int valid_debugfs_mount(const char *debugfs)
158 return 0; 158 return 0;
159} 159}
160 160
161static const char *tracepoint_id_to_name(u64 config) 161struct tracepoint_path *tracepoint_id_to_path(u64 config)
162{ 162{
163 static char tracepoint_name[2 * MAX_EVENT_LENGTH]; 163 struct tracepoint_path *path = NULL;
164 DIR *sys_dir, *evt_dir; 164 DIR *sys_dir, *evt_dir;
165 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; 165 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
166 struct stat st; 166 struct stat st;
@@ -170,7 +170,7 @@ static const char *tracepoint_id_to_name(u64 config)
170 char evt_path[MAXPATHLEN]; 170 char evt_path[MAXPATHLEN];
171 171
172 if (valid_debugfs_mount(debugfs_path)) 172 if (valid_debugfs_mount(debugfs_path))
173 return "unkown"; 173 return NULL;
174 174
175 sys_dir = opendir(debugfs_path); 175 sys_dir = opendir(debugfs_path);
176 if (!sys_dir) 176 if (!sys_dir)
@@ -197,10 +197,23 @@ static const char *tracepoint_id_to_name(u64 config)
197 if (id == config) { 197 if (id == config) {
198 closedir(evt_dir); 198 closedir(evt_dir);
199 closedir(sys_dir); 199 closedir(sys_dir);
200 snprintf(tracepoint_name, 2 * MAX_EVENT_LENGTH, 200 path = calloc(1, sizeof(path));
201 "%s:%s", sys_dirent.d_name, 201 path->system = malloc(MAX_EVENT_LENGTH);
202 evt_dirent.d_name); 202 if (!path->system) {
203 return tracepoint_name; 203 free(path);
204 return NULL;
205 }
206 path->name = malloc(MAX_EVENT_LENGTH);
207 if (!path->name) {
208 free(path->system);
209 free(path);
210 return NULL;
211 }
212 strncpy(path->system, sys_dirent.d_name,
213 MAX_EVENT_LENGTH);
214 strncpy(path->name, evt_dirent.d_name,
215 MAX_EVENT_LENGTH);
216 return path;
204 } 217 }
205 } 218 }
206 closedir(evt_dir); 219 closedir(evt_dir);
@@ -208,7 +221,25 @@ static const char *tracepoint_id_to_name(u64 config)
208 221
209cleanup: 222cleanup:
210 closedir(sys_dir); 223 closedir(sys_dir);
211 return "unkown"; 224 return NULL;
225}
226
227#define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
228static const char *tracepoint_id_to_name(u64 config)
229{
230 static char buf[TP_PATH_LEN];
231 struct tracepoint_path *path;
232
233 path = tracepoint_id_to_path(config);
234 if (path) {
235 snprintf(buf, TP_PATH_LEN, "%s:%s", path->system, path->name);
236 free(path->name);
237 free(path->system);
238 free(path);
239 } else
240 snprintf(buf, TP_PATH_LEN, "%s:%s", "unknown", "unknown");
241
242 return buf;
212} 243}
213 244
214static int is_cache_op_valid(u8 cache_type, u8 cache_op) 245static int is_cache_op_valid(u8 cache_type, u8 cache_op)
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 9b1aeea01636..60704c15961f 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -1,10 +1,19 @@
1 1#ifndef _PARSE_EVENTS_H
2#define _PARSE_EVENTS_H
2/* 3/*
3 * Parse symbolic events/counts passed in as options: 4 * Parse symbolic events/counts passed in as options:
4 */ 5 */
5 6
6struct option; 7struct option;
7 8
9struct tracepoint_path {
10 char *system;
11 char *name;
12 struct tracepoint_path *next;
13};
14
15extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
16
8extern int nr_counters; 17extern int nr_counters;
9 18
10extern struct perf_counter_attr attrs[MAX_COUNTERS]; 19extern struct perf_counter_attr attrs[MAX_COUNTERS];
@@ -21,3 +30,5 @@ extern void print_events(void);
21extern char debugfs_path[]; 30extern char debugfs_path[];
22extern int valid_debugfs_mount(const char *debugfs); 31extern int valid_debugfs_mount(const char *debugfs);
23 32
33
34#endif /* _PARSE_EVENTS_H */
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index 78adff189bba..81615279b876 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -32,7 +32,9 @@
32#include <unistd.h> 32#include <unistd.h>
33#include <ctype.h> 33#include <ctype.h>
34#include <errno.h> 34#include <errno.h>
35#include <stdbool.h>
35 36
37#include "../perf.h"
36#include "trace-event.h" 38#include "trace-event.h"
37 39
38 40
@@ -289,7 +291,18 @@ static void read_header_files(void)
289 put_tracing_file(path); 291 put_tracing_file(path);
290} 292}
291 293
292static void copy_event_system(const char *sys) 294static bool name_in_tp_list(char *sys, struct tracepoint_path *tps)
295{
296 while (tps) {
297 if (!strcmp(sys, tps->name))
298 return true;
299 tps = tps->next;
300 }
301
302 return false;
303}
304
305static void copy_event_system(const char *sys, struct tracepoint_path *tps)
293{ 306{
294 unsigned long long size, check_size; 307 unsigned long long size, check_size;
295 struct dirent *dent; 308 struct dirent *dent;
@@ -305,7 +318,8 @@ static void copy_event_system(const char *sys)
305 318
306 while ((dent = readdir(dir))) { 319 while ((dent = readdir(dir))) {
307 if (strcmp(dent->d_name, ".") == 0 || 320 if (strcmp(dent->d_name, ".") == 0 ||
308 strcmp(dent->d_name, "..") == 0) 321 strcmp(dent->d_name, "..") == 0 ||
322 !name_in_tp_list(dent->d_name, tps))
309 continue; 323 continue;
310 format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10); 324 format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10);
311 sprintf(format, "%s/%s/format", sys, dent->d_name); 325 sprintf(format, "%s/%s/format", sys, dent->d_name);
@@ -321,7 +335,8 @@ static void copy_event_system(const char *sys)
321 rewinddir(dir); 335 rewinddir(dir);
322 while ((dent = readdir(dir))) { 336 while ((dent = readdir(dir))) {
323 if (strcmp(dent->d_name, ".") == 0 || 337 if (strcmp(dent->d_name, ".") == 0 ||
324 strcmp(dent->d_name, "..") == 0) 338 strcmp(dent->d_name, "..") == 0 ||
339 !name_in_tp_list(dent->d_name, tps))
325 continue; 340 continue;
326 format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10); 341 format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10);
327 sprintf(format, "%s/%s/format", sys, dent->d_name); 342 sprintf(format, "%s/%s/format", sys, dent->d_name);
@@ -340,18 +355,29 @@ static void copy_event_system(const char *sys)
340 } 355 }
341} 356}
342 357
343static void read_ftrace_files(void) 358static void read_ftrace_files(struct tracepoint_path *tps)
344{ 359{
345 char *path; 360 char *path;
346 361
347 path = get_tracing_file("events/ftrace"); 362 path = get_tracing_file("events/ftrace");
348 363
349 copy_event_system(path); 364 copy_event_system(path, tps);
350 365
351 put_tracing_file(path); 366 put_tracing_file(path);
352} 367}
353 368
354static void read_event_files(void) 369static bool system_in_tp_list(char *sys, struct tracepoint_path *tps)
370{
371 while (tps) {
372 if (!strcmp(sys, tps->system))
373 return true;
374 tps = tps->next;
375 }
376
377 return false;
378}
379
380static void read_event_files(struct tracepoint_path *tps)
355{ 381{
356 struct dirent *dent; 382 struct dirent *dent;
357 struct stat st; 383 struct stat st;
@@ -370,7 +396,8 @@ static void read_event_files(void)
370 while ((dent = readdir(dir))) { 396 while ((dent = readdir(dir))) {
371 if (strcmp(dent->d_name, ".") == 0 || 397 if (strcmp(dent->d_name, ".") == 0 ||
372 strcmp(dent->d_name, "..") == 0 || 398 strcmp(dent->d_name, "..") == 0 ||
373 strcmp(dent->d_name, "ftrace") == 0) 399 strcmp(dent->d_name, "ftrace") == 0 ||
400 !system_in_tp_list(dent->d_name, tps))
374 continue; 401 continue;
375 sys = malloc_or_die(strlen(path) + strlen(dent->d_name) + 2); 402 sys = malloc_or_die(strlen(path) + strlen(dent->d_name) + 2);
376 sprintf(sys, "%s/%s", path, dent->d_name); 403 sprintf(sys, "%s/%s", path, dent->d_name);
@@ -388,7 +415,8 @@ static void read_event_files(void)
388 while ((dent = readdir(dir))) { 415 while ((dent = readdir(dir))) {
389 if (strcmp(dent->d_name, ".") == 0 || 416 if (strcmp(dent->d_name, ".") == 0 ||
390 strcmp(dent->d_name, "..") == 0 || 417 strcmp(dent->d_name, "..") == 0 ||
391 strcmp(dent->d_name, "ftrace") == 0) 418 strcmp(dent->d_name, "ftrace") == 0 ||
419 !system_in_tp_list(dent->d_name, tps))
392 continue; 420 continue;
393 sys = malloc_or_die(strlen(path) + strlen(dent->d_name) + 2); 421 sys = malloc_or_die(strlen(path) + strlen(dent->d_name) + 2);
394 sprintf(sys, "%s/%s", path, dent->d_name); 422 sprintf(sys, "%s/%s", path, dent->d_name);
@@ -396,7 +424,7 @@ static void read_event_files(void)
396 if (ret >= 0) { 424 if (ret >= 0) {
397 if (S_ISDIR(st.st_mode)) { 425 if (S_ISDIR(st.st_mode)) {
398 write_or_die(dent->d_name, strlen(dent->d_name) + 1); 426 write_or_die(dent->d_name, strlen(dent->d_name) + 1);
399 copy_event_system(sys); 427 copy_event_system(sys, tps);
400 } 428 }
401 } 429 }
402 free(sys); 430 free(sys);
@@ -450,9 +478,27 @@ static void read_ftrace_printk(void)
450 478
451} 479}
452 480
453void read_tracing_data(void) 481static struct tracepoint_path *
482get_tracepoints_path(struct perf_counter_attr *pattrs, int nb_counters)
483{
484 struct tracepoint_path path, *ppath = &path;
485 int i;
486
487 for (i = 0; i < nb_counters; i++) {
488 if (pattrs[i].type != PERF_TYPE_TRACEPOINT)
489 continue;
490 ppath->next = tracepoint_id_to_path(pattrs[i].config);
491 if (!ppath->next)
492 die("%s\n", "No memory to alloc tracepoints list");
493 ppath = ppath->next;
494 }
495
496 return path.next;
497}
498void read_tracing_data(struct perf_counter_attr *pattrs, int nb_counters)
454{ 499{
455 char buf[BUFSIZ]; 500 char buf[BUFSIZ];
501 struct tracepoint_path *tps;
456 502
457 output_fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); 503 output_fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644);
458 if (output_fd < 0) 504 if (output_fd < 0)
@@ -483,9 +529,11 @@ void read_tracing_data(void)
483 page_size = getpagesize(); 529 page_size = getpagesize();
484 write_or_die(&page_size, 4); 530 write_or_die(&page_size, 4);
485 531
532 tps = get_tracepoints_path(pattrs, nb_counters);
533
486 read_header_files(); 534 read_header_files();
487 read_ftrace_files(); 535 read_ftrace_files(tps);
488 read_event_files(); 536 read_event_files(tps);
489 read_proc_kallsyms(); 537 read_proc_kallsyms();
490 read_ftrace_printk(); 538 read_ftrace_printk();
491} 539}
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index b53b27f34e4e..a6577cdd9afd 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -29,6 +29,7 @@
29#include <errno.h> 29#include <errno.h>
30 30
31#undef _GNU_SOURCE 31#undef _GNU_SOURCE
32#include "../perf.h"
32#include "util.h" 33#include "util.h"
33#include "trace-event.h" 34#include "trace-event.h"
34 35
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index 1dac301ae54f..b12e4903739a 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -36,6 +36,7 @@
36#include <ctype.h> 36#include <ctype.h>
37#include <errno.h> 37#include <errno.h>
38 38
39#include "../perf.h"
39#include "util.h" 40#include "util.h"
40#include "trace-event.h" 41#include "trace-event.h"
41 42
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 3ddb8947be8a..051fcf363825 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -1,6 +1,7 @@
1#ifndef _PARSE_EVENTS_H 1#ifndef _TRACE_EVENTS_H
2#define _PARSE_EVENTS_H 2#define _TRACE_EVENTS_H
3 3
4#include "parse-events.h"
4 5
5#define __unused __attribute__((unused)) 6#define __unused __attribute__((unused))
6 7
@@ -233,6 +234,6 @@ extern int header_page_data_size;
233 234
234int parse_header_page(char *buf, unsigned long size); 235int parse_header_page(char *buf, unsigned long size);
235 236
236void read_tracing_data(void); 237void read_tracing_data(struct perf_counter_attr *pattrs, int nb_counters);
237 238
238#endif /* _PARSE_EVENTS_H */ 239#endif /* _TRACE_EVENTS_H */