@@ -309,8 +309,8 @@ int tracecmd_write_options(struct tracecmd_output *handle);
int tracecmd_append_options(struct tracecmd_output *handle);
void tracecmd_output_close(struct tracecmd_output *handle);
void tracecmd_output_free(struct tracecmd_output *handle);
-struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle,
- const char *file);
+struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char *file,
+ enum tracecmd_file_states state);
int tracecmd_write_cpu_data(struct tracecmd_output *handle,
int cpus, char * const *cpu_data_files);
@@ -1931,13 +1931,16 @@ struct tracecmd_output *tracecmd_create_init_file_override(const char *output_fi
* tracecmd_copy - copy the headers of one trace.dat file for another
* @ihandle: input handle of the trace.dat file to copy
* @file: the trace.dat file to create
+ * @state: what data will be copied from the source handle
*
* Reads the header information and creates a new trace data file
* with the same characteristics (events and all) and returns
* tracecmd_output handle to this new file.
*/
-struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char *file)
+struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char *file,
+ enum tracecmd_file_states state)
{
+ enum tracecmd_file_states fstate;
struct tracecmd_output *handle;
const char *compr_name = NULL;
@@ -1946,7 +1949,8 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char
if (!handle)
return NULL;
- if (tracecmd_copy_headers(ihandle, handle, 0, 0) < 0)
+ fstate = state > TRACECMD_FILE_CMD_LINES ? TRACECMD_FILE_CMD_LINES : state;
+ if (tracecmd_copy_headers(ihandle, handle, 0, fstate) < 0)
goto out_free;
/* The file is all ready to have cpu data attached */
@@ -125,7 +125,7 @@ void trace_restore (int argc, char **argv)
if (tracecmd_read_headers(ihandle, TRACECMD_FILE_CMD_LINES) < 0)
die("error reading file %s headers", input);
- handle = tracecmd_copy(ihandle, output);
+ handle = tracecmd_copy(ihandle, output, TRACECMD_FILE_CMD_LINES);
tracecmd_close(ihandle);
} else
handle = tracecmd_create_init_file(output, NULL);
@@ -345,7 +345,7 @@ static double parse_file(struct tracecmd_input *handle,
dir = dirname(output);
base = basename(output);
- ohandle = tracecmd_copy(handle, output_file);
+ ohandle = tracecmd_copy(handle, output_file, TRACECMD_FILE_CMD_LINES);
cpus = tracecmd_cpus(handle);
cpu_data = malloc(sizeof(*cpu_data) * cpus);
The tracecmd_copy() API is used to create output trace handler from given input trace handler and to copy data from it. Currently it is used by trace-cmd split and restore commands, that's why it is hardcoded what data to be copied from input to output handler. Addig desired output handler file state makes the API more generic and allows it to be used in more use cases. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/trace-cmd/include/private/trace-cmd-private.h | 4 ++-- lib/trace-cmd/trace-output.c | 8 ++++++-- tracecmd/trace-restore.c | 2 +- tracecmd/trace-split.c | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-)