diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-12-15 19:38:27 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-15 19:38:27 -0500 |
commit | 9b961aa74b44b0952232626c5e819161d3517035 (patch) | |
tree | 6de45e3ce3a2533cd52d3c3dabd6c00c862156d3 | |
parent | aaa8b798203492e3ed80f06689c3f0c1f133d21b (diff) |
trace-cmd: Show ring buffer stastics at the end of tracing
When the tracer is completed, show the ring buffer statistics to
give a good idea about overruns and such.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-cmd.c | 11 | ||||
-rw-r--r-- | trace-cmd.h | 1 | ||||
-rw-r--r-- | trace-record.c | 39 |
3 files changed, 51 insertions, 0 deletions
diff --git a/trace-cmd.c b/trace-cmd.c index 92008cd..879d9ad 100644 --- a/trace-cmd.c +++ b/trace-cmd.c | |||
@@ -673,6 +673,7 @@ int main (int argc, char **argv) | |||
673 | const char *output = NULL; | 673 | const char *output = NULL; |
674 | const char *option; | 674 | const char *option; |
675 | struct event_list *event; | 675 | struct event_list *event; |
676 | struct trace_seq s; | ||
676 | int disable = 0; | 677 | int disable = 0; |
677 | int plug = 0; | 678 | int plug = 0; |
678 | int events = 0; | 679 | int events = 0; |
@@ -680,6 +681,7 @@ int main (int argc, char **argv) | |||
680 | int record = 0; | 681 | int record = 0; |
681 | int run_command = 0; | 682 | int run_command = 0; |
682 | int fset; | 683 | int fset; |
684 | int cpu; | ||
683 | 685 | ||
684 | int c; | 686 | int c; |
685 | 687 | ||
@@ -852,6 +854,15 @@ int main (int argc, char **argv) | |||
852 | record_data(); | 854 | record_data(); |
853 | delete_thread_data(); | 855 | delete_thread_data(); |
854 | 856 | ||
857 | printf("Buffer statistics:\n\n"); | ||
858 | for (cpu = 0; cpu < cpu_count; cpu++) { | ||
859 | trace_seq_init(&s); | ||
860 | trace_seq_printf(&s, "CPU: %d\n", cpu); | ||
861 | tracecmd_stat_cpu(&s, cpu); | ||
862 | trace_seq_do_printf(&s); | ||
863 | printf("\n"); | ||
864 | } | ||
865 | |||
855 | exit(0); | 866 | exit(0); |
856 | 867 | ||
857 | return 0; | 868 | return 0; |
diff --git a/trace-cmd.h b/trace-cmd.h index 27f30a7..4410f4c 100644 --- a/trace-cmd.h +++ b/trace-cmd.h | |||
@@ -109,6 +109,7 @@ void tracecmd_free_recorder(struct tracecmd_recorder *recorder); | |||
109 | struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu); | 109 | struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu); |
110 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep); | 110 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep); |
111 | void tracecmd_stop_recording(struct tracecmd_recorder *recorder); | 111 | void tracecmd_stop_recording(struct tracecmd_recorder *recorder); |
112 | void tracecmd_stat_cpu(struct trace_seq *s, int cpu); | ||
112 | 113 | ||
113 | 114 | ||
114 | #endif /* _TRACE_CMD_H */ | 115 | #endif /* _TRACE_CMD_H */ |
diff --git a/trace-record.c b/trace-record.c index 96579f1..6c910c7 100644 --- a/trace-record.c +++ b/trace-record.c | |||
@@ -138,3 +138,42 @@ void tracecmd_stop_recording(struct tracecmd_recorder *recorder) | |||
138 | 138 | ||
139 | recorder->stop = 1; | 139 | recorder->stop = 1; |
140 | } | 140 | } |
141 | |||
142 | /** | ||
143 | * tracecmd_stat_cpu - show the buffer stats of a particular CPU | ||
144 | * @s: the trace_seq to record the data in. | ||
145 | * @cpu: the CPU to stat | ||
146 | * | ||
147 | */ | ||
148 | void tracecmd_stat_cpu(struct trace_seq *s, int cpu) | ||
149 | { | ||
150 | char buf[BUFSIZ]; | ||
151 | char *tracing; | ||
152 | char *path; | ||
153 | int fd; | ||
154 | int r; | ||
155 | |||
156 | tracing = tracecmd_find_tracing_dir(); | ||
157 | if (!tracing) { | ||
158 | errno = ENODEV; | ||
159 | goto out_free; | ||
160 | } | ||
161 | |||
162 | path = malloc_or_die(strlen(tracing) + 40); | ||
163 | if (!path) | ||
164 | goto out_free; | ||
165 | |||
166 | sprintf(path, "%s/per_cpu/cpu%d/stats", tracing, cpu); | ||
167 | fd = open(path, O_RDONLY); | ||
168 | if (fd < 0) | ||
169 | goto out_free; | ||
170 | |||
171 | while ((r = read(fd, buf, BUFSIZ)) > 0) | ||
172 | trace_seq_printf(s, "%.*s", r, buf); | ||
173 | |||
174 | close(fd); | ||
175 | |||
176 | out_free: | ||
177 | free(path); | ||
178 | free(tracing); | ||
179 | } | ||