diff mbox series

[v6,39/45] trace-cmd: Add compression parameter to tracecmd_copy

Message ID 20210614075029.598048-40-tz.stoyanov@gmail.com (mailing list archive)
State Superseded
Headers show
Series Add trace file compression | expand

Commit Message

Tzvetomir Stoyanov (VMware) June 14, 2021, 7:50 a.m. UTC
Added compression parameter to the tracecmd_copy() API, which allows to
select the compression of the created output file.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 lib/trace-cmd/include/private/trace-cmd-private.h |  2 +-
 lib/trace-cmd/trace-output.c                      | 11 +++++++----
 tracecmd/trace-restore.c                          |  2 +-
 tracecmd/trace-split.c                            |  2 +-
 4 files changed, 10 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index 79fef884..c8f0ee93 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -316,7 +316,7 @@  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,
-				      enum tracecmd_file_states state);
+				      enum tracecmd_file_states state, const char *compression);
 
 int tracecmd_write_cpu_data(struct tracecmd_output *handle,
 			    int cpus, char * const *cpu_data_files);
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 377c5863..dae11ed3 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -1999,20 +1999,23 @@  struct tracecmd_output *tracecmd_create_init_file_override(const char *output_fi
  * @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
+ * @compression: compression of the output file, can be one of:
+ *		 NULL - inherit compression from the input file
+ *		 "any" - compress the output file with the best available algorithm
+ *		 "none" - do not compress the output file
+ *		 algorithm_name - compress the output file with specified algorithm
  *
  * 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,
-				      enum tracecmd_file_states state)
+				      enum tracecmd_file_states state, const char *compression)
 {
 	enum tracecmd_file_states fstate;
 	struct tracecmd_output *handle;
-	const char *compr_name = NULL;
 
-	tracecmd_get_file_compress_proto(ihandle, &compr_name, NULL);
-	handle = create_file(file, ihandle, NULL, NULL, &all_event_list, compr_name);
+	handle = create_file(file, ihandle, NULL, NULL, &all_event_list, compression);
 	if (!handle)
 		return NULL;
 
diff --git a/tracecmd/trace-restore.c b/tracecmd/trace-restore.c
index 7d439fd2..58913fa7 100644
--- a/tracecmd/trace-restore.c
+++ b/tracecmd/trace-restore.c
@@ -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, TRACECMD_FILE_CMD_LINES);
+		handle = tracecmd_copy(ihandle, output, TRACECMD_FILE_CMD_LINES, NULL);
 		tracecmd_close(ihandle);
 	} else
 		handle = tracecmd_create_init_file(output, NULL);
diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c
index 401e1d29..b98e6fc9 100644
--- a/tracecmd/trace-split.c
+++ b/tracecmd/trace-split.c
@@ -345,7 +345,7 @@  static double parse_file(struct tracecmd_input *handle,
 	dir = dirname(output);
 	base = basename(output);
 
-	ohandle = tracecmd_copy(handle, output_file, TRACECMD_FILE_CMD_LINES);
+	ohandle = tracecmd_copy(handle, output_file, TRACECMD_FILE_CMD_LINES, NULL);
 
 	cpus = tracecmd_cpus(handle);
 	cpu_data = malloc(sizeof(*cpu_data) * cpus);