aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2016-02-08 06:19:35 -0500
committerBjoern Brandenburg <bbb@mpi-sws.org>2016-03-08 11:01:07 -0500
commitfefbdbf294bb3ee67957c84603806c1d132b19bb (patch)
treeb1a3301f4c237531cfcb45aa3db295b601a1ebfc
parent017b98154f755a5e3c7fd6299e741f7858b55147 (diff)
ft2csv: add -l (list IDs in trace) option
Use ft2csv -l <MY-TRACE-FILE> to get a list of all present events.
-rw-r--r--src/ft2csv.c62
1 files changed, 52 insertions, 10 deletions
diff --git a/src/ft2csv.c b/src/ft2csv.c
index 6a0402d..162db9a 100644
--- a/src/ft2csv.c
+++ b/src/ft2csv.c
@@ -368,6 +368,24 @@ static void show_single_records(struct timestamp* start, struct timestamp* end,
368 show_single(start); 368 show_single(start);
369} 369}
370 370
371static void list_ids(struct timestamp* start, struct timestamp* end)
372{
373 unsigned int already_seen[256] = {0};
374 const char *name;
375
376 for (; start != end; start++)
377 if (!already_seen[start->event])
378 {
379 already_seen[start->event] = 1;
380 name = event2str(start->event);
381 if (name)
382 printf("%s\n", name);
383 else
384 printf("%d\n", start->event);
385 }
386}
387
388
371#define USAGE \ 389#define USAGE \
372 "Usage: ft2csv [-r] [-i] [-b] [-a CPU] [-o CPU] <event_name> <logfile> \n" \ 390 "Usage: ft2csv [-r] [-i] [-b] [-a CPU] [-o CPU] <event_name> <logfile> \n" \
373 " -i: ignore interleaved -- ignore samples if start " \ 391 " -i: ignore interleaved -- ignore samples if start " \
@@ -376,7 +394,9 @@ static void show_single_records(struct timestamp* start, struct timestamp* end,
376 " -r: raw binary format -- don't produce .csv output \n" \ 394 " -r: raw binary format -- don't produce .csv output \n" \
377 " -a: avoid CPU -- skip samples from a specific CPU\n" \ 395 " -a: avoid CPU -- skip samples from a specific CPU\n" \
378 " -o: only CPU -- skip all samples from other CPUs\n" \ 396 " -o: only CPU -- skip all samples from other CPUs\n" \
379 " -x: allow interrupts -- don't skip samples with IRQ-happned flag \n" \ 397 " -x: allow interrupts -- don't skip samples with IRQ-happned flag\n" \
398 " -l: list events -- list the events present in the file\n" \
399 " -h: help -- show this help message\n" \
380 "" 400 ""
381 401
382static void die(char* msg) 402static void die(char* msg)
@@ -388,7 +408,7 @@ static void die(char* msg)
388 exit(1); 408 exit(1);
389} 409}
390 410
391#define OPTS "ibra:o:pex" 411#define OPTS "ibra:o:pexhl"
392 412
393int main(int argc, char** argv) 413int main(int argc, char** argv)
394{ 414{
@@ -398,6 +418,7 @@ int main(int argc, char** argv)
398 cmd_t id; 418 cmd_t id;
399 int opt; 419 int opt;
400 char event_name[80]; 420 char event_name[80];
421 int list_events = 0;
401 422
402 while ((opt = getopt(argc, argv, OPTS)) != -1) { 423 while ((opt = getopt(argc, argv, OPTS)) != -1) {
403 switch (opt) { 424 switch (opt) {
@@ -437,16 +458,41 @@ int main(int argc, char** argv)
437 find_by_pid = 0; 458 find_by_pid = 0;
438 fprintf(stderr, "Matching timestamp pairs based on event ID.\n"); 459 fprintf(stderr, "Matching timestamp pairs based on event ID.\n");
439 break; 460 break;
461 case 'l':
462 list_events = 1;
463 break;
464 case 'h':
465 errno = 0;
466 die("");
467 break;
440 default: 468 default:
441 die("Unknown option."); 469 die("Unknown option.");
442 break; 470 break;
443 } 471 }
444 } 472 }
445 473
446 if (argc - optind != 2) 474
447 die("arguments missing"); 475 if (list_events) {
448 if (map_file(argv[optind + 1], &mapped, &size)) 476 /* no event ID specified */
449 die("could not map file"); 477 if (argc - optind != 1)
478 die("arguments missing");
479 if (map_file(argv[optind], &mapped, &size))
480 die("could not map file");
481 } else {
482 if (argc - optind != 2)
483 die("arguments missing");
484 if (map_file(argv[optind + 1], &mapped, &size))
485 die("could not map file");
486 }
487
488 ts = (struct timestamp*) mapped;
489 count = size / sizeof(struct timestamp);
490 end = ts + count;
491
492 if (list_events) {
493 list_ids(ts, end);
494 return 0;
495 }
450 496
451 if (!str2event(argv[optind], &id)) { 497 if (!str2event(argv[optind], &id)) {
452 /* see if it is a short name */ 498 /* see if it is a short name */
@@ -459,10 +505,6 @@ int main(int argc, char** argv)
459 if (find_by_pid == AUTO_SELECT) 505 if (find_by_pid == AUTO_SELECT)
460 find_by_pid = id <= PID_RECORDS_RANGE; 506 find_by_pid = id <= PID_RECORDS_RANGE;
461 507
462 ts = (struct timestamp*) mapped;
463 count = size / sizeof(struct timestamp);
464 end = ts + count;
465
466 if (id >= SINGLE_RECORDS_RANGE) 508 if (id >= SINGLE_RECORDS_RANGE)
467 show_single_records(ts, end, id); 509 show_single_records(ts, end, id);
468 else 510 else