@@ -174,6 +174,8 @@ int tracecmd_copy_headers(struct tracecmd_input *in_handle,
struct tracecmd_output *out_handle,
enum tracecmd_file_states start_state,
enum tracecmd_file_states end_state);
+int tracecmd_copy_buffer_descr(struct tracecmd_input *in_handle,
+ struct tracecmd_output *out_handle);
void tracecmd_set_flag(struct tracecmd_input *handle, int flag);
void tracecmd_clear_flag(struct tracecmd_input *handle, int flag);
unsigned long tracecmd_get_flags(struct tracecmd_input *handle);
@@ -4173,6 +4173,44 @@ int tracecmd_copy_headers(struct tracecmd_input *in_handle,
return ret < 0 ? -1 : 0;
}
+static int skip_buffers(struct tracecmd_input *handle)
+{
+ unsigned long long offset;
+ unsigned int count;
+ char *bname;
+ int i;
+
+ if (read4(handle, &count) < 0)
+ return -1;
+
+ for (i = 0; i < count; i++) {
+ if (read8(handle, &offset) < 0)
+ return -1;
+ bname = read_string(handle);
+ free(bname);
+ }
+
+ handle->file_state = TRACECMD_FILE_BUFERS;
+ return 0;
+}
+
+int tracecmd_copy_buffer_descr(struct tracecmd_input *in_handle,
+ struct tracecmd_output *out_handle)
+{
+ int i;
+
+ if (in_handle->file_version >= 7) {
+ if (!check_in_state(in_handle, TRACECMD_FILE_BUFERS))
+ return -1;
+ skip_buffers(in_handle);
+ }
+ for (i = 0; i < in_handle->nr_buffers; i++)
+ tracecmd_add_buffer_description(out_handle,
+ in_handle->buffers[i].name, 0);
+
+ return tracecmd_write_buffers_description(out_handle);
+}
+
/**
* tracecmd_record_at_buffer_start - return true if record is first on subbuffer
* @handle: input handle for the trace.dat file
@@ -1952,6 +1952,9 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char
fstate = state > TRACECMD_FILE_CPU_COUNT ? TRACECMD_FILE_CPU_COUNT : state;
if (tracecmd_copy_headers(ihandle, handle, 0, fstate) < 0)
goto out_free;
+ if (state >= TRACECMD_FILE_BUFERS &&
+ tracecmd_copy_buffer_descr(ihandle, handle) < 0)
+ goto out_free;
/* The file is all ready to have cpu data attached */
return handle;
Extend the tracecmd_copy() API to support copying of trace buffers description from input to output trace handler. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- .../include/private/trace-cmd-private.h | 2 + lib/trace-cmd/trace-input.c | 38 +++++++++++++++++++ lib/trace-cmd/trace-output.c | 3 ++ 3 files changed, 43 insertions(+)