aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Hart <dvhart@linux.intel.com>2011-01-04 15:43:38 -0500
committerSteven Rostedt <rostedt@goodmis.org>2011-01-04 20:23:16 -0500
commit6bfc042cbfa9fe19ffe014531cfe135bc3c0da55 (patch)
treecb1347e51c46480d7c70b1b46225803846535401
parentf1b412402cff36987736748c150bd5c90dd5300b (diff)
trace-cmd: Move *_tracing_file into trace-util.c
Make tracecmd_(get|put)_tracing_file available to shared objects, such the python ctracecmd.so module generated by the SWIG mechanism. Signed-off-by: Darren Hart <dvhart@linux.intel.com> LKML-Reference: <1294173820-7043-2-git-send-email-dvhart@linux.intel.com> CC: Tom Zanussi <tom.zanussi@intel.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-cmd.c111
-rw-r--r--trace-util.c24
2 files changed, 61 insertions, 74 deletions
diff --git a/trace-cmd.c b/trace-cmd.c
index f54af18..5055db6 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -55,19 +55,6 @@
55int silence_warnings; 55int silence_warnings;
56int show_status; 56int show_status;
57 57
58static char *get_tracing_file(const char *name);
59static void put_tracing_file(char *file);
60
61char *tracecmd_get_tracing_file(const char *name)
62{
63 return get_tracing_file(name);
64}
65
66void tracecmd_put_tracing_file(char *name)
67{
68 put_tracing_file(name);
69}
70
71static int tracing_on_init_val; 58static int tracing_on_init_val;
72 59
73static int rt_prio; 60static int rt_prio;
@@ -306,11 +293,11 @@ static void clear_trace(void)
306 char *path; 293 char *path;
307 294
308 /* reset the trace */ 295 /* reset the trace */
309 path = get_tracing_file("trace"); 296 path = tracecmd_get_tracing_file("trace");
310 fp = fopen(path, "w"); 297 fp = fopen(path, "w");
311 if (!fp) 298 if (!fp)
312 die("writing to '%s'", path); 299 die("writing to '%s'", path);
313 put_tracing_file(path); 300 tracecmd_put_tracing_file(path);
314 fwrite("0", 1, 1, fp); 301 fwrite("0", 1, 1, fp);
315 fclose(fp); 302 fclose(fp);
316} 303}
@@ -321,11 +308,11 @@ static void reset_max_latency(void)
321 char *path; 308 char *path;
322 309
323 /* reset the trace */ 310 /* reset the trace */
324 path = get_tracing_file("tracing_max_latency"); 311 path = tracecmd_get_tracing_file("tracing_max_latency");
325 fp = fopen(path, "w"); 312 fp = fopen(path, "w");
326 if (!fp) 313 if (!fp)
327 die("writing to '%s'", path); 314 die("writing to '%s'", path);
328 put_tracing_file(path); 315 tracecmd_put_tracing_file(path);
329 fwrite("0", 1, 1, fp); 316 fwrite("0", 1, 1, fp);
330 fclose(fp); 317 fclose(fp);
331} 318}
@@ -336,7 +323,7 @@ static void update_ftrace_pid(const char *pid)
336 int ret; 323 int ret;
337 int fd; 324 int fd;
338 325
339 path = get_tracing_file("set_ftrace_pid"); 326 path = tracecmd_get_tracing_file("set_ftrace_pid");
340 if (!path) 327 if (!path)
341 return; 328 return;
342 329
@@ -400,30 +387,6 @@ void run_cmd(int argc, char **argv)
400 waitpid(pid, &status, 0); 387 waitpid(pid, &status, 0);
401} 388}
402 389
403static char *get_tracing_file(const char *name)
404{
405 static const char *tracing;
406 char *file;
407
408 if (!tracing) {
409 tracing = tracecmd_find_tracing_dir();
410 if (!tracing)
411 die("Can't find tracing dir");
412 }
413
414 file = malloc_or_die(strlen(tracing) + strlen(name) + 2);
415 if (!file)
416 return NULL;
417
418 sprintf(file, "%s/%s", tracing, name);
419 return file;
420}
421
422static void put_tracing_file(char *file)
423{
424 free(file);
425}
426
427static void show_events(void) 390static void show_events(void)
428{ 391{
429 char buf[BUFSIZ]; 392 char buf[BUFSIZ];
@@ -431,11 +394,11 @@ static void show_events(void)
431 FILE *fp; 394 FILE *fp;
432 size_t n; 395 size_t n;
433 396
434 path = get_tracing_file("available_events"); 397 path = tracecmd_get_tracing_file("available_events");
435 fp = fopen(path, "r"); 398 fp = fopen(path, "r");
436 if (!fp) 399 if (!fp)
437 die("reading %s", path); 400 die("reading %s", path);
438 put_tracing_file(path); 401 tracecmd_put_tracing_file(path);
439 402
440 do { 403 do {
441 n = fread(buf, 1, BUFSIZ, fp); 404 n = fread(buf, 1, BUFSIZ, fp);
@@ -452,11 +415,11 @@ static void show_plugins(void)
452 FILE *fp; 415 FILE *fp;
453 size_t n; 416 size_t n;
454 417
455 path = get_tracing_file("available_tracers"); 418 path = tracecmd_get_tracing_file("available_tracers");
456 fp = fopen(path, "r"); 419 fp = fopen(path, "r");
457 if (!fp) 420 if (!fp)
458 die("reading %s", path); 421 die("reading %s", path);
459 put_tracing_file(path); 422 tracecmd_put_tracing_file(path);
460 423
461 do { 424 do {
462 n = fread(buf, 1, BUFSIZ, fp); 425 n = fread(buf, 1, BUFSIZ, fp);
@@ -471,11 +434,11 @@ static void set_plugin(const char *name)
471 FILE *fp; 434 FILE *fp;
472 char *path; 435 char *path;
473 436
474 path = get_tracing_file("current_tracer"); 437 path = tracecmd_get_tracing_file("current_tracer");
475 fp = fopen(path, "w"); 438 fp = fopen(path, "w");
476 if (!fp) 439 if (!fp)
477 die("writing to '%s'", path); 440 die("writing to '%s'", path);
478 put_tracing_file(path); 441 tracecmd_put_tracing_file(path);
479 442
480 fwrite(name, 1, strlen(name), fp); 443 fwrite(name, 1, strlen(name), fp);
481 fclose(fp); 444 fclose(fp);
@@ -488,11 +451,11 @@ static void show_options(void)
488 FILE *fp; 451 FILE *fp;
489 size_t n; 452 size_t n;
490 453
491 path = get_tracing_file("trace_options"); 454 path = tracecmd_get_tracing_file("trace_options");
492 fp = fopen(path, "r"); 455 fp = fopen(path, "r");
493 if (!fp) 456 if (!fp)
494 die("reading %s", path); 457 die("reading %s", path);
495 put_tracing_file(path); 458 tracecmd_put_tracing_file(path);
496 459
497 do { 460 do {
498 n = fread(buf, 1, BUFSIZ, fp); 461 n = fread(buf, 1, BUFSIZ, fp);
@@ -517,11 +480,11 @@ static void set_option(const char *option)
517 FILE *fp; 480 FILE *fp;
518 char *path; 481 char *path;
519 482
520 path = get_tracing_file("trace_options"); 483 path = tracecmd_get_tracing_file("trace_options");
521 fp = fopen(path, "w"); 484 fp = fopen(path, "w");
522 if (!fp) 485 if (!fp)
523 die("writing to '%s'", path); 486 die("writing to '%s'", path);
524 put_tracing_file(path); 487 tracecmd_put_tracing_file(path);
525 488
526 fwrite(option, 1, strlen(option), fp); 489 fwrite(option, 1, strlen(option), fp);
527 fclose(fp); 490 fclose(fp);
@@ -549,11 +512,11 @@ static void old_update_events(const char *name, char update)
549 name = "*:*"; 512 name = "*:*";
550 513
551 /* need to use old way */ 514 /* need to use old way */
552 path = get_tracing_file("set_event"); 515 path = tracecmd_get_tracing_file("set_event");
553 fp = fopen(path, "w"); 516 fp = fopen(path, "w");
554 if (!fp) 517 if (!fp)
555 die("opening '%s'", path); 518 die("opening '%s'", path);
556 put_tracing_file(path); 519 tracecmd_put_tracing_file(path);
557 520
558 /* Disable the event with "!" */ 521 /* Disable the event with "!" */
559 if (update == '0') 522 if (update == '0')
@@ -612,13 +575,13 @@ static int update_glob(const char *name, const char *filter,
612 len = strlen(name) + strlen("events//enable") + 1; 575 len = strlen(name) + strlen("events//enable") + 1;
613 str = malloc_or_die(len); 576 str = malloc_or_die(len);
614 snprintf(str, len, "events/%s/enable", name); 577 snprintf(str, len, "events/%s/enable", name);
615 path = get_tracing_file(str); 578 path = tracecmd_get_tracing_file(str);
616 free(str); 579 free(str);
617 580
618 globbuf.gl_offs = 0; 581 globbuf.gl_offs = 0;
619 printf("path = %s\n", path); 582 printf("path = %s\n", path);
620 ret = glob(path, GLOB_ONLYDIR, NULL, &globbuf); 583 ret = glob(path, GLOB_ONLYDIR, NULL, &globbuf);
621 put_tracing_file(path); 584 tracecmd_put_tracing_file(path);
622 if (ret < 0) 585 if (ret < 0)
623 return 0; 586 return 0;
624 587
@@ -661,11 +624,11 @@ static void filter_all_systems(const char *filter)
661 int ret; 624 int ret;
662 int i; 625 int i;
663 626
664 path = get_tracing_file("events/*/filter"); 627 path = tracecmd_get_tracing_file("events/*/filter");
665 628
666 globbuf.gl_offs = 0; 629 globbuf.gl_offs = 0;
667 ret = glob(path, 0, NULL, &globbuf); 630 ret = glob(path, 0, NULL, &globbuf);
668 put_tracing_file(path); 631 tracecmd_put_tracing_file(path);
669 if (ret < 0) 632 if (ret < 0)
670 die("No filters found"); 633 die("No filters found");
671 634
@@ -690,12 +653,12 @@ static void update_event(const char *name, const char *filter,
690 int ret2; 653 int ret2;
691 654
692 /* Check if the kernel has the events/enable file */ 655 /* Check if the kernel has the events/enable file */
693 path = get_tracing_file("events/enable"); 656 path = tracecmd_get_tracing_file("events/enable");
694 ret = stat(path, &st); 657 ret = stat(path, &st);
695 if (ret < 0) { 658 if (ret < 0) {
696 if (filter_only) 659 if (filter_only)
697 return; 660 return;
698 put_tracing_file(path); 661 tracecmd_put_tracing_file(path);
699 /* old kernel */ 662 /* old kernel */
700 old_update_events(name, update); 663 old_update_events(name, update);
701 return; 664 return;
@@ -714,14 +677,14 @@ static void update_event(const char *name, const char *filter,
714 filter_all_systems("0"); 677 filter_all_systems("0");
715 678
716 if (filter_only) { 679 if (filter_only) {
717 put_tracing_file(path); 680 tracecmd_put_tracing_file(path);
718 return; 681 return;
719 } 682 }
720 683
721 fp = fopen(path, "w"); 684 fp = fopen(path, "w");
722 if (!fp) 685 if (!fp)
723 die("writing to '%s'", path); 686 die("writing to '%s'", path);
724 put_tracing_file(path); 687 tracecmd_put_tracing_file(path);
725 ret = fwrite(&update, 1, 1, fp); 688 ret = fwrite(&update, 1, 1, fp);
726 fclose(fp); 689 fclose(fp);
727 if (ret < 0) 690 if (ret < 0)
@@ -741,7 +704,7 @@ static void update_event(const char *name, const char *filter,
741 if (!strlen(ptr) || strcmp(ptr, "*") == 0) { 704 if (!strlen(ptr) || strcmp(ptr, "*") == 0) {
742 ret = update_glob(str, filter, filter_only, update); 705 ret = update_glob(str, filter, filter_only, update);
743 free(str); 706 free(str);
744 put_tracing_file(path); 707 tracecmd_put_tracing_file(path);
745 if (!ret) 708 if (!ret)
746 goto fail; 709 goto fail;
747 return; 710 return;
@@ -786,9 +749,9 @@ static void check_tracing_enabled(void)
786 char *path; 749 char *path;
787 750
788 if (fd < 0) { 751 if (fd < 0) {
789 path = get_tracing_file("tracing_enabled"); 752 path = tracecmd_get_tracing_file("tracing_enabled");
790 fd = open(path, O_WRONLY); 753 fd = open(path, O_WRONLY);
791 put_tracing_file(path); 754 tracecmd_put_tracing_file(path);
792 755
793 if (fd < 0) 756 if (fd < 0)
794 return; 757 return;
@@ -806,11 +769,11 @@ static int open_tracing_on(void)
806 if (fd >= 0) 769 if (fd >= 0)
807 return fd; 770 return fd;
808 771
809 path = get_tracing_file("tracing_on"); 772 path = tracecmd_get_tracing_file("tracing_on");
810 fd = open(path, O_RDWR); 773 fd = open(path, O_RDWR);
811 if (fd < 0) 774 if (fd < 0)
812 die("opening '%s'", path); 775 die("opening '%s'", path);
813 put_tracing_file(path); 776 tracecmd_put_tracing_file(path);
814 tracing_on_fd = fd; 777 tracing_on_fd = fd;
815 778
816 return fd; 779 return fd;
@@ -893,7 +856,7 @@ static void update_filter(const char *event_name, const char *field,
893 strlen("events//filter") + 1); 856 strlen("events//filter") + 1);
894 sprintf(filter_name, "events/%s/filter", event_name); 857 sprintf(filter_name, "events/%s/filter", event_name);
895 858
896 path = get_tracing_file(filter_name); 859 path = tracecmd_get_tracing_file(filter_name);
897 free(filter_name); 860 free(filter_name);
898 861
899 /* Ignore if file does not exist */ 862 /* Ignore if file does not exist */
@@ -929,7 +892,7 @@ static void update_filter(const char *event_name, const char *field,
929 free(filter); 892 free(filter);
930 893
931 out: 894 out:
932 put_tracing_file(path); 895 tracecmd_put_tracing_file(path);
933} 896}
934 897
935static void update_pid_event_filters(const char *pid) 898static void update_pid_event_filters(const char *pid)
@@ -1323,7 +1286,7 @@ static int trace_empty(void)
1323 * that is without a '#' the trace is not empty. 1286 * that is without a '#' the trace is not empty.
1324 * Otherwise it is. 1287 * Otherwise it is.
1325 */ 1288 */
1326 path = get_tracing_file("trace"); 1289 path = tracecmd_get_tracing_file("trace");
1327 fp = fopen(path, "r"); 1290 fp = fopen(path, "r");
1328 if (!fp) 1291 if (!fp)
1329 die("reading '%s'", path); 1292 die("reading '%s'", path);
@@ -1336,7 +1299,7 @@ static int trace_empty(void)
1336 } 1299 }
1337 } while (line && n > 0); 1300 } while (line && n > 0);
1338 1301
1339 put_tracing_file(path); 1302 tracecmd_put_tracing_file(path);
1340 1303
1341 fclose(fp); 1304 fclose(fp);
1342 1305
@@ -1349,7 +1312,7 @@ static void write_func_file(const char *file, struct func_list **list)
1349 char *path; 1312 char *path;
1350 int fd; 1313 int fd;
1351 1314
1352 path = get_tracing_file(file); 1315 path = tracecmd_get_tracing_file(file);
1353 1316
1354 fd = open(path, O_WRONLY | O_TRUNC); 1317 fd = open(path, O_WRONLY | O_TRUNC);
1355 if (fd < 0) 1318 if (fd < 0)
@@ -1365,7 +1328,7 @@ static void write_func_file(const char *file, struct func_list **list)
1365 close(fd); 1328 close(fd);
1366 1329
1367 free: 1330 free:
1368 put_tracing_file(path); 1331 tracecmd_put_tracing_file(path);
1369} 1332}
1370 1333
1371static void set_funcs(void) 1334static void set_funcs(void)
@@ -1400,7 +1363,7 @@ void set_buffer_size(void)
1400 1363
1401 snprintf(buf, BUFSIZ, "%d", buffer_size); 1364 snprintf(buf, BUFSIZ, "%d", buffer_size);
1402 1365
1403 path = get_tracing_file("buffer_size_kb"); 1366 path = tracecmd_get_tracing_file("buffer_size_kb");
1404 fd = open(path, O_WRONLY); 1367 fd = open(path, O_WRONLY);
1405 if (fd < 0) 1368 if (fd < 0)
1406 die("can't open %s", path); 1369 die("can't open %s", path);
diff --git a/trace-util.c b/trace-util.c
index 9e0ceca..970e6bc 100644
--- a/trace-util.c
+++ b/trace-util.c
@@ -830,3 +830,27 @@ void tracecmd_unload_plugins(struct plugin_list *plugin_list)
830 free(list); 830 free(list);
831 } 831 }
832} 832}
833
834char *tracecmd_get_tracing_file(const char *name)
835{
836 static const char *tracing;
837 char *file;
838
839 if (!tracing) {
840 tracing = tracecmd_find_tracing_dir();
841 if (!tracing)
842 die("Can't find tracing dir");
843 }
844
845 file = malloc_or_die(strlen(tracing) + strlen(name) + 2);
846 if (!file)
847 return NULL;
848
849 sprintf(file, "%s/%s", tracing, name);
850 return file;
851}
852
853void tracecmd_put_tracing_file(char *name)
854{
855 free(name);
856}