aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2011-01-28 11:57:57 -0500
committerSteven Rostedt <rostedt@goodmis.org>2011-01-28 11:57:57 -0500
commitbcbd6328047704b2d7e1f5c0246f2dc47406d1cb (patch)
tree85a4a7a850dc5de8d6778714e474c38d32e39cc2
parent0d8c0ce5775fc3fa11170cfe560afae2ae9e50e2 (diff)
trace-cmd/restore: Allow override where debugfs/tracing and kallsyms come from
Add to trace-cmd restore: -t dir: where dir is the directory to search instead of looking at debugfs/tracing -k file: where to read kallsyms from, instead of reading /proc/kallsyms Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--Documentation/trace-cmd-restore.1.txt15
-rw-r--r--trace-cmd.h3
-rw-r--r--trace-output.c36
-rw-r--r--trace-restore.c13
4 files changed, 57 insertions, 10 deletions
diff --git a/Documentation/trace-cmd-restore.1.txt b/Documentation/trace-cmd-restore.1.txt
index 6fd6ba4..290b0ac 100644
--- a/Documentation/trace-cmd-restore.1.txt
+++ b/Documentation/trace-cmd-restore.1.txt
@@ -42,6 +42,21 @@ OPTIONS
42 'trace-partial.dat'. This is because the file is not a full version 42 'trace-partial.dat'. This is because the file is not a full version
43 of something that trace-cmd-report(1) could use. 43 of something that trace-cmd-report(1) could use.
44 44
45*-t* tracing_dir::
46 Used with *-c*, it overrides the location to read the events from.
47 By default, tracing information is read from the debugfs/tracing
48 directory. *-t* will use that location instead. This can be useful
49 if the trace.dat file to create is from another machine.
50 Just tar -cvf events.tar debugfs/tracing and copy and untar that
51 file locally, and use that directory instead.
52
53*-k* kallsyms::
54 Used with *-c*, it overrides where to read the kallsyms file from.
55 By default, /proc/kallsyms is used. *-k* will override the file to
56 read the kallsyms from. This can be useful if the trace.dat file
57 to create is from another machine. Just copy the /proc/kallsyms
58 file locally, and use *-k* to point to that file.
59
45*-o* output':: 60*-o* output'::
46 By default, trace-cmd restore will create a 'trace.dat' file 61 By default, trace-cmd restore will create a 'trace.dat' file
47 (or 'trace-partial.dat' if *-c* is specified). You can 62 (or 'trace-partial.dat' if *-c* is specified). You can
diff --git a/trace-cmd.h b/trace-cmd.h
index ec59e98..708d743 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -174,6 +174,9 @@ tracecmd_create_file_glob(const char *output_file,
174 struct tracecmd_event_list *event_globs); 174 struct tracecmd_event_list *event_globs);
175struct tracecmd_output *tracecmd_create_init_fd(int fd); 175struct tracecmd_output *tracecmd_create_init_fd(int fd);
176struct tracecmd_output *tracecmd_create_init_file(const char *output_file); 176struct tracecmd_output *tracecmd_create_init_file(const char *output_file);
177struct tracecmd_output *tracecmd_create_init_file_override(const char *output_file,
178 const char *tracing_dir,
179 const char *kallsyms);
177void tracecmd_output_close(struct tracecmd_output *handle); 180void tracecmd_output_close(struct tracecmd_output *handle);
178struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, 181struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle,
179 const char *file); 182 const char *file);
diff --git a/trace-output.c b/trace-output.c
index 8837aa0..26b0197 100644
--- a/trace-output.c
+++ b/trace-output.c
@@ -599,13 +599,17 @@ static int read_event_files(struct tracecmd_output *handle,
599 return ret; 599 return ret;
600} 600}
601 601
602static int read_proc_kallsyms(struct tracecmd_output *handle) 602static int read_proc_kallsyms(struct tracecmd_output *handle,
603 const char *kallsyms)
603{ 604{
604 unsigned int size, check_size, endian4; 605 unsigned int size, check_size, endian4;
605 const char *path = "/proc/kallsyms"; 606 const char *path = "/proc/kallsyms";
606 struct stat st; 607 struct stat st;
607 int ret; 608 int ret;
608 609
610 if (kallsyms)
611 path = kallsyms;
612
609 ret = stat(path, &st); 613 ret = stat(path, &st);
610 if (ret < 0) { 614 if (ret < 0) {
611 /* not found */ 615 /* not found */
@@ -665,6 +669,8 @@ static int read_ftrace_printk(struct tracecmd_output *handle)
665 669
666static struct tracecmd_output * 670static struct tracecmd_output *
667create_file_fd(int fd, struct tracecmd_input *ihandle, 671create_file_fd(int fd, struct tracecmd_input *ihandle,
672 const char *tracing_dir,
673 const char *kallsyms,
668 struct tracecmd_event_list *list) 674 struct tracecmd_event_list *list)
669{ 675{
670 struct tracecmd_output *handle; 676 struct tracecmd_output *handle;
@@ -684,6 +690,11 @@ create_file_fd(int fd, struct tracecmd_input *ihandle,
684 memset(handle, 0, sizeof(*handle)); 690 memset(handle, 0, sizeof(*handle));
685 691
686 handle->fd = fd; 692 handle->fd = fd;
693 if (tracing_dir) {
694 handle->tracing_dir = strdup(tracing_dir);
695 if (!handle->tracing_dir)
696 goto out_free;
697 }
687 698
688 buf[0] = 23; 699 buf[0] = 23;
689 buf[1] = 8; 700 buf[1] = 8;
@@ -736,7 +747,7 @@ create_file_fd(int fd, struct tracecmd_input *ihandle,
736 goto out_free; 747 goto out_free;
737 if (read_event_files(handle, list)) 748 if (read_event_files(handle, list))
738 goto out_free; 749 goto out_free;
739 if (read_proc_kallsyms(handle)) 750 if (read_proc_kallsyms(handle, kallsyms))
740 goto out_free; 751 goto out_free;
741 if (read_ftrace_printk(handle)) 752 if (read_ftrace_printk(handle))
742 goto out_free; 753 goto out_free;
@@ -775,6 +786,8 @@ create_file_fd(int fd, struct tracecmd_input *ihandle,
775 786
776static struct tracecmd_output *create_file(const char *output_file, 787static struct tracecmd_output *create_file(const char *output_file,
777 struct tracecmd_input *ihandle, 788 struct tracecmd_input *ihandle,
789 const char *tracing_dir,
790 const char *kallsyms,
778 struct tracecmd_event_list *list) 791 struct tracecmd_event_list *list)
779{ 792{
780 struct tracecmd_output *handle; 793 struct tracecmd_output *handle;
@@ -784,7 +797,7 @@ static struct tracecmd_output *create_file(const char *output_file,
784 if (fd < 0) 797 if (fd < 0)
785 return NULL; 798 return NULL;
786 799
787 handle = create_file_fd(fd, ihandle, list); 800 handle = create_file_fd(fd, ihandle, tracing_dir, kallsyms, list);
788 if (!handle) { 801 if (!handle) {
789 close(fd); 802 close(fd);
790 unlink(output_file); 803 unlink(output_file);
@@ -870,7 +883,7 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in
870 struct tracecmd_output *handle; 883 struct tracecmd_output *handle;
871 char *path; 884 char *path;
872 885
873 handle = create_file(output_file, NULL, &all_event_list); 886 handle = create_file(output_file, NULL, NULL, NULL, &all_event_list);
874 if (!handle) 887 if (!handle)
875 return NULL; 888 return NULL;
876 889
@@ -1050,7 +1063,7 @@ tracecmd_create_file_glob(const char *output_file,
1050{ 1063{
1051 struct tracecmd_output *handle; 1064 struct tracecmd_output *handle;
1052 1065
1053 handle = create_file(output_file, NULL, list); 1066 handle = create_file(output_file, NULL, NULL, NULL, list);
1054 if (!handle) 1067 if (!handle)
1055 return NULL; 1068 return NULL;
1056 1069
@@ -1069,12 +1082,19 @@ struct tracecmd_output *tracecmd_create_file(const char *output_file,
1069 1082
1070struct tracecmd_output *tracecmd_create_init_fd(int fd) 1083struct tracecmd_output *tracecmd_create_init_fd(int fd)
1071{ 1084{
1072 return create_file_fd(fd, NULL, &all_event_list); 1085 return create_file_fd(fd, NULL, NULL, NULL, &all_event_list);
1073} 1086}
1074 1087
1075struct tracecmd_output *tracecmd_create_init_file(const char *output_file) 1088struct tracecmd_output *tracecmd_create_init_file(const char *output_file)
1076{ 1089{
1077 return create_file(output_file, NULL, &all_event_list); 1090 return create_file(output_file, NULL, NULL, NULL, &all_event_list);
1091}
1092
1093struct tracecmd_output *tracecmd_create_init_file_override(const char *output_file,
1094 const char *tracing_dir,
1095 const char *kallsyms)
1096{
1097 return create_file(output_file, NULL, tracing_dir, kallsyms, &all_event_list);
1078} 1098}
1079 1099
1080/** 1100/**
@@ -1091,7 +1111,7 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle,
1091{ 1111{
1092 struct tracecmd_output *handle; 1112 struct tracecmd_output *handle;
1093 1113
1094 handle = create_file(file, ihandle, &all_event_list); 1114 handle = create_file(file, ihandle, NULL, NULL, &all_event_list);
1095 if (!handle) 1115 if (!handle)
1096 return NULL; 1116 return NULL;
1097 1117
diff --git a/trace-restore.c b/trace-restore.c
index cf8c14f..d255546 100644
--- a/trace-restore.c
+++ b/trace-restore.c
@@ -45,6 +45,8 @@ void trace_restore (int argc, char **argv)
45 const char *output_file = "trace.dat"; 45 const char *output_file = "trace.dat";
46 const char *output = NULL; 46 const char *output = NULL;
47 const char *input = NULL; 47 const char *input = NULL;
48 const char *tracing_dir = NULL;
49 const char *kallsyms = NULL;
48 struct stat st1; 50 struct stat st1;
49 struct stat st2; 51 struct stat st2;
50 int first_arg; 52 int first_arg;
@@ -58,7 +60,7 @@ void trace_restore (int argc, char **argv)
58 if (strcmp(argv[1], "restore") != 0) 60 if (strcmp(argv[1], "restore") != 0)
59 usage(argv); 61 usage(argv);
60 62
61 while ((c = getopt(argc-1, argv+1, "+hco:i:")) >= 0) { 63 while ((c = getopt(argc-1, argv+1, "+hco:i:t:k:")) >= 0) {
62 switch (c) { 64 switch (c) {
63 case 'h': 65 case 'h':
64 usage(argv); 66 usage(argv);
@@ -71,6 +73,12 @@ void trace_restore (int argc, char **argv)
71 output_file = "trace-partial.dat"; 73 output_file = "trace-partial.dat";
72 break; 74 break;
73 75
76 case 't':
77 tracing_dir = optarg;
78 break;
79 case 'k':
80 kallsyms = optarg;
81 break;
74 case 'o': 82 case 'o':
75 if (output) 83 if (output)
76 die("only one output file allowed"); 84 die("only one output file allowed");
@@ -99,7 +107,8 @@ void trace_restore (int argc, char **argv)
99 usage(argv); 107 usage(argv);
100 } 108 }
101 109
102 handle = tracecmd_create_init_file(output); 110 handle = tracecmd_create_init_file_override(output, tracing_dir,
111 kallsyms);
103 if (!handle) 112 if (!handle)
104 die("Unabled to create output file %s", output); 113 die("Unabled to create output file %s", output);
105 tracecmd_output_close(handle); 114 tracecmd_output_close(handle);