diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2009-12-17 14:36:41 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-17 14:36:41 -0500 |
| commit | 2c36d9bd41b3d0f4722e322ee4b062d046bf3ec5 (patch) | |
| tree | 97ecd14f3b62da6953c9b23e053f4fcd86eafb16 | |
| parent | 3659208b623ce3687f438ddab940fad260ea65c2 (diff) | |
trace-cmd: Change tracecmd_open() to take file name
Rename tracecmd_open() to tracecmd_open_fd and add a new
tracecmd_open() to take the name of a file.
Also added the API for tracecmd_close() but still need to do
proper clean up. It just frees the handle, but does nothing with
everything else it allocated.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | trace-cmd.h | 4 | ||||
| -rw-r--r-- | trace-input.c | 26 | ||||
| -rw-r--r-- | trace-read.c | 6 |
3 files changed, 30 insertions, 6 deletions
diff --git a/trace-cmd.h b/trace-cmd.h index 371d616..c5a3163 100644 --- a/trace-cmd.h +++ b/trace-cmd.h | |||
| @@ -44,7 +44,9 @@ char *tracecmd_find_tracing_dir(void); | |||
| 44 | 44 | ||
| 45 | /* --- Opening and Reading the trace.dat file --- */ | 45 | /* --- Opening and Reading the trace.dat file --- */ |
| 46 | 46 | ||
| 47 | struct tracecmd_input *tracecmd_open(int fd); | 47 | struct tracecmd_input *tracecmd_open(const char *file); |
| 48 | struct tracecmd_input *tracecmd_open_fd(int fd); | ||
| 49 | void tracecmd_close(struct tracecmd_input *handle); | ||
| 48 | int tracecmd_read_headers(struct tracecmd_input *handle); | 50 | int tracecmd_read_headers(struct tracecmd_input *handle); |
| 49 | int tracecmd_long_size(struct tracecmd_input *handle); | 51 | int tracecmd_long_size(struct tracecmd_input *handle); |
| 50 | int tracecmd_page_size(struct tracecmd_input *handle); | 52 | int tracecmd_page_size(struct tracecmd_input *handle); |
diff --git a/trace-input.c b/trace-input.c index 80de3cf..ee9177f 100644 --- a/trace-input.c +++ b/trace-input.c | |||
| @@ -1316,10 +1316,10 @@ void tracecmd_print_events(struct tracecmd_input *handle) | |||
| 1316 | } | 1316 | } |
| 1317 | 1317 | ||
| 1318 | /** | 1318 | /** |
| 1319 | * tracecmd_open - create a tracecmd_handle from the trace.dat file descriptor | 1319 | * tracecmd_open_fd - create a tracecmd_handle from the trace.dat file descriptor |
| 1320 | * @fd: the file descriptor for the trace.dat file | 1320 | * @fd: the file descriptor for the trace.dat file |
| 1321 | */ | 1321 | */ |
| 1322 | struct tracecmd_input *tracecmd_open(int fd) | 1322 | struct tracecmd_input *tracecmd_open_fd(int fd) |
| 1323 | { | 1323 | { |
| 1324 | struct tracecmd_input *handle; | 1324 | struct tracecmd_input *handle; |
| 1325 | char test[] = { 23, 8, 68 }; | 1325 | char test[] = { 23, 8, 68 }; |
| @@ -1377,6 +1377,28 @@ struct tracecmd_input *tracecmd_open(int fd) | |||
| 1377 | } | 1377 | } |
| 1378 | 1378 | ||
| 1379 | /** | 1379 | /** |
| 1380 | * tracecmd_open - create a tracecmd_handle from a given file | ||
| 1381 | * @file: the file name of the file that is of tracecmd data type. | ||
| 1382 | */ | ||
| 1383 | struct tracecmd_input *tracecmd_open(const char *file) | ||
| 1384 | { | ||
| 1385 | int fd; | ||
| 1386 | |||
| 1387 | fd = open(file, O_RDONLY); | ||
| 1388 | if (fd < 0) | ||
| 1389 | return NULL; | ||
| 1390 | |||
| 1391 | return tracecmd_open_fd(fd); | ||
| 1392 | } | ||
| 1393 | |||
| 1394 | void tracecmd_close(struct tracecmd_input *handle) | ||
| 1395 | { | ||
| 1396 | /* TODO FREE EVERYTHING!!! %%%% MEMORY LEAK!!! %%%% */ | ||
| 1397 | close(handle->fd); | ||
| 1398 | free(handle); | ||
| 1399 | } | ||
| 1400 | |||
| 1401 | /** | ||
| 1380 | * tracecmd_long_size - return the size of "long" for the arch | 1402 | * tracecmd_long_size - return the size of "long" for the arch |
| 1381 | * @handle: input handle for the trace.dat file | 1403 | * @handle: input handle for the trace.dat file |
| 1382 | */ | 1404 | */ |
diff --git a/trace-read.c b/trace-read.c index b6b233c..e875189 100644 --- a/trace-read.c +++ b/trace-read.c | |||
| @@ -38,8 +38,8 @@ | |||
| 38 | 38 | ||
| 39 | #include "trace-local.h" | 39 | #include "trace-local.h" |
| 40 | 40 | ||
| 41 | unsigned int page_size; | 41 | static unsigned int page_size; |
| 42 | int input_fd; | 42 | static int input_fd; |
| 43 | const char *input_file = "trace.dat"; | 43 | const char *input_file = "trace.dat"; |
| 44 | 44 | ||
| 45 | static int filter_cpu = -1; | 45 | static int filter_cpu = -1; |
| @@ -276,7 +276,7 @@ struct tracecmd_input *read_trace_header(void) | |||
| 276 | if (input_fd < 0) | 276 | if (input_fd < 0) |
| 277 | die("opening '%s'\n", input_file); | 277 | die("opening '%s'\n", input_file); |
| 278 | 278 | ||
| 279 | return tracecmd_open(input_fd); | 279 | return tracecmd_open_fd(input_fd); |
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | void trace_report (int argc, char **argv) | 282 | void trace_report (int argc, char **argv) |
