aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--trace-cmd.h2
-rw-r--r--trace-output.c39
-rw-r--r--trace-record.c24
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;
127struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); 127struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus);
128struct tracecmd_output *tracecmd_create_file(const char *output_file, 128struct 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);
130struct tracecmd_output *tracecmd_create_init_fd(int fd, int cpus);
130void tracecmd_output_close(struct tracecmd_output *handle); 131void tracecmd_output_close(struct tracecmd_output *handle);
131struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, 132struct 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
138void tracecmd_free_recorder(struct tracecmd_recorder *recorder); 139void tracecmd_free_recorder(struct tracecmd_recorder *recorder);
139struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu); 140struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu);
141struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu);
140int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep); 142int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep);
141void tracecmd_stop_recording(struct tracecmd_recorder *recorder); 143void tracecmd_stop_recording(struct tracecmd_recorder *recorder);
142void tracecmd_stat_cpu(struct trace_seq *s, int cpu); 144void 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
523static struct tracecmd_output *create_file(const char *output_file, int cpus, 523static struct tracecmd_output *
524 struct tracecmd_input *ihandle) 524create_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
632static 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
634struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus) 651struct 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
780struct tracecmd_output *
781tracecmd_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
59struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu) 59struct 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
113struct 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
115int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep) 131int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep)
116{ 132{
117 struct timespec req; 133 struct timespec req;