diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2010-02-23 22:03:47 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-23 22:03:47 -0500 |
| commit | 5e3c45b45f4cc829f4aafe3225ddb9482e94d5d5 (patch) | |
| tree | e00cd1c901d2cf4b3c8c5a6fd9a7890ef7d76df3 | |
| parent | fe67d919aaec589776817b52d7d1c49559cd2b53 (diff) | |
trace-cmd: Add fd versions of some trace.dat writers
Add some verisons of tracecmd_output that allows to pass in an
already opened file descriptor.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | trace-cmd.h | 2 | ||||
| -rw-r--r-- | trace-output.c | 39 | ||||
| -rw-r--r-- | trace-record.c | 24 |
3 files changed, 56 insertions, 9 deletions
diff --git a/trace-cmd.h b/trace-cmd.h index 3b68db1..1db7303 100644 --- a/trace-cmd.h +++ b/trace-cmd.h | |||
| @@ -127,6 +127,7 @@ extern __thread struct tracecmd_input *tracecmd_curr_thread_handle; | |||
| 127 | struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); | 127 | struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); |
| 128 | struct tracecmd_output *tracecmd_create_file(const char *output_file, | 128 | struct tracecmd_output *tracecmd_create_file(const char *output_file, |
| 129 | int cpus, char * const *cpu_data_files); | 129 | int cpus, char * const *cpu_data_files); |
| 130 | struct tracecmd_output *tracecmd_create_init_fd(int fd, int cpus); | ||
| 130 | void tracecmd_output_close(struct tracecmd_output *handle); | 131 | void tracecmd_output_close(struct tracecmd_output *handle); |
| 131 | struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, | 132 | struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, |
| 132 | const char *file); | 133 | const char *file); |
| @@ -137,6 +138,7 @@ int tracecmd_append_cpu_data(struct tracecmd_output *handle, | |||
| 137 | 138 | ||
| 138 | void tracecmd_free_recorder(struct tracecmd_recorder *recorder); | 139 | void tracecmd_free_recorder(struct tracecmd_recorder *recorder); |
| 139 | struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu); | 140 | struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu); |
| 141 | struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu); | ||
| 140 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep); | 142 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep); |
| 141 | void tracecmd_stop_recording(struct tracecmd_recorder *recorder); | 143 | void tracecmd_stop_recording(struct tracecmd_recorder *recorder); |
| 142 | void tracecmd_stat_cpu(struct trace_seq *s, int cpu); | 144 | void tracecmd_stat_cpu(struct trace_seq *s, int cpu); |
diff --git a/trace-output.c b/trace-output.c index a59099d..a45265d 100644 --- a/trace-output.c +++ b/trace-output.c | |||
| @@ -520,8 +520,8 @@ static int read_ftrace_printk(struct tracecmd_output *handle) | |||
| 520 | return 0; | 520 | return 0; |
| 521 | } | 521 | } |
| 522 | 522 | ||
| 523 | static struct tracecmd_output *create_file(const char *output_file, int cpus, | 523 | static struct tracecmd_output * |
| 524 | struct tracecmd_input *ihandle) | 524 | create_file_fd(int fd, int cpus, struct tracecmd_input *ihandle) |
| 525 | { | 525 | { |
| 526 | struct tracecmd_output *handle; | 526 | struct tracecmd_output *handle; |
| 527 | unsigned long long endian8; | 527 | unsigned long long endian8; |
| @@ -539,9 +539,7 @@ static struct tracecmd_output *create_file(const char *output_file, int cpus, | |||
| 539 | return NULL; | 539 | return NULL; |
| 540 | memset(handle, 0, sizeof(*handle)); | 540 | memset(handle, 0, sizeof(*handle)); |
| 541 | 541 | ||
| 542 | handle->fd = open(output_file, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); | 542 | handle->fd = fd; |
| 543 | if (handle->fd < 0) | ||
| 544 | goto out_free; | ||
| 545 | 543 | ||
| 546 | buf[0] = 23; | 544 | buf[0] = 23; |
| 547 | buf[1] = 8; | 545 | buf[1] = 8; |
| @@ -631,6 +629,25 @@ static struct tracecmd_output *create_file(const char *output_file, int cpus, | |||
| 631 | return NULL; | 629 | return NULL; |
| 632 | } | 630 | } |
| 633 | 631 | ||
| 632 | static struct tracecmd_output *create_file(const char *output_file, int cpus, | ||
| 633 | struct tracecmd_input *ihandle) | ||
| 634 | { | ||
| 635 | struct tracecmd_output *handle; | ||
| 636 | int fd; | ||
| 637 | |||
| 638 | fd = open(output_file, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); | ||
| 639 | if (fd < 0) | ||
| 640 | return NULL; | ||
| 641 | |||
| 642 | handle = create_file_fd(fd, cpus, ihandle); | ||
| 643 | if (!handle) { | ||
| 644 | close(fd); | ||
| 645 | unlink(output_file); | ||
| 646 | } | ||
| 647 | |||
| 648 | return handle; | ||
| 649 | } | ||
| 650 | |||
| 634 | struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus) | 651 | struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus) |
| 635 | { | 652 | { |
| 636 | struct tracecmd_output *handle; | 653 | struct tracecmd_output *handle; |
| @@ -760,6 +777,18 @@ struct tracecmd_output *tracecmd_create_file(const char *output_file, | |||
| 760 | return handle; | 777 | return handle; |
| 761 | } | 778 | } |
| 762 | 779 | ||
| 780 | struct tracecmd_output * | ||
| 781 | tracecmd_create_init_fd(int fd, int cpus) | ||
| 782 | { | ||
| 783 | struct tracecmd_output *handle; | ||
| 784 | |||
| 785 | handle = create_file_fd(fd, cpus, NULL); | ||
| 786 | if (!handle) | ||
| 787 | return NULL; | ||
| 788 | |||
| 789 | return handle; | ||
| 790 | } | ||
| 791 | |||
| 763 | /** | 792 | /** |
| 764 | * tracecmd_copy - copy the headers of one trace.dat file for another | 793 | * tracecmd_copy - copy the headers of one trace.dat file for another |
| 765 | * @ihandle: input handle of the trace.dat file to copy | 794 | * @ihandle: input handle of the trace.dat file to copy |
diff --git a/trace-record.c b/trace-record.c index 8317320..cdfc857 100644 --- a/trace-record.c +++ b/trace-record.c | |||
| @@ -56,7 +56,7 @@ void tracecmd_free_recorder(struct tracecmd_recorder *recorder) | |||
| 56 | free(recorder); | 56 | free(recorder); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu) | 59 | struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu) |
| 60 | { | 60 | { |
| 61 | struct tracecmd_recorder *recorder; | 61 | struct tracecmd_recorder *recorder; |
| 62 | char *tracing = NULL; | 62 | char *tracing = NULL; |
| @@ -76,9 +76,7 @@ struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu) | |||
| 76 | 76 | ||
| 77 | recorder->page_size = getpagesize(); | 77 | recorder->page_size = getpagesize(); |
| 78 | 78 | ||
| 79 | recorder->fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); | 79 | recorder->fd = fd; |
| 80 | if (recorder->fd < 0) | ||
| 81 | goto out_free; | ||
| 82 | 80 | ||
| 83 | tracing = tracecmd_find_tracing_dir(); | 81 | tracing = tracecmd_find_tracing_dir(); |
| 84 | if (!tracing) { | 82 | if (!tracing) { |
| @@ -112,6 +110,24 @@ struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu) | |||
| 112 | return NULL; | 110 | return NULL; |
| 113 | } | 111 | } |
| 114 | 112 | ||
| 113 | struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu) | ||
| 114 | { | ||
| 115 | struct tracecmd_recorder *recorder; | ||
| 116 | int fd; | ||
| 117 | |||
| 118 | fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); | ||
| 119 | if (recorder->fd < 0) | ||
| 120 | return NULL; | ||
| 121 | |||
| 122 | recorder = tracecmd_create_recorder_fd(fd, cpu); | ||
| 123 | if (!recorder) { | ||
| 124 | close(fd); | ||
| 125 | unlink(file); | ||
| 126 | } | ||
| 127 | |||
| 128 | return recorder; | ||
| 129 | } | ||
| 130 | |||
| 115 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep) | 131 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep) |
| 116 | { | 132 | { |
| 117 | struct timespec req; | 133 | struct timespec req; |
