aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--trace-cmd.h2
-rw-r--r--trace-output.c57
2 files changed, 59 insertions, 0 deletions
diff --git a/trace-cmd.h b/trace-cmd.h
index 1db7303..7e21bc7 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -133,6 +133,8 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle,
133 const char *file); 133 const char *file);
134int tracecmd_append_cpu_data(struct tracecmd_output *handle, 134int tracecmd_append_cpu_data(struct tracecmd_output *handle,
135 int cpus, char * const *cpu_data_files); 135 int cpus, char * const *cpu_data_files);
136int tracecmd_attach_cpu_data(char *file, int cpus, char * const *cpu_data_files);
137int tracecmd_attach_cpu_data_fd(int fd, int cpus, char * const *cpu_data_files);
136 138
137/* --- Reading the Fly Recorder Trace --- */ 139/* --- Reading the Fly Recorder Trace --- */
138 140
diff --git a/trace-output.c b/trace-output.c
index a45265d..b586846 100644
--- a/trace-output.c
+++ b/trace-output.c
@@ -762,6 +762,63 @@ int tracecmd_append_cpu_data(struct tracecmd_output *handle,
762 return -1; 762 return -1;
763} 763}
764 764
765int tracecmd_attach_cpu_data_fd(int fd, int cpus, char * const *cpu_data_files)
766{
767 struct tracecmd_input *ihandle;
768 struct tracecmd_output *handle;
769 struct pevent *pevent;
770 int ret = -1;
771
772 /* Move the file descriptor to the beginning */
773 if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
774 return -1;
775
776 /* get a input handle from this */
777 ihandle = tracecmd_alloc_fd(fd);
778 if (!ihandle)
779 return -1;
780
781 /* move the file descriptor to the end */
782 if (lseek(fd, 0, SEEK_END) == (off_t)-1)
783 goto out_free;
784
785 /* create a partial output handle */
786
787 handle = malloc(sizeof(*handle));
788 if (!handle)
789 return -1;
790 memset(handle, 0, sizeof(*handle));
791
792 handle->fd = fd;
793
794 /* get endian and page size */
795 pevent = tracecmd_get_pevent(ihandle);
796 /* Use the pevent of the ihandle for later writes */
797 handle->pevent = tracecmd_get_pevent(ihandle);
798 pevent_ref(pevent);
799 handle->page_size = tracecmd_page_size(ihandle);
800
801 if (tracecmd_append_cpu_data(handle, cpus, cpu_data_files) < 0)
802 goto out_free;
803
804 ret = 0;
805 tracecmd_output_close(handle);
806 out_free:
807 tracecmd_close(ihandle);
808 return ret;
809}
810
811int tracecmd_attach_cpu_data(char *file, int cpus, char * const *cpu_data_files)
812{
813 int fd;
814
815 fd = open(file, O_RDWR);
816 if (fd < 0)
817 return -1;
818
819 return tracecmd_attach_cpu_data_fd(fd, cpus, cpu_data_files);
820}
821
765struct tracecmd_output *tracecmd_create_file(const char *output_file, 822struct tracecmd_output *tracecmd_create_file(const char *output_file,
766 int cpus, char * const *cpu_data_files) 823 int cpus, char * const *cpu_data_files)
767{ 824{