Add trace file compression
cover Add trace file compression
A new PoC implementation for adding a compression to trace file version 7. A basic infrastructure for compression support is added into the trace-cmd library. The zlib is used for compression, but more libraries and algorithms can be added. Only part of the trace file metadata is compressed:
- ftrace events format
- format of recorded events
- information about the mapping of function addresses to the function names
- trace_printk() format strings
- information of the mapping a PID to a process name
Note: not all trace-cmd commands are tested with these changes. These are verified to work with compressed trace files:
trace-cmd record
trace-cmd report
trace-cmd dump
Todo list, in order to have complete trace file compression:
- Compress trace file options.
- Compress trace data.
- Add support for more compression libraries.
- Add new trace-cmd command to convert trace files from version 6 to version 7 and vise versa.
- Add compression support to all trace-cmd commands.
- Update trace-cmd documentation.
This patch set depends on "[PATCH 0/6] Bump trace file version" and should be applied on top of it.
https://lore.kernel.org/linux-trace-devel/[email protected]/
Tzvetomir Stoyanov (VMware) (10):
trace-cmd: Add APIs for library initialization and free trace-cmd library: Add support for compression algorithms trace-cmd library: Compress part of the trace file trace-cmd library: Read compressed trace file
trace-cmd library: Add new API to get compression of input handler trace-cmd library: Inherit compression algorithm from input file trace-cmd library: Extend the create file APIs to support different
compression
trace-cmd record: Add new parameter --compression trace-cmd dump: Add support for trace files version 7 trace-cmd library: Add support for zlib compression library
lib/trace-cmd/Makefile | 11 + .../include/private/trace-cmd-private.h | 42 ++- lib/trace-cmd/include/trace-cmd-local.h | 7 + lib/trace-cmd/trace-compress-zlib.c | 172 ++++++++++ lib/trace-cmd/trace-compress.c | 289 +++++++++++++++++ lib/trace-cmd/trace-input.c | 304 +++++++++++++----- lib/trace-cmd/trace-output.c | 268 ++++++++++++--- lib/trace-cmd/trace-util.c | 12 + tracecmd/trace-cmd.c | 11 +- tracecmd/trace-dump.c | 164 ++++++++-- tracecmd/trace-record.c | 18 +- tracecmd/trace-restore.c | 4 +- tracecmd/trace-usage.c | 1 + 13 files changed, 1152 insertions(+), 151 deletions(-) create mode 100644 lib/trace-cmd/trace-compress-zlib.c create mode 100644 lib/trace-cmd/trace-compress.c
Signature · 1 line
2.30.2
PATCH 1/10 trace-cmd: Add APIs for library initialization and free
The trace-cmd library has no APIs for initialization and free of the whole library. Added these new APIs:
tracecmd_lib_init()
tracecmd_lib_free()
and call them in trace-cmd main function.
--- lib/trace-cmd/include/private/trace-cmd-private.h | 3 +++ lib/trace-cmd/trace-util.c | 9 +++++++++ tracecmd/trace-cmd.c | 11 ++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +3 -0
@@ -29,6 +29,9 @@struct tep_plugin_list *trace_load_plugins (struct tep_handle *tep,int flags); +int tracecmd_lib_init (void ); +void tracecmd_lib_free (void ); +int *tracecmd_add_id (int *list,int id,int len);enum {
lib/trace-cmd/trace-util.c +9 -0
@@ -589,3 +589,12 @@ bool tracecmd_is_version_supported(unsigned int version)return true;return false; } + +int tracecmd_lib_init (void ) +{ +return 0 ; +} + +void tracecmd_lib_free (void ) +{ +}
tracecmd/trace-cmd.c +8 -3
@@ -116,15 +116,20 @@ int main (int argc, char **argv)if (argc <2 )trace_usage (argc, argv); +tracecmd_lib_init (); +for (i =0 ; i <ARRAY_SIZE (commands); ++i) {if (strcmp (argv[1 ], commands[i].name) ==0 ){ commands[i].run (argc, argv); - goto out; +break ; } } +tracecmd_lib_free (); +/* No valid command found, show help */ -trace_usage (argc, argv); -out: +if (i ==ARRAY_SIZE (commands)) +trace_usage (argc, argv); +exit (0 ); }
Signature · 1 line
2.30.2
PATCH 2/10 trace-cmd library: Add support for compression algorithms
In reply to Tzvetomir Stoyanov (VMware)Added infrastructure to trace-cmd library for compression. Introduced various new APIs to work with this new functionality:
tracecmd_compress_proto_get() tracecmd_compress_protos_get() tracecmd_compress_proto_get_name() tracecmd_compress_proto_select() tracecmd_compress_proto_register() tracecmd_compress_data()
tracecmd_uncompress_data()
tracecmd_get_compress_size()
The compression algorithms are not part of this patch.
--- lib/trace-cmd/Makefile | 1 + .../include/private/trace-cmd-private.h | 22 ++ lib/trace-cmd/include/trace-cmd-local.h | 2 + lib/trace-cmd/trace-compress.c | 287 ++++++++++++++++++ lib/trace-cmd/trace-util.c | 3 + 5 files changed, 315 insertions(+) create mode 100644 lib/trace-cmd/trace-compress.c
lib/trace-cmd/Makefile +1 -0
@@ -25,6 +25,7 @@ ifeq ($(VSOCK_DEFINED), 1) OBJS += trace-timesync-ptp.o OBJS += trace-timesync-kvm.o endif +OBJS += trace-compress.o # Additional util objects OBJS += trace-blk-hack.o
lib/trace-cmd/include/private/trace-cmd-private.h +22 -0
@@ -471,6 +471,28 @@ void tracecmd_tsync_free(struct tracecmd_time_sync *tsync);int tracecmd_write_guest_time_shift (struct tracecmd_output *handle,struct tracecmd_time_sync *tsync); +/* --- Compression --- */ +struct tracecmd_compress_proto ; +struct tracecmd_compress_proto *tracecmd_compress_proto_get (const char *name,const char *version); +struct tracecmd_compress_proto *tracecmd_compress_proto_select (void ); +int tracecmd_compress_proto_register (const char *name,const char *version,int weight, +int (*compress)(char *in,unsigned int in_bytes, +char *out,unsigned int *out_bytes), +int (*uncompress)(char *in,unsigned int in_bytes, +char *out,unsigned int *out_bytes), +unsigned int (*comress_size)(unsigned int bytes), +bool (*is_supported)(const char *name,const char *version)); +int tracecmd_compress_protos_get (char ***names,char ***versions); +int tracecmd_compress_proto_get_name (struct tracecmd_compress_proto *proto, +const char **name,const char **version); +int tracecmd_compress_data (struct tracecmd_compress_proto *proto, +char *in,unsigned int in_bytes, +char *out,unsigned int *out_bytes); +int tracecmd_uncompress_data (struct tracecmd_compress_proto *proto, +char *in,unsigned int in_bytes, +char *out,unsigned int *out_bytes); +unsigned int tracecmd_get_compress_size (struct tracecmd_compress_proto *proto,unsigned int bytes); +/* --- Plugin handling --- */ extern struct tep_plugin_option trace_ftrace_options[];
lib/trace-cmd/include/trace-cmd-local.h +2 -0
@@ -30,5 +30,7 @@ void tracecmd_fatal(const char *fmt, ...);#endif #endif +int tracecmd_compress_init (void ); +void tracecmd_compress_free (void );#endif /* _TRACE_CMD_LOCAL_H */
lib/trace-cmd/trace-compress.c new file +287 -0
287 lines not on this page · raw message
lib/trace-cmd/trace-util.c +3 -0
@@ -592,9 +592,12 @@ bool tracecmd_is_version_supported(unsigned int version)int tracecmd_lib_init (void ) { + +tracecmd_compress_init ();return 0 ; }void tracecmd_lib_free (void ) { +tracecmd_compress_free (); }
Signature · 1 line
2.30.2
PATCH 3/10 trace-cmd library: Compress part of the trace file
In reply to Tzvetomir Stoyanov (VMware)Compress some methadata of the trace.dat file. If there is compression support, chose file version 7 and compress these parts of the file:
- ftrace events format
- format of recorded events
- information of the mapping of function addresses to the function names
- trace_printk() format strings
- information of the mapping a PID to a process name
A new compression header is added in the file, right after the page size information.
--- lib/trace-cmd/trace-output.c | 190 ++++++++++++++++++++++++++++++----- 1 file changed, 167 insertions(+), 23 deletions(-)
lib/trace-cmd/trace-output.c +167 -23
@@ -58,6 +58,13 @@ struct tracecmd_output {bool quiet;unsigned long file_state;unsigned long file_version; + +bool compress; +unsigned int compress_size; +unsigned int commpress_capacity; +char *compress_buffer; +struct tracecmd_compress_proto *compress_proto; +struct list_head options;struct tracecmd_msg_handle *msg_handle;char *trace_clock;
@@ -75,9 +82,31 @@ struct list_event_system {char *name; }; +static stsize_t write_compress (struct tracecmd_output *handle,const void *data,tsize_t size) +{ +char *buf; +int extend; + +if (handle->commpress_capacity < handle->compress_size + size) { + extend = (handle->compress_size + size) - handle->commpress_capacity; + extend = extend <BUFSIZ ?BUFSIZ : extend; + buf =realloc (handle->compress_buffer, handle->commpress_capacity + extend); +if (!buf) +return -ENOMEM ; + handle->compress_buffer = buf; + handle->commpress_capacity += extend; + } +memcpy (&handle->compress_buffer[handle->compress_size], data, size); + handle->compress_size += size; +return 0 ; +} +static stsize_t do_write_check (struct tracecmd_output *handle,const void *data,tsize_t size) { +if (handle->compress) +return write_compress (handle, data, size); +if (handle->msg_handle)return tracecmd_msg_data_send (handle->msg_handle, data, size);
@@ -109,6 +138,70 @@ static unsigned long long convert_endian_8(struct tracecmd_output *handle,return tep_read_number (handle->pevent, &val,8 ); } +static stsize_t write_compress_data (struct tracecmd_output *handle) +{ +unsigned int size; +char *buf; +int endian4; +int ret; + + size =tracecmd_get_compress_size (handle->compress_proto, handle->compress_size); + buf =malloc (size); +if (!buf) +return -ENOMEM ; + + ret =tracecmd_compress_data (handle->compress_proto, handle->compress_buffer, + handle->compress_size, buf, &size); +if (ret <0 ) + goto out; +/* Write compressed data size */ + endian4 =convert_endian_4 (handle, size); + ret =do_write_check (handle, &endian4,4 ); +if (ret <0 ) + goto out; +/* Write uncompressed data size */ + endian4 =convert_endian_4 (handle, handle->compress_size); + ret =do_write_check (handle, &endian4,4 ); +if (ret <0 ) + goto out; +/* Write uncompressed the data */ + ret =do_write_check (handle, buf, size); +out: +free (buf); +return ret; +} + +static inline void compression_reset (struct tracecmd_output *handle) +{ +if (handle->file_version <7 || !handle->compress_proto) +return ; +free (handle->compress_buffer); + handle->compress_buffer =NULL ; + handle->commpress_capacity =0 ; + handle->compress_size =0 ; +} + +static inline int compression_start (struct tracecmd_output *handle) +{ +if (handle->file_version <7 || !handle->compress_proto) +return 0 ; +compression_reset (handle); + handle->compress = true; +return 0 ; +} + +static inline int compression_end (struct tracecmd_output *handle) +{ +int ret; + +if (handle->file_version <7 || !handle->compress_proto) +return 0 ; + handle->compress = false; + ret =write_compress_data (handle); +compression_reset (handle); +return ret; +} +/** * tracecmd_set_quiet - Set if to print output to the screen * @quiet: If non zero, print no output to the screen
@@ -659,13 +752,17 @@ static int read_ftrace_files(struct tracecmd_output *handle) }create_event_list_item (handle, &systems, &list); - +compression_start (handle); ret =copy_event_system (handle, systems); +if (!ret) + ret =compression_end (handle); +else +compression_reset (handle);free_list_events (systems); - handle->file_state =TRACECMD_FILE_FTRACE_EVENTS ; - +if (!ret) + handle->file_state =TRACECMD_FILE_FTRACE_EVENTS ;return ret; }
@@ -715,6 +812,7 @@ static int read_event_files(struct tracecmd_output *handle,for (slist = systems; slist; slist = slist->next) count++; +compression_start (handle); ret =-1 ; endian4 =convert_endian_4 (handle, count);if (do_write_check (handle, &endian4,4 ))
@@ -730,8 +828,14 @@ static int read_event_files(struct tracecmd_output *handle, ret =copy_event_system (handle, slist); } - handle->file_state =TRACECMD_FILE_ALL_EVENTS ; +if (!ret) + ret =compression_end (handle); out_free: +if (!ret) + handle->file_state =TRACECMD_FILE_ALL_EVENTS ; +else +compression_reset (handle); +free_list_events (systems);return ret;
@@ -793,20 +897,20 @@ static int read_proc_kallsyms(struct tracecmd_output *handle,if (kallsyms) path = kallsyms; - +compression_start (handle); ret =stat (path, &st);if (ret <0 ) {/* not found */ size =0 ; endian4 =convert_endian_4 (handle, size); -if (do_write_check (handle, &endian4,4 )) -return -1 ; -return 0 ; + ret =do_write_check (handle, &endian4,4 ); + goto out; } size =get_size (path); endian4 =convert_endian_4 (handle, size); -if (do_write_check (handle, &endian4,4 )) -return -1 ; + ret =do_write_check (handle, &endian4,4 ); +if (ret) + goto out;set_proc_kptr_restrict (0 ); check_size =copy_file (handle, path);
@@ -814,13 +918,18 @@ static int read_proc_kallsyms(struct tracecmd_output *handle, errno =EINVAL ;tracecmd_warning ("error in size of file '%s'" , path);set_proc_kptr_restrict (1 ); -return -1 ; + ret =-1 ; + goto out; }set_proc_kptr_restrict (1 ); - handle->file_state =TRACECMD_FILE_KALLSYMS ; - -return 0 ; + ret =compression_end (handle); +out: +if (!ret) + handle->file_state =TRACECMD_FILE_KALLSYMS ; +else +compression_reset (handle); +return ret; }static int read_ftrace_printk (struct tracecmd_output *handle)
@@ -840,6 +949,7 @@ static int read_ftrace_printk(struct tracecmd_output *handle)if (!path)return -1 ; +compression_start (handle); ret =stat (path, &st);if (ret <0 ) {/* not found */
@@ -861,11 +971,14 @@ static int read_ftrace_printk(struct tracecmd_output *handle) } out: - handle->file_state =TRACECMD_FILE_PRINTK ;put_tracing_file (path); +if (compression_end (handle)) +return -1 ; + handle->file_state =TRACECMD_FILE_PRINTK ;return 0 ; fail:put_tracing_file (path); +compression_reset (handle);return -1 ; }
@@ -911,16 +1024,40 @@ out_free:static int select_file_version (struct tracecmd_output *handle,struct tracecmd_input *ihandle,unsigned long file_version) { -if (ihandle) +if (ihandle) { handle->file_version =tracecmd_get_file_version (ihandle); -else if (file_version >0 ) + }else if (file_version >0 ) { handle->file_version = file_version; -else - handle->file_version =FILE_VERSION ; + }else { + handle->compress_proto =tracecmd_compress_proto_select (); +if (handle->compress_proto) + handle->file_version =7 ; +else + handle->file_version =6 ; + }return 0 ; } +static int write_compression_header (struct tracecmd_output *handle) +{ +const char *name =NULL ; +const char *ver =NULL ; +char *buf; +int ret; + + ret =tracecmd_compress_proto_get_name (handle->compress_proto, &name, &ver); +if (ret <0 || !name || !ver) +return -1 ; + ret =asprintf (&buf,"%s %s" , name, ver); +if (ret <0 ) +return -1 ; + ret =do_write_check (handle, buf,strlen (buf) +1 ); + +free (buf); +return ret; +} +static struct tracecmd_output * create_file_fd(int fd, struct tracecmd_input *ihandle, const char *tracing_dir,
@@ -996,7 +1133,8 @@ create_file_fd(int fd, struct tracecmd_input *ihandle,if (do_write_check (handle, &endian4,4 )) goto out_free; handle->file_state =TRACECMD_FILE_INIT ; - +if (handle->file_version >=7 &&write_compression_header (handle)) + goto out_free;if (ihandle)return handle;
@@ -1329,11 +1467,17 @@ int tracecmd_write_cmdlines(struct tracecmd_output *handle) handle->file_state);return ret; } +compression_start (handle); + ret =save_tracing_file_data (handle,"saved_cmdlines" ); -if (ret <0 ) +if (ret <0 ) { +compression_reset (handle);return ret; - handle->file_state =TRACECMD_FILE_CMD_LINES ; -return 0 ; + } + ret =compression_end (handle); +if (!ret) + handle->file_state =TRACECMD_FILE_CMD_LINES ; +return ret; } struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus,
Signature · 1 line
2.30.2
PATCH 4/10 trace-cmd library: Read compressed trace file
In reply to Tzvetomir Stoyanov (VMware)If a trace file version 7 is detected, read compresses sections of it. Read the compression header, check if the comporession algorithm and version, used to compress the file, are supported and use it to uncompress these secions from the file:
- ftrace events format
- format of recorded events
- information of the mapping of function addresses to the function names
- trace_printk() format strings
- information of the mapping a PID to a process name
--- lib/trace-cmd/trace-input.c | 293 +++++++++++++++++++++++++++--------- 1 file changed, 221 insertions(+), 72 deletions(-)
lib/trace-cmd/trace-input.c +221 -72
@@ -135,6 +135,11 @@ struct tracecmd_input {long long ts_offset;struct tsc2nsec tsc_calc; +struct tracecmd_compress_proto *z_proto; +char *z_buffer; +unsigned long z_buffer_size; +unsigned long z_pointer; +struct host_trace_info host;double ts2secs;char * cpustats;
@@ -254,12 +259,52 @@ static ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size)return tot; } +static ssize_t do_read_compressed (struct tracecmd_input *handle,void *data,size_t size) +{ +int ret; +int s; + +if (handle->z_buffer) { +if (handle->z_pointer + size > handle->z_buffer_size) + s = handle->z_buffer_size - handle->z_pointer; +else + s = size; +memcpy (data, handle->z_buffer + handle->z_pointer, s); + handle->z_pointer += s; + ret = s; + }else { + ret =do_read (handle, data, size); + } + +return ret; +} + +static int do_lseek (struct tracecmd_input *handle,int offset,int whence) +{ +int ret; + +if (handle->z_buffer) { +if (whence !=SEEK_CUR ) +return -1 ; +if (offset <0 && handle->z_pointer < (-offset)) +return -1 ; +if (offset >0 && handle->z_pointer + offset > handle->z_buffer_size) +return -1 ; + handle->z_pointer += offset; + ret =0 ; + }else { + ret =lseek (handle->fd, offset, whence); + } + +return ret; +} +static ssize_t do_read_check (struct tracecmd_input *handle,void *data,size_t size) {ssize_t ret; - ret =do_read (handle, data, size); + ret =do_read_compressed (handle, data, size);if (ret <0 )return ret;if (ret != size)
@@ -277,7 +322,7 @@ static char *read_string(struct tracecmd_input *handle)ssize_t r;for (;;) { - r =do_read (handle, buf,BUFSIZ ); + r =do_read_compressed (handle, buf,BUFSIZ );if (r <0 ) goto fail;if (!r)
@@ -306,7 +351,7 @@ static char *read_string(struct tracecmd_input *handle) }/* move the file descriptor to the end of the string */ - r =lseek (handle->fd, -(r - (i+1 )),SEEK_CUR ); + r =do_lseek (handle, -(r - (i+1 )),SEEK_CUR );if (r <0 ) goto fail;
@@ -358,6 +403,54 @@ static int read8(struct tracecmd_input *handle, unsigned long long *size)return 0 ; } +static void uncompress_reset (struct tracecmd_input *handle) +{ +free (handle->z_buffer); + handle->z_buffer =NULL ; + handle->z_buffer_size =0 ; + handle->z_pointer =0 ; +} + +static int uncompress_block (struct tracecmd_input *handle) +{ +unsigned int s_compressed; +unsigned int s_uncompressed; +char *bytes =NULL ; +int ret; + +if (handle->file_version <7 || !handle->z_proto) +return 0 ; +uncompress_reset (handle); + +if (read4 (handle, &s_compressed) <0 ) +return -1 ; +if (read4 (handle, &s_uncompressed) <0 ) +return -1 ; + + handle->z_buffer =malloc (s_uncompressed); +if (!handle->z_buffer) +return -1 ; + bytes =malloc (s_compressed); +if (!bytes) + goto error; + +if (do_read (handle, bytes, s_compressed) != s_compressed) + goto error; + ret =tracecmd_uncompress_data (handle->z_proto, bytes, s_compressed, + handle->z_buffer, &s_uncompressed); +if (ret) + goto error; +free (bytes); + handle->z_buffer_size = s_uncompressed; + handle->z_pointer =0 ; +return 0 ; +error: +uncompress_reset (handle); +free (bytes); +return -1 ; + +} +static int read_header_files (struct tracecmd_input *handle) {struct tep_handle *pevent = handle->pevent;
@@ -601,34 +694,40 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex) } } -if (read4 (handle, &count) <0 ) +if (uncompress_block (handle))return -1 ; + ret =read4 (handle, &count); +if (ret <0 ) + goto out; +for (i =0 ; i < count; i++) { -if (read8 (handle, &size) <0 ) -return -1 ; + ret =read8 (handle, &size); +if (ret <0 ) + goto out; ret =read_ftrace_file (handle, size, print_all, ereg);if (ret <0 ) -return -1 ; + goto out; } handle->event_files_start =lseek64 (handle->fd,0 ,SEEK_CUR ); + handle->file_state =TRACECMD_FILE_FTRACE_EVENTS ; + ret =0 ; +out:if (sreg) {regfree (sreg);regfree (ereg); } - - handle->file_state =TRACECMD_FILE_FTRACE_EVENTS ; - -return 0 ; +uncompress_reset (handle); +return ret; }static int read_event_files (struct tracecmd_input *handle,const char *regex) {unsigned long long size; -char *system; +char *system =NULL ;regex_t spreg;regex_t epreg;regex_t *sreg =NULL ;
@@ -653,13 +752,19 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex)return -1 ; } -if (read4 (handle, &systems) <0 ) +if (uncompress_block (handle))return -1 ; + ret =read4 (handle, &systems); +if (ret <0 ) + goto out; +for (i =0 ; i < systems; i++) { system =read_string (handle); -if (!system) -return -1 ; +if (!system) { + ret =-1 ; + goto out; + } sys_printed =0 ; print_all =0 ;
@@ -686,103 +791,117 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex) } } -if (read4 (handle, &count) <0 ) - goto failed; + ret =read4 (handle, &count); +if (ret <0 ) + goto out;for (x=0 ; x < count; x++) { -if (read8 (handle, &size) <0 ) - goto failed; + ret =read8 (handle, &size); +if (ret <0 ) + goto out; ret =read_event_file (handle, system, size, print_all, &sys_printed, reg);if (ret <0 ) - goto failed; + goto out; }free (system); - } - -if (sreg) { -regfree (sreg); -regfree (ereg); + system =NULL ; } handle->file_state =TRACECMD_FILE_ALL_EVENTS ; - -return 0 ; - - failed: + ret =0 ; + out: +uncompress_reset (handle);if (sreg) {regfree (sreg);regfree (ereg); }free (system); -return -1 ; +return ret; }static int read_proc_kallsyms (struct tracecmd_input *handle) { -struct tep_handle *pevent = handle->pevent; +struct tep_handle *tep = handle->pevent;unsigned int size; -char *buf; +char *buf =NULL ; +int ret;if (handle->file_state >=TRACECMD_FILE_KALLSYMS )return 0 ; -if (read4 (handle, &size) <0 ) +if (uncompress_block (handle))return -1 ; -if (!size) -return 0 ;/* OK? */ - buf =malloc (size+1 ); -if (!buf) -return -1 ; -if (do_read_check (handle, buf, size)){ -free (buf); -return -1 ; + ret =read4 (handle, &size); +if (ret <0 ) + goto out; +if (!size) { + handle->file_state =TRACECMD_FILE_KALLSYMS ; + goto out;/* OK? */ } - buf[size] =0 ; - -tep_parse_kallsyms (pevent, buf); -free (buf); + buf =malloc (size+1 ); +if (!buf) { + ret =-1 ; + goto out; + } + ret =do_read_check (handle, buf, size); +if (ret <0 ) + goto out; + buf[size] =0 ; +tep_parse_kallsyms (tep, buf); handle->file_state =TRACECMD_FILE_KALLSYMS ; - -return 0 ; + ret =0 ; +out: +free (buf); +uncompress_reset (handle); +return ret; }static int read_ftrace_printk (struct tracecmd_input *handle) {unsigned int size; -char *buf; +char *buf =NULL ; +int ret;if (handle->file_state >=TRACECMD_FILE_PRINTK )return 0 ; -if (read4 (handle, &size) <0 ) +if (uncompress_block (handle))return -1 ; -if (!size) -return 0 ;/* OK? */ + + ret =read4 (handle, &size); +if (ret <0 ) + goto out; +if (!size) { + handle->file_state =TRACECMD_FILE_PRINTK ; + goto out;/* OK? */ + } buf =malloc (size +1 ); -if (!buf) -return -1 ; -if (do_read_check (handle, buf, size)) { -free (buf); -return -1 ; +if (!buf) { + ret =-1 ; + goto out; } + ret =do_read_check (handle, buf, size); +if (ret <0 ) + goto out; buf[size] =0 ;tep_parse_printk_formats (handle->pevent, buf); - -free (buf); - handle->file_state =TRACECMD_FILE_PRINTK ; + ret =0 ; -return 0 ; +out: +free (buf); +uncompress_reset (handle); +return ret; }static int read_and_parse_cmdlines (struct tracecmd_input *handle);
@@ -2962,20 +3081,30 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle) {struct tep_handle *pevent = handle->pevent;unsigned long long size; -char *cmdlines; +char *cmdlines =NULL ; +int ret;if (handle->file_state >=TRACECMD_FILE_CMD_LINES )return 0 ; -if (read_data_and_size (handle, &cmdlines, &size) <0 ) +if (uncompress_block (handle))return -1 ; + + ret =read_data_and_size (handle, &cmdlines, &size); +if (ret <0 ) + goto out; +if (!size) { + handle->file_state =TRACECMD_FILE_CMD_LINES ; + goto out; + } cmdlines[size] =0 ;tep_parse_saved_cmdlines (pevent, cmdlines); -free (cmdlines); - handle->file_state =TRACECMD_FILE_CMD_LINES ; - -return 0 ; + ret =0 ; +out: +free (cmdlines); +uncompress_reset (handle); +return ret; }static void extract_trace_clock (struct tracecmd_input *handle,char *line)
@@ -3256,7 +3385,8 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)struct tracecmd_input *handle;char test[] =TRACECMD_MAGIC ;unsigned int page_size; -char *version; +char *str =NULL ; +char *zver;char buf[BUFSIZ ];unsigned long ver;
@@ -3279,11 +3409,11 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)if (memcmp (buf,"tracing" ,7 ) !=0 ) goto failed_read; - version =read_string (handle); -if (!version) + str =read_string (handle); +if (!str) goto failed_read; -pr_stat ("version = %s\n" , version); - ver =strtol (version,NULL ,10 ); +pr_stat ("version = %s\n" , str); + ver =strtol (str,NULL ,10 );if (!ver && errno) goto failed_read;if (!tracecmd_is_version_supported (ver)) {
@@ -3291,7 +3421,8 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) goto failed_read; } handle->file_version = ver; -free (version); +free (str); + str =NULL ;if (do_read_check (handle, buf,1 )) goto failed_read;
@@ -3325,11 +3456,29 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) handle->header_files_start =lseek64 (handle->fd, handle->header_files_start,SEEK_SET ); +if (handle->file_version >=7 ) { + str =read_string (handle); +if (!str) + goto failed_read; + zver =strchr (str,' ' ); +if (!zver) + goto failed_read; + *zver ='\0' ; + handle->z_proto =tracecmd_compress_proto_get (str, zver +1 ); +if (!handle->z_proto) { +tracecmd_warning ("Unsupported file compression %s %s" , str, zver +1 ); + goto failed_read; + } +free (str); + str =NULL ; + } + handle->file_state =TRACECMD_FILE_INIT ;return handle; failed_read: +free (str);free (handle);return NULL ;
Signature · 1 line
2.30.2
PATCH 5/10 trace-cmd library: Add new API to get compression of input handler
In reply to Tzvetomir Stoyanov (VMware)The new API returns a handler to compression algorithm, used to compress the trace file asociated with given input file handler:
tracecmd_get_file_comperssion()
--- lib/trace-cmd/include/private/trace-cmd-private.h | 2 ++ lib/trace-cmd/trace-input.c | 11 +++++++++++ 2 files changed, 13 insertions(+)
lib/trace-cmd/include/private/trace-cmd-private.h +2 -0
@@ -236,6 +236,8 @@ unsigned long long tracecmd_get_cursor(struct tracecmd_input *handle, int cpu);unsigned long tracecmd_get_file_version (struct tracecmd_input *handle); +struct tracecmd_compress_proto * +tracecmd_get_file_comperssion (struct tracecmd_input *handle);int tracecmd_ftrace_overrides (struct tracecmd_input *handle,struct tracecmd_ftrace *finfo);bool tracecmd_get_use_trace_clock (struct tracecmd_input *handle);
lib/trace-cmd/trace-input.c +11 -0
@@ -4192,6 +4192,17 @@ unsigned long tracecmd_get_file_version(struct tracecmd_input *handle)return handle->file_version; } +/** +* tracecmd_get_file_comperssion - return a handler to compression protocol, +* used to compress the trace file +* @handle: input handle for the trace.dat file +*/ +struct tracecmd_compress_proto * +tracecmd_get_file_comperssion (struct tracecmd_input *handle) +{ +return handle->z_proto; +} +/** * tracecmd_get_use_trace_clock - return use_trace_clock * @handle: input handle for the trace.dat file
Signature · 1 line
2.30.2
PATCH 6/10 trace-cmd library: Inherit compression algorithm from input file
In reply to Tzvetomir Stoyanov (VMware)When a new trace file output handler is allocated, based on given trace file input handler - use the same compression algorithm.
--- lib/trace-cmd/trace-output.c | 2 ++ 1 file changed, 2 insertions(+)
lib/trace-cmd/trace-output.c +2 -0
@@ -1026,6 +1026,7 @@ static int select_file_version(struct tracecmd_output *handle, struct tracecmd_i {if (ihandle) { handle->file_version =tracecmd_get_file_version (ihandle); + handle->compress_proto =tracecmd_get_file_comperssion (ihandle); }else if (file_version >0 ) { handle->file_version = file_version; }else {
@@ -1769,6 +1770,7 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd)tep_ref (handle->pevent); handle->page_size =tracecmd_page_size (ihandle); handle->file_version =tracecmd_get_file_version (ihandle); + handle->compress_proto =tracecmd_get_file_comperssion (ihandle);list_head_init (&handle->options);tracecmd_close (ihandle);
Signature · 1 line
2.30.2
PATCH 7/10 trace-cmd library: Extend the create file APIs to support different compression
In reply to Tzvetomir Stoyanov (VMware)Added additional parameter for file compression to all trace-cmd library APIs for creating a new trace file. The caller could specify what compression algorithm should be used when creating a new trace file:
tracecmd_create_file_latency
tracecmd_create_init_file_glob
tracecmd_create_init_fd_glob
tracecmd_create_init_fd_msg
tracecmd_create_init_file tracecmd_create_init_file_override
--- .../include/private/trace-cmd-private.h | 15 ++-- lib/trace-cmd/trace-output.c | 80 ++++++++++++++----- tracecmd/trace-record.c | 10 +-- tracecmd/trace-restore.c | 4 +- 4 files changed, 74 insertions(+), 35 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +9 -6
@@ -272,24 +272,27 @@ struct tracecmd_option;struct tracecmd_msg_handle ;struct tracecmd_output *tracecmd_create_file_latency (const char *output_file,int cpus, -unsigned long file_version); +unsigned long file_version, +const char *compression);struct tracecmd_output *tracecmd_create_init_file_glob (const char *output_file,struct tracecmd_event_list *list, -unsigned long file_version); +unsigned long file_version,const char *compression);struct tracecmd_output *tracecmd_create_init_fd (int fd);struct tracecmd_output *tracecmd_create_init_fd_glob (int fd,struct tracecmd_event_list *list, -unsigned long file_version); +unsigned long file_version,const char *compression);struct tracecmd_output *tracecmd_create_init_fd_msg (struct tracecmd_msg_handle *msg_handle,struct tracecmd_event_list *list, -unsigned long file_version); +unsigned long file_version,const char *compression);struct tracecmd_output *tracecmd_create_init_file (const char *output_file, -unsigned long file_version); +unsigned long file_version, +const char *compression);struct tracecmd_output *tracecmd_create_init_file_override (const char *output_file,const char *tracing_dir,const char *kallsyms, -unsigned long file_version); +unsigned long file_version, +const char *compression);struct tracecmd_option *tracecmd_add_option (struct tracecmd_output *handle,unsigned short id,int size,const void *data);
lib/trace-cmd/trace-output.c +58 -22
171 lines not on this page · raw message
tracecmd/trace-record.c +5 -5
@@ -3647,7 +3647,7 @@ setup_connection(struct buffer_instance *instance, struct common_record_context/* Now create the handle through this socket */ if (msg_handle->version ==V3_PROTOCOL ) { network_handle =tracecmd_create_init_fd_msg (msg_handle, listed_events, - ctx->file_version); + ctx->file_version,NULL );if (!network_handle) goto error;tracecmd_set_quiet (network_handle, quiet);
@@ -3666,7 +3666,7 @@ setup_connection(struct buffer_instance *instance, struct common_record_context goto error; }else { network_handle =tracecmd_create_init_fd_glob (msg_handle->fd, listed_events, - ctx->file_version); + ctx->file_version,NULL );if (!network_handle) goto error;tracecmd_set_quiet (network_handle, quiet);
@@ -3854,7 +3854,7 @@ static void setup_agent(struct buffer_instance *instance,struct tracecmd_output *network_handle; network_handle =tracecmd_create_init_fd_msg (instance->msg_handle, listed_events, - ctx->file_version); + ctx->file_version,NULL );add_options (network_handle, ctx);tracecmd_write_cmdlines (network_handle);tracecmd_write_cpus (network_handle, instance->cpu_count);
@@ -4247,7 +4247,7 @@ static void record_data(struct common_record_context *ctx)if (latency) { handle =tracecmd_create_file_latency (ctx->output, local_cpu_count, - ctx->file_version); + ctx->file_version,NULL );tracecmd_set_quiet (handle, quiet); }else {if (!local_cpu_count)
@@ -4279,7 +4279,7 @@ static void record_data(struct common_record_context *ctx) } handle =tracecmd_create_init_file_glob (ctx->output, listed_events, - ctx->file_version); + ctx->file_version,NULL );if (!handle)die ("Error creating output file" );tracecmd_set_quiet (handle, quiet);
tracecmd/trace-restore.c +2 -2
@@ -91,7 +91,7 @@ void trace_restore (int argc, char **argv) } handle =tracecmd_create_init_file_override (output, tracing_dir, - kallsyms,0 ); + kallsyms,0 ,NULL );if (!handle)die ("Unabled to create output file %s" , output);if (tracecmd_write_cmdlines (handle) <0 )
@@ -128,7 +128,7 @@ void trace_restore (int argc, char **argv) handle =tracecmd_copy (ihandle, output);tracecmd_close (ihandle); }else - handle =tracecmd_create_init_file (output,0 ); + handle =tracecmd_create_init_file (output,0 ,NULL );if (!handle)die ("error writing to %s" , output);
Signature · 1 line
2.30.2
PATCH 8/10 trace-cmd record: Add new parameter --compression
In reply to Tzvetomir Stoyanov (VMware)Added a new optional parameter to "trace-cmd record", can be used to select the desired compression algorithm for the trace output file.
--- tracecmd/trace-record.c | 18 +++++++++++++----- tracecmd/trace-usage.c | 1 + 2 files changed, 14 insertions(+), 5 deletions(-)
tracecmd/trace-record.c +13 -5
@@ -199,6 +199,7 @@ struct common_record_context {char *date2ts;char *user;const char *clock; +const char *compression;unsigned long file_version;struct tsc_nsec tsc2nsec;int data_flags;
@@ -3647,7 +3648,7 @@ setup_connection(struct buffer_instance *instance, struct common_record_context/* Now create the handle through this socket */ if (msg_handle->version ==V3_PROTOCOL ) { network_handle =tracecmd_create_init_fd_msg (msg_handle, listed_events, - ctx->file_version,NULL ); + ctx->file_version, ctx->compression);if (!network_handle) goto error;tracecmd_set_quiet (network_handle, quiet);
@@ -3666,7 +3667,7 @@ setup_connection(struct buffer_instance *instance, struct common_record_context goto error; }else { network_handle =tracecmd_create_init_fd_glob (msg_handle->fd, listed_events, - ctx->file_version,NULL ); + ctx->file_version, ctx->compression);if (!network_handle) goto error;tracecmd_set_quiet (network_handle, quiet);
@@ -3854,7 +3855,7 @@ static void setup_agent(struct buffer_instance *instance,struct tracecmd_output *network_handle; network_handle =tracecmd_create_init_fd_msg (instance->msg_handle, listed_events, - ctx->file_version,NULL ); + ctx->file_version, ctx->compression);add_options (network_handle, ctx);tracecmd_write_cmdlines (network_handle);tracecmd_write_cpus (network_handle, instance->cpu_count);
@@ -4247,7 +4248,7 @@ static void record_data(struct common_record_context *ctx)if (latency) { handle =tracecmd_create_file_latency (ctx->output, local_cpu_count, - ctx->file_version,NULL ); + ctx->file_version, ctx->compression);tracecmd_set_quiet (handle, quiet); }else {if (!local_cpu_count)
@@ -4279,7 +4280,7 @@ static void record_data(struct common_record_context *ctx) } handle =tracecmd_create_init_file_glob (ctx->output, listed_events, - ctx->file_version,NULL ); + ctx->file_version, ctx->compression);if (!handle)die ("Error creating output file" );tracecmd_set_quiet (handle, quiet);
@@ -5505,6 +5506,7 @@ void init_top_instance(void) }enum { + OPT_comporession =238 , OPT_file_version =239 , OPT_tsc2nsec =240 , OPT_fork =241 ,
@@ -5941,6 +5943,7 @@ static void parse_record_options(int argc, {"fork", no_argument, NULL, OPT_fork}, {"tsc2nsec", no_argument, NULL, OPT_tsc2nsec}, {"file-version", required_argument, NULL, OPT_file_version}, + {"compression", required_argument, NULL, OPT_comporession}, {NULL, 0, NULL, 0} };
@@ -6367,6 +6370,11 @@ static void parse_record_options(int argc,if (!tracecmd_is_version_supported (ctx->file_version))die ("File version %d is not supported" , ctx->file_version);break ; +case OPT_comporession: + ctx->compression =strdup (optarg); +if (!tracecmd_compress_proto_get (ctx->compression,NULL )) +die ("Compression algorithm %s is not supported" , ctx->compression); +break ;case OPT_quiet:case 'q' : quiet = true;
tracecmd/trace-usage.c +1 -0
@@ -69,6 +69,7 @@ static struct usage_help usage_help[] = {" If 0 is specified, no loop is performed - timestamps offset is calculated only twice," " at the beginnig and at the end of the trace\n" " --file-version select the desired version of the trace output file\n" +" --compression select the desired compression algorithm for the trace output file\n" }, { "set",
Signature · 1 line
2.30.2
PATCH 9/10 trace-cmd dump: Add support for trace files version 7
In reply to Tzvetomir Stoyanov (VMware)Added support to read and dump information of trace files version 7.
--- tracecmd/trace-dump.c | 164 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 144 insertions(+), 20 deletions(-)
tracecmd/trace-dump.c +144 -20
@@ -26,6 +26,12 @@static struct tep_handle *tep;static unsigned int trace_cpus;static int has_clock; +static unsigned long file_version; + +static struct tracecmd_compress_proto *z_handle; +static char *z_buffer; +static unsigned long z_buffer_size; +static unsigned long z_pointer;enum dump_items {SUMMARY = (1 <<0 ),
@@ -52,46 +58,72 @@ enum dump_items verbosity; tracecmd_plog(fmt, ##__VA_ARGS__); \ }while (0 ) -static int read_file_string(int fd, char *dst, int len) +static int read_fd(int fd, char *dst, int len) {size_t size =0 ;int r;do { - r =read (fd, dst+size,1 ); + r =read (fd, dst+size, len);if (r >0 ) { - size++; - len--; + size += r; + len -= r; }else break ; -if (!dst[size -1 ]) -break ; - }while (r >0 && len); + }while (r >0 ); -if (!size || dst[size -1 ]) +if (len)return -1 ; -return 0 ; +return size; } -static int read_file_bytes (int fd,char *dst,int len) + +static int read_compressed (int fd,char *dst,int len) +{ +int ret; + +if (z_buffer) { +if (z_pointer + len > z_buffer_size) +return -1 ; +memcpy (dst, z_buffer + z_pointer, len); + z_pointer += len; + ret = len; + }else { + ret =read_fd (fd, dst, len); + } + +return ret; +} + +static int read_file_string (int fd,char *dst,int len) {size_t size =0 ;int r;do { - r =read (fd, dst+size, len); + r =read_compressed (fd, dst+size,1 );if (r >0 ) { - size += r; - len -= r; + size++; + len--; }else break ; - }while (r >0 ); +if (!dst[size -1 ]) +break ; + }while (r >0 && len); -if (len) +if (!size || dst[size -1 ])return -1 ;return 0 ; } +static int read_file_bytes (int fd,char *dst,int len) +{ +int ret; + + ret =read_compressed (fd, dst, len); +return ret <0 ? ret :0 ; +} +static void read_dump_string (int fd,int size,enum dump_items id) {char buf[DUMP_SIZE ];
@@ -146,7 +178,6 @@ static void dump_initial_format(int fd)char magic[] =TRACECMD_MAGIC ;char buf[DUMP_SIZE ];int val4; -unsigned long ver;do_print (SUMMARY ,"\t[Initial format]\n" );
@@ -168,11 +199,11 @@ static void dump_initial_format(int fd)die ("no version string" );do_print (SUMMARY ,"\t\t%s\t[Version]\n" , buf); - ver =strtol (buf,NULL ,10 ); -if (!ver && errno) + file_version =strtol (buf,NULL ,10 ); +if (!file_version && errno)die ("Invalid file version string %s" , buf); -if (!tracecmd_is_version_supported (ver)) -die ("Unsupported file version %lu" , ver); +if (!tracecmd_is_version_supported (file_version)) +die ("Unsupported file version %lu" , file_version);/* get file endianness*/ if (read_file_bytes (fd, buf,1 ))
@@ -192,6 +223,29 @@ static void dump_initial_format(int fd)do_print (SUMMARY ,"\t\t%d\t[Page size, bytes]\n" , val4); } +static void dump_compress (int fd) +{ +char compr[DUMP_SIZE ]; +char *ver =NULL ; + +if (file_version <7 ) +return ; + +/* get compression header */ +if (read_file_string (fd, compr,DUMP_SIZE )) +die ("no compression header" ); + ver =strchr (compr,' ' ); +if (!ver) +die ("no compression version" ); + *ver ='\0' ; +do_print ((SUMMARY ),"\t\t%s\t[Compression algorithm]\n" , compr); +do_print ((SUMMARY ),"\t\t%s\t[Compression version]\n" , ver +1 ); + + z_handle =tracecmd_compress_proto_get (compr, ver +1 ); +if (!z_handle) +die ("cannot uncomress the file" ); +} +static void dump_header_page (int fd) {unsigned long long size;
@@ -234,11 +288,60 @@ static void dump_header_event(int fd)read_dump_string (fd, size,HEAD_EVENT ); } +static void uncompress_reset (void ) +{ +free (z_buffer); + z_buffer =NULL ; + z_buffer_size =0 ; + z_pointer =0 ; +} + +static int uncompress_block (int fd) +{ +unsigned int s_compressed; +unsigned int s_uncompressed; +char *bytes =NULL ; +int ret; + +if (file_version <7 || !z_handle) +return 0 ; +uncompress_reset (); +if (read_file_number (fd, &s_compressed,4 )) +return -1 ; +if (read_file_number (fd, &s_uncompressed,4 )) +return -1 ; + + z_buffer =malloc (s_uncompressed); +if (!z_buffer) +return -1 ; + bytes =malloc (s_compressed); +if (!bytes) + goto error; + +if (read_fd (fd, bytes, s_compressed) <0 ) + goto error; + ret =tracecmd_uncompress_data (z_handle, bytes, s_compressed, + z_buffer, &s_uncompressed); +if (ret) + goto error; +free (bytes); + z_buffer_size = s_uncompressed; + z_pointer =0 ; +return 0 ; +error: +uncompress_reset (); +free (bytes); +return -1 ; + +} +static void dump_ftrace_events_format (int fd) {unsigned long long size;unsigned int count; +if (uncompress_block (fd)) +die ("cannot uncopress file block" );do_print ((SUMMARY |FTRACE_FORMAT ),"\t[Ftrace format, " );if (read_file_number (fd, &count,4 ))die ("cannot read the count of the ftrace events" );
@@ -251,6 +354,7 @@ static void dump_ftrace_events_format(int fd)read_dump_string (fd, size,FTRACE_FORMAT ); count--; } +uncompress_reset (); }static void dump_events_format (int fd)
@@ -262,6 +366,9 @@ static void dump_events_format(int fd)do_print ((SUMMARY |EVENT_FORMAT |EVENT_SYSTEMS ),"\t[Events format, " ); +if (uncompress_block (fd)) +die ("cannot uncopress file block" ); +if (read_file_number (fd, &systems,4 ))die ("cannot read the count of the event systems" );
@@ -284,6 +391,7 @@ static void dump_events_format(int fd) } systems--; } +uncompress_reset (); }static void dump_kallsyms (int fd)
@@ -292,12 +400,17 @@ static void dump_kallsyms(int fd)do_print ((SUMMARY |KALLSYMS ),"\t[Kallsyms, " ); +if (uncompress_block (fd)) +die ("cannot uncopress file block" ); +if (read_file_number (fd, &size,4 ))die ("cannot read the size of the kallsyms" );do_print ((SUMMARY |KALLSYMS ),"%d bytes]\n" , size);read_dump_string (fd, size,KALLSYMS ); + +uncompress_reset (); }static void dump_printk (int fd)
@@ -306,12 +419,17 @@ static void dump_printk(int fd)do_print ((SUMMARY |TRACE_PRINTK ),"\t[Trace printk, " ); +if (uncompress_block (fd)) +die ("cannot uncopress file block" ); +if (read_file_number (fd, &size,4 ))die ("cannot read the size of the trace printk" );do_print ((SUMMARY |TRACE_PRINTK ),"%d bytes]\n" , size);read_dump_string (fd, size,TRACE_PRINTK ); + +uncompress_reset (); }static void dump_cmdlines (int fd)
@@ -320,12 +438,17 @@ static void dump_cmdlines(int fd)do_print ((SUMMARY |CMDLINES ),"\t[Saved command lines, " ); +if (uncompress_block (fd)) +die ("cannot uncopress file block" ); +if (read_file_number (fd, &size,8 ))die ("cannot read the size of the saved command lines" );do_print ((SUMMARY |CMDLINES ),"%d bytes]\n" , size);read_dump_string (fd, size,CMDLINES ); + +uncompress_reset (); }static void dump_cpus_count (int fd)
@@ -669,6 +792,7 @@ static void dump_file(const char *file)do_print (SUMMARY ,"\n Tracing meta data in file %s:\n" , file);dump_initial_format (fd); +dump_compress (fd);dump_header_page (fd);dump_header_event (fd);dump_ftrace_events_format (fd);
Signature · 1 line
2.30.2
PATCH 10/10 trace-cmd library: Add support for zlib compression library
In reply to Tzvetomir Stoyanov (VMware)If libz is available, use that library to provide compression support for the trace file compression. The library is detected runtime.
--- lib/trace-cmd/Makefile | 10 ++ lib/trace-cmd/include/trace-cmd-local.h | 5 + lib/trace-cmd/trace-compress-zlib.c | 172 ++++++++++++++++++++++++ lib/trace-cmd/trace-compress.c | 6 +- 4 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 lib/trace-cmd/trace-compress-zlib.c
lib/trace-cmd/Makefile +10 -0
@@ -7,6 +7,13 @@ ldir:=$(src)/lib/trace-cmd DEFAULT_TARGET = $(LIBTRACECMD_STATIC) +pound := \# +ZLIB_INSTALLED := $(shell if (printf "$(pound)include <zlib.h>\n void main(){deflateInit(NULL, Z_BEST_COMPRESSION);}" | $(CC) -o /dev/null -x c - -lz >/dev/null 2>&1) ; then echo 1; else echo 0 ; fi) +ifeq ($(ZLIB_INSTALLED), 1) +CFLAGS += -DHAVE_ZLIB +$(info Have zlib compression support) +endif + OBJS = OBJS += trace-hash.o OBJS += trace-hooks.o
@@ -26,6 +33,9 @@ OBJS += trace-timesync-ptp.o OBJS += trace-timesync-kvm.o endif OBJS += trace-compress.o +ifeq ($(ZLIB_INSTALLED), 1) +OBJS += trace-compress-zlib.o +endif # Additional util objects OBJS += trace-blk-hack.o
lib/trace-cmd/include/trace-cmd-local.h +5 -0
@@ -30,6 +30,11 @@ void tracecmd_fatal(const char *fmt, ...);#endif #endif +#ifdef HAVE_ZLIB +int tracecmd_zlib_init (void ); +void tracecmd_zlib_free (void ); +#endif +int tracecmd_compress_init (void );void tracecmd_compress_free (void );
lib/trace-cmd/trace-compress-zlib.c new file +172 -0
172 lines not on this page · raw message
lib/trace-cmd/trace-compress.c +4 -2
@@ -38,8 +38,10 @@ int tracecmd_compress_init(void)gettimeofday (&time,NULL );srand ((time.tv_sec *1000 ) + (time.tv_usec /1000 )); -/* toDo: add here initialization of compression protocols */ - +#ifdef HAVE_ZLIB +if (!tracecmd_zlib_init ()) + count++; +#endif if (!count)tracecmd_warning ("No compression support available" );
Signature · 1 line
2.30.2
Quoted 29 lines · On Thu, 22 Apr 2021 10:38:52 +0300 "Tzvetomir Stoyanov (VMware)"…
A new PoC implementation for adding a compression to trace file version 7. A basic infrastructure for compression support is added into the trace-cmd library. The zlib is used for compression, but more libraries and algorithms can be added. Only part of the trace file metadata is compressed:
- ftrace events format
- format of recorded events
- information about the mapping of function addresses to the function names
-trace_printk()format strings
- information of the mapping a PID to a process nameNote: not all trace-cmd commands are tested with these changes. These are verified to work with compressed trace files:
trace-cmd record
trace-cmd report
trace-cmd dumpTodo list, in order to have complete trace file compression:
- Compress trace file options.
- Compress trace data.
- Add support for more compression libraries.
- Add new trace-cmd command to convert trace files from version 6 to version 7 and vise versa.
- Add compression support to all trace-cmd commands.
- Update trace-cmd documentation.This patch set depends on "[PATCH 0/6] Bump trace file version" and should be applied on top of it.
https://lore.kernel.org/linux-trace-devel/[email protected]/
Quoted 12 lines
Tzvetomir Stoyanov (VMware) (10):
trace-cmd: Add APIs for library initialization and free trace-cmd library: Add support for compression algorithms trace-cmd library: Compress part of the trace file trace-cmd library: Read compressed trace file
trace-cmd library: Add new API to get compression of input handler trace-cmd library: Inherit compression algorithm from input file trace-cmd library: Extend the create file APIs to support different
compression
trace-cmd record: Add new parameter --compression trace-cmd dump: Add support for trace files version 7 trace-cmd library: Add support for zlib compression library
I'm not able to apply these patches as I'm getting conflicts from your previous series that bumps the version number, as if what you sent to the mailing list was not what you have in your git repo.
Can you please resend the version update patch series.
-- Steve
Quoted 18 lines
lib/trace-cmd/Makefile | 11 + .../include/private/trace-cmd-private.h | 42 ++- lib/trace-cmd/include/trace-cmd-local.h | 7 + lib/trace-cmd/trace-compress-zlib.c | 172 ++++++++++ lib/trace-cmd/trace-compress.c | 289 +++++++++++++++++ lib/trace-cmd/trace-input.c | 304 +++++++++++++----- lib/trace-cmd/trace-output.c | 268 ++++++++++++--- lib/trace-cmd/trace-util.c | 12 + tracecmd/trace-cmd.c | 11 +- tracecmd/trace-dump.c | 164 ++++++++-- tracecmd/trace-record.c | 18 +- tracecmd/trace-restore.c | 4 +- tracecmd/trace-usage.c | 1 + 13 files changed, 1152 insertions(+), 151 deletions(-) create mode 100644 lib/trace-cmd/trace-compress-zlib.c create mode 100644 lib/trace-cmd/trace-compress.c
Quoted 46 lines · Steven Rostedt
Quoted 29 lines · On Thu, 22 Apr 2021 10:38:52 +0300 "Tzvetomir Stoyanov (VMware)"…
A new PoC implementation for adding a compression to trace file version 7. A basic infrastructure for compression support is added into the trace-cmd library. The zlib is used for compression, but more libraries and algorithms can be added. Only part of the trace file metadata is compressed:
- ftrace events format
- format of recorded events
- information about the mapping of function addresses to the function names
-trace_printk()format strings
- information of the mapping a PID to a process nameNote: not all trace-cmd commands are tested with these changes. These are verified to work with compressed trace files:
trace-cmd record
trace-cmd report
trace-cmd dumpTodo list, in order to have complete trace file compression:
- Compress trace file options.
- Compress trace data.
- Add support for more compression libraries.
- Add new trace-cmd command to convert trace files from version 6 to version 7 and vise versa.
- Add compression support to all trace-cmd commands.
- Update trace-cmd documentation.This patch set depends on "[PATCH 0/6] Bump trace file version" and should be applied on top of it.
https://lore.kernel.org/linux-trace-devel/[email protected]/Quoted 12 lines
Tzvetomir Stoyanov (VMware) (10):
trace-cmd: Add APIs for library initialization and free trace-cmd library: Add support for compression algorithms trace-cmd library: Compress part of the trace file trace-cmd library: Read compressed trace file
trace-cmd library: Add new API to get compression of input handler trace-cmd library: Inherit compression algorithm from input file trace-cmd library: Extend the create file APIs to support different
compression
trace-cmd record: Add new parameter --compression trace-cmd dump: Add support for trace files version 7 trace-cmd library: Add support for zlib compression library
Quoted 5 lines
I'm not able to apply these patches as I'm getting conflicts from your previous series that bumps the version number, as if what you sent to the mailing list was not what you have in your git repo.
Can you please resend the version update patch series.
The order of applying the changes should be:
1. [PATCH v2] trace-cmd: Check if file version is supported
https://lore.kernel.org/linux-trace-devel/[email protected]/
2. [PATCH 0/6] Bump trace file version
https://lore.kernel.org/linux-trace-devel/[email protected]/
3. [POC PATCH 00/10] Add trace file compression
https://lore.kernel.org/linux-trace-devel/[email protected]/
I wrote these dependencies in the cover-letters. BTW, I do not see
(2) in patchwork, only in the mailing list.
I'll send v2 of "Bump trace file version" including (1) in the patchset.
Quoted 23 lines
-- Steve
Quoted 18 lines
lib/trace-cmd/Makefile | 11 + .../include/private/trace-cmd-private.h | 42 ++- lib/trace-cmd/include/trace-cmd-local.h | 7 + lib/trace-cmd/trace-compress-zlib.c | 172 ++++++++++ lib/trace-cmd/trace-compress.c | 289 +++++++++++++++++ lib/trace-cmd/trace-input.c | 304 +++++++++++++----- lib/trace-cmd/trace-output.c | 268 ++++++++++++--- lib/trace-cmd/trace-util.c | 12 + tracecmd/trace-cmd.c | 11 +- tracecmd/trace-dump.c | 164 ++++++++-- tracecmd/trace-record.c | 18 +- tracecmd/trace-restore.c | 4 +- tracecmd/trace-usage.c | 1 + 13 files changed, 1152 insertions(+), 151 deletions(-) create mode 100644 lib/trace-cmd/trace-compress-zlib.c create mode 100644 lib/trace-cmd/trace-compress.c
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov VMware Open Source Technology Center
Quoted 9 lines · On Thu, 29 Apr 2021 06:51:59 +0300 Tzvetomir Stoyanov <[email protected]>…
The order of applying the changes should be:
1. [PATCH v2] trace-cmd: Check if file version is supported
https://lore.kernel.org/linux-trace-devel/[email protected]/
2. [PATCH 0/6] Bump trace file version
https://lore.kernel.org/linux-trace-devel/[email protected]/
3. [POC PATCH 00/10] Add trace file compression
https://lore.kernel.org/linux-trace-devel/[email protected]/I wrote these dependencies in the cover-letters. BTW, I do not see
Yeah, I see that. But I was using patchwork to read the files and not the email. But there is a way (not totally obvious) to read the cover letter from patchwork. (just found it now!)
Quoted 2 lines
(2) in patchwork, only in the mailing list.
I'll send v2 of "Bump trace file version" including (1) in the patchset.
As I stated in the other email. After I make comments, and expect a newer version, I'll set the older one to "changes needed", which makes it disappear from the default view. You can still see it if you deselect "Action Required".
-- Steve