Trace file version 7
Subsystems (2)
cover Trace file version 7
Introduce the next version of the trace-cmd trace file - 7. Major changes since version 6:
- New, flexible and extendable structure of the file.
- Optional compression of file metadata and tracing data.
By default, trace-cmd still uses the old version 6 when recording trace file. There are new options to force using the new version. A new "trace-cmd convert" sub-command is introduced, to convert files between different versions.
Known issues:
- "trace-cmd split" does not work with trace file version 7, if there are CPUs with empty trace data.
- "trace-cmd agent" has problems with compressed files
Tzvetomir Stoyanov (VMware) (87):
trace-cmd library: Read option id with correct endian trace-cmd report: Fix typos in error messages
tarce-cmd library: Fix version string memory leak trace-cmd library: Fixed a memory leak on input handler close trace-cmd library: Fix possible memory corruption on processing a
trace buffer
trace-cmd library: Add constructor and destructor trace-cmd library: Add cache functionality to network message handler trace-cmd library: Add support for compression algorithms trace-cmd list: Show supported compression algorithms trace-cmd library: Internal helpers for compressing data trace-cmd library: Internal helpers for uncompressing data trace-cmd library: Define trace file version 7
trace-cmd library: Refactor APIs for creating output handler trace-cmd library: Reuse within the library the function that checks
file state.
trace-cmd library: New API to get the version of output handler trace-cmd library: Inherit compression algorithm from input file trace-cmd library: New API to configure compression on an output
handler
trace-cmd record: Add compression to the trace context trace-cmd library: Write compression header in the trace file trace-cmd library: Compress part of the trace file trace-cmd library: Add internal helper functon for writing headers
before file sections
trace-cmd library: Write header before file sections trace-cmd library: Refactor the logic for writing trace data in the
file
trace-cmd library: Add local helper function for data compression trace-cmd library: Compress the trace data
tarce-cmd library: Add multiple options sections in trace file version
7
trace-cmd library: Do not write CPU count section in trace files
version 7
trace-cmd library: Move CPU flyrecord trace metadata into the buffer
option, for trace file version 7
trace-cmd record: Append trace options after the trace data are
written
trace-cmd library: Add section header before flyrecord trace data trace-cmd library: Fit CPU latency trace data in the new trace file
version 7 format
trace-cmd library: Do not write CPUs with empty trace data trace-cmd library: Add macro to check file state on reading trace-cmd library: Introduce sections in trace file reading logic trace-cmd library: Initialize internal sections database on file read trace-cmd library: Use sections database when reading parts of the
trace file
trace-cmd library: Set log size to the input tep handler when it is
read from the file
trace-cmd library: Fix possible memory leak in read_ftrace_files() trace-cmd library: Fix possible memory leak in read_event_files() trace-cmd library: Fix possible memory leak in read_proc_kallsyms() trace-cmd library: Fix possible memory leak in read_ftrace_printk() trace-cmd library: Fix possible memory leak in
read_and_parse_cmdlines()
trace-cmd library: Track maximum CPUs count in input handler trace-cmd library: Set input handler default values in allocation
function
trace-cmd library: Read headers from trace file version 7 tarce-cmd library: Do not use local variables when reading CPU stat
option
trace-cmd library: Read handle header and compression of the option
section
trace-cmd library: Read extended BUFFER option
trace-cmd library: Handle the extended DONE option trace-cmd library: Read compression header
trace-cmd library: Extend the input handler with trace data
decompression context
trace-cmd library: Initialize CPU data decompression logic trace-cmd library: Initialize CPU data for reading from version 7
trace files
trace-cmd library: Add logic for in-memory decompression trace-cmd library: Handle latency trace in version 7 files trace-cmd library: Handle buffer trace data init for version 7 files trace-cmd report: Use the new latency API to read data trace-cmd report: Close input file handlers on exit trace-cmd report: Do not print empty buffer name
trace-cmd report: Init the top trace instance earlier
trace-cmd: Call additional APIs when creating trace file trace-cmd dump: Add helpers for processing trace file version 7 trace-cmd dump: Print compression header
trace-cmd dump: Add helpers for processing trace file sections trace-cmd dump: Read recursively all options sections trace-cmd dump: Read extended BUFFER option
trace-cmd dump: Dump sections
trace-cmd dump: Dump trace file version 7
trace-cmd dump: Dump sections content
trace-cmd dump: Add new argument --sections
trace-cmd dump: Align better the output of flyrecord dump trace-cmd library: Add zlib compression algorithm trace-cmd library: Reuse local function that writes to output handler trace-cmd library: Use output handler when copying data from input
file
trace-cmd library: Handle version 7 files when copying headers between
files
tarce-cmd library: Copy CPU count between trace files tarce-cmd library: New API to copy buffer description between trace
files
tarce-cmd library: New API to copy options between trace files tarce-cmd library: New API to copy trace data between trace files trace-cmd library: Extend tracecmd_copy() API
trace-cmd library: Set correct CPU to the record, retrieved with
tracecmd_peek_data
trace-cmd: Add new subcommand "convert"
trace-cmd report: Add new parameters for version 7 trace files
trace-cmd: Update bash completion
tarce-cmd: Man page for "trace-cmd convert"
tarce-cmd: Update record man page
trace-cmd: Document trace file version 7
.../trace-cmd/trace-cmd-convert.1.txt | 65 +
Documentation/trace-cmd/trace-cmd-list.1.txt | 3 +
.../trace-cmd/trace-cmd-record.1.txt | 13 +
Documentation/trace-cmd/trace-cmd.1.txt | 4 +-
...e-cmd.dat.5.txt => trace-cmd.dat.v6.5.txt} | 15 +-
.../trace-cmd/trace-cmd.dat.v7.5.txt | 442 ++++
Makefile | 7 +
include/trace-cmd/trace-cmd.h | 5 +
lib/trace-cmd/Makefile | 8 +
.../include/private/trace-cmd-private.h | 115 +-
lib/trace-cmd/include/trace-cmd-local.h | 63 +-
lib/trace-cmd/trace-compress-zlib.c | 109 +
lib/trace-cmd/trace-compress.c | 910 +++++++
lib/trace-cmd/trace-input.c | 2130 ++++++++++++++---
lib/trace-cmd/trace-msg.c | 131 +-
lib/trace-cmd/trace-output.c | 1681 ++++++++++---
lib/trace-cmd/trace-util.c | 45 +-
tracecmd/Makefile | 5 +
tracecmd/include/trace-local.h | 2 +
tracecmd/trace-cmd.bash | 37 +
tracecmd/trace-cmd.c | 1 +
tracecmd/trace-convert.c | 106 +
tracecmd/trace-dump.c | 459 +++-
tracecmd/trace-list.c | 26 +
tracecmd/trace-listen.c | 8 +-
tracecmd/trace-read.c | 40 +-
tracecmd/trace-record.c | 141 +-
tracecmd/trace-restore.c | 37 +-
tracecmd/trace-split.c | 5 +-
tracecmd/trace-usage.c | 21 +-
30 files changed, 5723 insertions(+), 911 deletions(-)
create mode 100644 Documentation/trace-cmd/trace-cmd-convert.1.txt
rename Documentation/trace-cmd/{trace-cmd.dat.5.txt => trace-cmd.dat.v6.5.txt} (96%)
create mode 100644 Documentation/trace-cmd/trace-cmd.dat.v7.5.txt
create mode 100644 lib/trace-cmd/trace-compress-zlib.c
create mode 100644 lib/trace-cmd/trace-compress.c
create mode 100644 tracecmd/trace-convert.cSignature · 1 line
2.31.1
PATCH 1/87 trace-cmd library: Read option id with correct endian
The id of a trace option is 2 bytes short integer. When reading it from the trace file, use the tep handler associated with the file, if available, to convert the option with the correct endian order. A new helper function is introduced to read and convert 2 byte integer.
--- lib/trace-cmd/trace-input.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
lib/trace-cmd/trace-input.c +14 -4
@@ -336,6 +336,18 @@ static char *read_string(struct tracecmd_input *handle)return NULL ; } +static int read2 (struct tracecmd_input *handle,unsigned short *size) +{ +struct tep_handle *pevent = handle->pevent; +unsigned short data; + +if (do_read_check (handle, &data,2 )) +return -1 ; + + *size =tep_read_number (pevent, &data,2 ); +return 0 ; +} +static int read4 (struct tracecmd_input *handle,unsigned int *size) {struct tep_handle *pevent = handle->pevent;
@@ -2660,16 +2672,15 @@ static int handle_options(struct tracecmd_input *handle) handle->options_start =lseek64 (handle->fd,0 ,SEEK_CUR );for (;;) { -if (do_read_check (handle, &option,2 )) +if (read2 (handle, &option))return -1 ;if (option ==TRACECMD_OPTION_DONE )break ;/* next 4 bytes is the size of the option */ -if (do_read_check (handle, &size,4 )) +if (read4 (handle, &size))return -1 ; - size =tep_read_number (handle->pevent, &size,4 ); buf =malloc (size);if (!buf)return -ENOMEM ;
@@ -2827,7 +2838,6 @@ static int read_options_type(struct tracecmd_input *handle)if (do_read_check (handle, buf,10 ))return -1 ; } -/* * Check if this is a latency report or flyrecord. */
Signature · 1 line
2.31.1
PATCH 2/87 trace-cmd report: Fix typos in error messages
In reply to Tzvetomir Stoyanov (VMware)Fixed typos in "trace-cmd report" messages that report reading and parsing errors.
--- tracecmd/trace-read.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tracecmd/trace-read.c +2 -2
@@ -1290,7 +1290,7 @@ static void read_data_info(struct list_head *handle_list, enum output_type otypedie ("error in reading buffer instance" ); new_handle =tracecmd_buffer_instance_handle (handles->handle, i);if (!new_handle) { -warning ("could not retreive handle %s" , name); +warning ("could not retrieve handle %s" , name);continue ; }add_handle (new_handle, name);
@@ -1324,7 +1324,7 @@ static void read_data_info(struct list_head *handle_list, enum output_type otypeif (last_record) {int cpu = last_record->cpu;if (cpu >= last_handle->cpus) -die ("cpu %d creater than %d\n" , cpu, last_handle->cpus); +die ("cpu %d greater than %d\n" , cpu, last_handle->cpus);if (tscheck && last_handle->last_timestamp[cpu] > last_record->ts) { errno =0 ;
Signature · 1 line
2.31.1
PATCH 3/87 tarce-cmd library: Fix version string memory leak
In reply to Tzvetomir Stoyanov (VMware)The version string is allocated when a VERSION option is processed, but is never freed. Free it on input hanlder close.
--- lib/trace-cmd/trace-input.c | 3 +++ 1 file changed, 3 insertions(+)
lib/trace-cmd/trace-input.c +3 -0
@@ -3517,6 +3517,7 @@ void tracecmd_close(struct tracecmd_input *handle)free (handle->cpu_data);free (handle->uname);free (handle->trace_clock); +free (handle->version);close (handle->fd);tracecmd_free_hooks (handle->hooks);
@@ -3958,6 +3959,7 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx) new_handle->cpu_data =NULL ; new_handle->nr_buffers =0 ; new_handle->buffers =NULL ; + new_handle->version =NULL ; new_handle->ref =1 ;if (handle->trace_clock) { new_handle->trace_clock =strdup (handle->trace_clock);
@@ -3970,6 +3972,7 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx) new_handle->parent = handle; new_handle->cpustats =NULL ; new_handle->hooks =NULL ; + new_handle->version =NULL ;if (handle->uname)/* Ignore if fails to malloc, no biggy */ new_handle->uname =strdup (handle->uname);
Signature · 1 line
2.31.1
PATCH 4/87 trace-cmd library: Fixed a memory leak on input handler close
In reply to Tzvetomir Stoyanov (VMware)When an input hanlder to a trace file is closed with tracecmd_close(), the list with buffers is not freed. This leads to a memory leak. Added logic to free that list.
--- lib/trace-cmd/trace-input.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
lib/trace-cmd/trace-input.c +19 -14
@@ -3482,7 +3482,7 @@ void tracecmd_ref(struct tracecmd_input *handle)*/ void tracecmd_close (struct tracecmd_input *handle) { -int cpu; +int i;if (!handle)return ;
@@ -3495,21 +3495,21 @@ void tracecmd_close(struct tracecmd_input *handle)if (--handle->ref)return ; -for (cpu =0 ; cpu < handle->cpus; cpu++) { +for (i =0 ; i < handle->cpus; i++) {/* The tracecmd_peek_data may have cached a record */ -free_next (handle, cpu); -free_page (handle, cpu); -if (handle->cpu_data && handle->cpu_data[cpu].kbuf) { -kbuffer_free (handle->cpu_data[cpu].kbuf); -if (handle->cpu_data[cpu].page_map) -free_page_map (handle->cpu_data[cpu].page_map); - -if (handle->cpu_data[cpu].page_cnt) +free_next (handle, i); +free_page (handle, i); +if (handle->cpu_data && handle->cpu_data[i].kbuf) { +kbuffer_free (handle->cpu_data[i].kbuf); +if (handle->cpu_data[i].page_map) +free_page_map (handle->cpu_data[i].page_map); + +if (handle->cpu_data[i].page_cnt)tracecmd_warning ("%d pages still allocated on cpu %d%s" , - handle->cpu_data[cpu].page_cnt, cpu, -show_records (handle->cpu_data[cpu].pages, - handle->cpu_data[cpu].nr_pages)); -free (handle->cpu_data[cpu].pages); + handle->cpu_data[i].page_cnt, i, +show_records (handle->cpu_data[i].pages, + handle->cpu_data[i].nr_pages)); +free (handle->cpu_data[i].pages); } }
@@ -3520,6 +3520,11 @@ void tracecmd_close(struct tracecmd_input *handle)free (handle->version);close (handle->fd); +for (i =0 ; i < handle->nr_buffers; i++) +free (handle->buffers[i].name); + +free (handle->buffers); +tracecmd_free_hooks (handle->hooks); handle->hooks =NULL ;
Signature · 1 line
2.31.1
PATCH 5/87 trace-cmd library: Fix possible memory corruption on processing a trace buffer
In reply to Tzvetomir Stoyanov (VMware)When a new trace buffer is read from the trace file, a new input handler is duplicated from the top one. Some of these data are poiters and should not be duplicated, as it could lead to a memory corruption on handler close.
Added a safety check to ensure requested buffer index is valid.
--- lib/trace-cmd/trace-input.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/trace-cmd/trace-input.c +3 -1
@@ -3945,13 +3945,14 @@ struct tracecmd_input * tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx) {struct tracecmd_input *new_handle; -struct input_buffer_instance *buffer = &handle->buffers[indx]; +struct input_buffer_instance *buffer;size_t offset;ssize_t ret;if (indx >= handle->nr_buffers)return NULL ; + buffer = &handle->buffers[indx];/* * We make a copy of the current handle, but we substitute * the cpu data with the cpu data for this buffer.
@@ -3965,6 +3966,7 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx) new_handle->nr_buffers =0 ; new_handle->buffers =NULL ; new_handle->version =NULL ; + new_handle->guest =NULL ; new_handle->ref =1 ;if (handle->trace_clock) { new_handle->trace_clock =strdup (handle->trace_clock);
Signature · 1 line
2.31.1
PATCH 6/87 trace-cmd library: Add constructor and destructor
In reply to Tzvetomir Stoyanov (VMware)Added empty constructor and destructor routines of the trace-cmd library. They will be used to initialize and free compression context of the library.
--- lib/trace-cmd/trace-util.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
lib/trace-cmd/trace-util.c +11 -0
@@ -624,3 +624,14 @@ bool tracecmd_is_version_supported(unsigned int version)return true;return false; } + +static void __attribute__ ((constructor))tracecmd_lib_init (void ) +{ + +} + +static void __attribute__((destructor))tracecmd_lib_free (void ) +{ + +} +
Signature · 1 line
2.31.1
PATCH 7/87 trace-cmd library: Add cache functionality to network message handler
In reply to Tzvetomir Stoyanov (VMware)Network message handler is used to send trace metadata through a network socket, instead writing it into a trace file. There are use cases, that could require to do a lseek() on the metadata. It is hard to implement lseek on a network socket, that's why for such use cases a cache to a local file is introduced. Once the metadata is constructed, the local cache is send to the socket. A new library API is used to enable the local cache:
tracecmd_msg_handle_cache()
The local cahce is flushed on the socket when the
tracecmd_msg_finish_sending_data()
is called.
--- .../include/private/trace-cmd-private.h | 5 + lib/trace-cmd/include/trace-cmd-local.h | 1 + lib/trace-cmd/trace-msg.c | 131 +++++++++++++----- 3 files changed, 103 insertions(+), 34 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +5 -0
@@ -339,12 +339,16 @@ enum tracecmd_msg_flags { };/* for both client and server */ +#define MSG_CACHE_FILE "/tmp/trace_msg_cacheXXXXXX"struct tracecmd_msg_handle {int fd;short cpu_count;short version;/* Current protocol version */ unsigned long flags;bool done; +bool cache; +int cfd; +char cfile[26 ];/* strlen(MSG_CACHE_FILE) */ };struct tracecmd_tsync_protos {
@@ -353,6 +357,7 @@ struct tracecmd_tsync_protos {struct tracecmd_msg_handle *tracecmd_msg_handle_alloc (int fd,unsigned long flags); +int tracecmd_msg_handle_cache (struct tracecmd_msg_handle *msg_handle);/* Closes the socket and frees the handle */ void tracecmd_msg_handle_close (struct tracecmd_msg_handle *msg_handle);
lib/trace-cmd/include/trace-cmd-local.h +1 -0
@@ -31,5 +31,6 @@ void tracecmd_info(const char *fmt, ...);#endif #endif +off64_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off_t offset,int whence);#endif /* _TRACE_CMD_LOCAL_H */
lib/trace-cmd/trace-msg.c +97 -34
265 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 8/87 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:
struct tracecmd_compression
tracecmd_compress_init()
tracecmd_compress_free()
tracecmd_compress_alloc()
tracecmd_compress_destroy()
tracecmd_compress_block()
tracecmd_uncompress_block()
tracecmd_compress_reset()
tracecmd_compress_read()
tracecmd_compress_pread()
tracecmd_compress_write()
tracecmd_compress_lseek() tracecmd_compress_proto_get_name() tracecmd_compress_is_supported() tracecmd_compress_protos_get() tracecmd_compress_proto_register() tracecmd_compress_copy_from() tracecmd_uncompress_copy_to()
tracecmd_uncompress_chunk()
tracecmd_load_chunks_info()
The compression algorithms are not part of this patch.
--- lib/trace-cmd/Makefile | 2 +- .../include/private/trace-cmd-private.h | 39 + lib/trace-cmd/include/trace-cmd-local.h | 4 + lib/trace-cmd/trace-compress.c | 910 ++++++++++++++++++ lib/trace-cmd/trace-util.c | 5 +- 5 files changed, 957 insertions(+), 3 deletions(-) create mode 100644 lib/trace-cmd/trace-compress.c
lib/trace-cmd/Makefile +1 -1
@@ -25,7 +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 OBJS += trace-ftrace.o
lib/trace-cmd/include/private/trace-cmd-private.h +39 -0
@@ -468,6 +468,45 @@ 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_chunk { +unsigned int size; +unsigned int zsize; +unsigned long long zoffset; +unsigned long long offset; +}; +struct tracecmd_compression ; +struct tracecmd_compression *tracecmd_compress_alloc (const char *name,const char *version, +int fd,struct tep_handle *tep, +struct tracecmd_msg_handle *msg_handle); +void tracecmd_compress_destroy (struct tracecmd_compression *handle); +int tracecmd_compress_block (struct tracecmd_compression *handle); +int tracecmd_uncompress_block (struct tracecmd_compression *handle); +void tracecmd_compress_reset (struct tracecmd_compression *handle); +int tracecmd_compress_read (struct tracecmd_compression *handle,char *dst,int len); +int tracecmd_compress_pread (struct tracecmd_compression *handle,char *dst,int len,off_t offset); +int tracecmd_compress_write (struct tracecmd_compression *handle, +const void *data,unsigned long long size); +off64_t tracecmd_compress_lseek (struct tracecmd_compression *handle,off64_t offset,int whence); +int tracecmd_compress_proto_get_name (struct tracecmd_compression *compress, +const char **name,const char **version); +bool tracecmd_compress_is_supported (const char *name,const char *version); +int tracecmd_compress_protos_get (char ***names,char ***versions); +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_copy_from (struct tracecmd_compression *handle,int fd,int chunk_size, +unsigned long long *read_size,unsigned long long *write_size); +int tracecmd_uncompress_copy_to (struct tracecmd_compression *handle,int fd, +unsigned long long *read_size,unsigned long long *write_size); +int tracecmd_uncompress_chunk (struct tracecmd_compression *handle, +struct tracecmd_compress_chunk *chunk,char *data); +int tracecmd_load_chunks_info (struct tracecmd_compression *handle, +struct tracecmd_compress_chunk **chunks_info);/* --- Plugin handling --- */ extern struct tep_plugin_option trace_ftrace_options[];
lib/trace-cmd/include/trace-cmd-local.h +4 -0
@@ -31,6 +31,10 @@ void tracecmd_info(const char *fmt, ...);#endif #endif +void tracecmd_compress_init (void ); +void tracecmd_compress_free (void ); + +off64_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off_t offset,int whence);#endif /* _TRACE_CMD_LOCAL_H */
lib/trace-cmd/trace-compress.c new file +910 -0
910 lines not on this page · raw message
lib/trace-cmd/trace-util.c +3 -2
@@ -627,11 +627,12 @@ bool tracecmd_is_version_supported(unsigned int version)static void __attribute__ ((constructor))tracecmd_lib_init (void ) { - +tracecmd_compress_init (); }static void __attribute__((destructor))tracecmd_lib_free (void ) { - +tracecmd_compress_free (); } +
Signature · 1 line
2.31.1
PATCH 9/87 trace-cmd list: Show supported compression algorithms
In reply to Tzvetomir Stoyanov (VMware)Add new parameter "trace-cmd list -c" to show supported compression algorithms.
--- Documentation/trace-cmd/trace-cmd-list.1.txt | 3 +++ tracecmd/trace-list.c | 26 ++++++++++++++++++++ tracecmd/trace-usage.c | 1 + 3 files changed, 30 insertions(+)
Documentation/trace-cmd/trace-cmd-list.1.txt +3 -0
@@ -71,6 +71,9 @@ OPTIONS List defined clocks that can be used with trace-cmd record -C. The one in brackets ([]) is the active clock. +*-c*:: + List the available trace file compression algorithms. + SEE ALSO -------- trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1),
tracecmd/trace-list.c +26 -0
@@ -549,6 +549,24 @@ static void show_plugins(void)tep_free (pevent); } +static void show_compression (void ) +{ +char **versions, **names; +int c, i; + + c =tracecmd_compress_protos_get (&names, &versions); +if (c <=0 ) { +printf ("No compression algorithms are supported\n" ); +return ; + } +printf ("Supported compression algorithms:\n" ); +for (i =0 ; i < c; i++) +printf ("\t%s, %s\n" , names[i], versions[i]); + +free (names); +free (versions); +} +void trace_list (int argc,char **argv) {int events =0 ;
@@ -562,6 +580,7 @@ void trace_list(int argc, char **argv)int flags =0 ;int systems =0 ;int show_all =1 ; +int compression =0 ;int i;const char *arg;const char *funcre =NULL ;
@@ -626,6 +645,10 @@ void trace_list(int argc, char **argv) systems =1 ; show_all =0 ;break ; +case 'c' : + compression =1 ; + show_all =0 ; +break ;case '-' :if (strcmp (argv[i],"--debug" ) ==0 ) {tracecmd_set_debug (true);
@@ -670,6 +693,8 @@ void trace_list(int argc, char **argv)show_clocks ();if (systems)show_systems (); +if (compression) +show_compression ();if (show_all) {printf ("event systems:\n" );show_systems ();
@@ -679,6 +704,7 @@ void trace_list(int argc, char **argv)show_tracers ();printf ("\noptions:\n" );show_options (); +show_compression (); }return ;
tracecmd/trace-usage.c +1 -0
@@ -348,6 +348,7 @@ static struct usage_help usage_help[] = {" -O list plugin options\n" " -B list defined buffer instances\n" " -C list the defined clocks (and active one)\n" +" -c list the supported trace file compression algorithms\n" }, { "restore",
Signature · 1 line
2.31.1
PATCH 10/87 trace-cmd library: Internal helpers for compressing data
In reply to Tzvetomir Stoyanov (VMware)New library internal helper functions are introduced, to add compression functionality to the output trace handler.
--- lib/trace-cmd/include/trace-cmd-local.h | 8 ++++ lib/trace-cmd/trace-output.c | 64 ++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-)
lib/trace-cmd/include/trace-cmd-local.h +8 -0
@@ -34,7 +34,15 @@ void tracecmd_info(const char *fmt, ...);void tracecmd_compress_init (void );void tracecmd_compress_free (void ); +int out_uncompress_block (struct tracecmd_output *handle); +int out_compression_start (struct tracecmd_output *handle); +int out_compression_end (struct tracecmd_output *handle); +void out_compression_reset (struct tracecmd_output *handle); +unsigned long long out_copy_fd_compress (struct tracecmd_output *handle, +int fd,unsigned long long max, +unsigned long long *write_size);off64_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off_t offset,int whence); +#endif /* _TRACE_CMD_LOCAL_H */
lib/trace-cmd/trace-output.c +62 -2
89 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 11/87 trace-cmd library: Internal helpers for uncompressing data
In reply to Tzvetomir Stoyanov (VMware)New library internal helper functions are introduced, to add compression functionality to the input trace handler.
--- lib/trace-cmd/include/trace-cmd-local.h | 4 ++ lib/trace-cmd/trace-input.c | 54 +++++++++++++++++++++---- 2 files changed, 50 insertions(+), 8 deletions(-)
lib/trace-cmd/include/trace-cmd-local.h +4 -0
@@ -38,6 +38,10 @@ int out_uncompress_block(struct tracecmd_output *handle);int out_compression_start (struct tracecmd_output *handle);int out_compression_end (struct tracecmd_output *handle);void out_compression_reset (struct tracecmd_output *handle); + +void in_uncompress_reset (struct tracecmd_input *handle); +int in_uncompress_block (struct tracecmd_input *handle); +unsigned long long out_copy_fd_compress (struct tracecmd_output *handle,int fd,unsigned long long max,unsigned long long *write_size);
lib/trace-cmd/trace-input.c +46 -8
106 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 11/87] trace-cmd library: Internal helpers for uncompressing data
Quoted 57 lines · On Wed, 28 Jul 2021 16:31:34 +0300 "Tzvetomir Stoyanov (VMware)"…
New library internal helper functions are introduced, to add compression functionality to the input trace handler.
Signed-off-by Tzvetomir Stoyanov (VMware) <[email protected]>--- lib/trace-cmd/include/trace-cmd-local.h | 4 ++ lib/trace-cmd/trace-input.c | 54 +++++++++++++++++++++---- 2 files changed, 50 insertions(+), 8 deletions(-)lib/trace-cmd/include/trace-cmd-local.h +4
-0@@ -38,6 +38,10 @@ int out_uncompress_block(struct tracecmd_output *handle);int out_compression_start (struct tracecmd_output *handle);int out_compression_end (struct tracecmd_output *handle);void out_compression_reset (struct tracecmd_output *handle); + +void in_uncompress_reset (struct tracecmd_input *handle); +int in_uncompress_block (struct tracecmd_input *handle); +unsigned long long out_copy_fd_compress (struct tracecmd_output *handle,int fd,unsigned long long max,unsigned long long *write_size);lib/trace-cmd/trace-input.c +5
-2@@ -136,6 +136,9 @@ struct tracecmd_input {long long ts_offset;struct tsc2nsec tsc_calc; +bool read_compress; +struct tracecmd_compression *compress; +struct host_trace_info host;double ts2secs;char * cpustats;@@ -238,13 +241,13 @@ static const char *show_records(struct page **pages, int nr_pages)static int init_cpu (struct tracecmd_input *handle,int cpu); -static ssize_t do_read (struct tracecmd_input *handle,void *data,size_t size) +static ssize_t do_read_fd (int fd,void *data,size_t size) {ssize_t tot =0 ;ssize_t r; do { - r = read(handle->fd, data + tot, size - tot); + r = read(fd, data + tot, size - tot); tot += r; if (!r)@@ -256,12 +259,28 @@ static ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size)return tot; }
lib/trace-cmd/trace-input.c static ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size) · line 270
Quoted 10 lines
lib/trace-cmd/trace-input.c +9
-0+static inline int do_lseek (struct tracecmd_input *handle,int offset,int whence) +{ +if (handle->read_compress) +return tracecmd_compress_lseek (handle->compress, offset, whence); +else +return lseek (handle->fd, offset, whence); +} + +static inline ssize_t do_read_compressed (struct tracecmd_input *handle,void *data,size_t size)
This should be just called "do_read", as it handles both compressed and normal reads. And the name suggests that it only does compressed reads.
Quoted 4 lines
lib/trace-cmd/trace-input.c +4
-0+{ +if (handle->read_compress) +return tracecmd_compress_read (handle->compress, data, size); +else
lib/trace-cmd/trace-input.c static ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size) · line 283
Quoted 10 lines
lib/trace-cmd/trace-input.c +4
-1+return do_read_fd (handle->fd, data, size); +} +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);
By keeping it do_read() you don't need all these other changes.
-- Steve
Quoted 60 lines
lib/trace-cmd/trace-input.c +24
-5if (ret <0 )return ret;if (ret != size)@@ -279,10 +298,8 @@ static char *read_string(struct tracecmd_input *handle)ssize_t r;for (;;) { - r =do_read (handle, buf,BUFSIZ ); -if (r <0 ) - goto fail; -if (!r) + r =do_read_compressed (handle, buf,BUFSIZ ); +if (r <=0 ) goto fail;for (i =0 ; i < r; i++) {@@ -308,7 +325,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;@@ -372,6 +389,26 @@ static int read8(struct tracecmd_input *handle, unsigned long long *size)return 0 ; } +__hidden void in_uncompress_reset(struct tracecmd_input *handle) +{ +if (handle->compress) { + handle->read_compress = false; +tracecmd_compress_reset (handle->compress); + } +} + +__hidden int in_uncompress_block(struct tracecmd_input *handle) +{ +int ret =0 ; + +if (handle->compress) { + ret =tracecmd_uncompress_block (handle->compress); +if (!ret) + handle->read_compress = true; + } +return ret; +} +static int read_header_files (struct tracecmd_input *handle) {struct tep_handle *pevent = handle->pevent;@@ -479,6 +516,7 @@ static int read_ftrace_file(struct tracecmd_input *handle, buf =malloc (size);if (!buf)return -1 ; +if (do_read_check (handle, buf, size)) {free (buf);return -1 ;
PATCH 12/87 trace-cmd library: Define trace file version 7
In reply to Tzvetomir Stoyanov (VMware)Added a define for file version 7, but keep the default file version to 6.
--- lib/trace-cmd/include/private/trace-cmd-private.h | 3 +++ lib/trace-cmd/include/trace-cmd-local.h | 7 ------- lib/trace-cmd/trace-output.c | 2 +- lib/trace-cmd/trace-util.c | 2 +- tracecmd/trace-record.c | 2 ++ 5 files changed, 7 insertions(+), 9 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +3 -0
@@ -31,6 +31,9 @@ struct tep_plugin_list *trace_load_plugins(struct tep_handle *tep, int flags);int *tracecmd_add_id (int *list,int id,int len); +#define FILE_VERSION_DEFAULT 6 +#define FILE_VERSION_MIN 6 +#define FILE_VERSION_MAX 7enum {RINGBUF_TYPE_PADDING =29 ,RINGBUF_TYPE_TIME_EXTEND =30 ,
lib/trace-cmd/include/trace-cmd-local.h +0 -7
@@ -14,13 +14,6 @@ void tracecmd_warning(const char *fmt, ...);void tracecmd_critical (const char *fmt, ...);void tracecmd_info (const char *fmt, ...); -/* trace.dat file format version */ -#define FILE_VERSION 6 - -#define _STR (x) #x -#define STR (x) _STR(x) -#define FILE_VERSION_STRING STR(FILE_VERSION) -#ifndef htonll# if __BYTE_ORDER == __LITTLE_ENDIAN#define htonll (x) __bswap_64(x)
lib/trace-cmd/trace-output.c +1 -1
@@ -976,7 +976,7 @@ static int select_file_version(struct tracecmd_output *handle,if (ihandle) handle->file_version =tracecmd_get_in_file_version (ihandle);else - handle->file_version =FILE_VERSION ; + handle->file_version =FILE_VERSION_DEFAULT ;return 0 ; }
lib/trace-cmd/trace-util.c +1 -1
@@ -620,7 +620,7 @@ unsigned long long tracecmd_generate_traceid(void)bool tracecmd_is_version_supported (unsigned int version) { -if (version <=FILE_VERSION ) +if (version >=FILE_VERSION_MIN && version <=FILE_VERSION_MAX )return true;return false; }
tracecmd/trace-record.c +2 -0
@@ -214,6 +214,7 @@ struct common_record_context {int topt;int run_command;int saved_cmdlines_size; +int file_version; };static void add_reset_file (const char *file,const char *val,int prio)
@@ -5937,6 +5938,7 @@ static void init_common_record_context(struct common_record_context *ctx, ctx->instance = &top_instance; ctx->curr_cmd = curr_cmd; local_cpu_count =tracecmd_count_cpus (); + ctx->file_version =FILE_VERSION_DEFAULT ;init_top_instance (); }
Signature · 1 line
2.31.1
PATCH 13/87 trace-cmd library: Refactor APIs for creating output handler
In reply to Tzvetomir Stoyanov (VMware)In the trace-cmd library there are various APIs for allocating and initializing output handler to a trace file. The existing APIs are use case oriented, with a lot of parameters. Extending them for new use cases, adding more input parameters, will make the library more complex and not easy to use.
Almost all use case oriented APIs for output handler creation are removed and replaced with new flow, which is easier to be extended with new creation parameters.
Removed APIs:
tracecmd_create_init_fd_msg()
tracecmd_create_init_file_glob()
tracecmd_create_init_fd_glob()
tracecmd_create_init_file_override()
New APIs:
tracecmd_output_allocate()
tracecmd_output_set_msg()
tracecmd_output_set_trace_dir()
tracecmd_output_set_kallsyms()
tracecmd_output_set_from_input()
tracecmd_output_set_version()
tracecmd_output_write_init()
tracecmd_output_write_headers()
The new tracecmd_output_allocate() API allocates memory and performs minimalinitialization of an output handler to a trace file. No data is written in the file.
The tracecmd_output_set_...() APIs can be used to set various parameters to the newly allocated output handler, that affect the way the data is written into the file.
When the output handler is configured for the desired use case, the tracecmd_output_write_init() is used to start writing to the file, it writes initial magic bytes.
The tracecmd_output_write_headers() API is used to write the initial headers into the file.
--- .../include/private/trace-cmd-private.h | 29 +- lib/trace-cmd/trace-output.c | 437 ++++++++++++------ tracecmd/trace-record.c | 64 ++- tracecmd/trace-restore.c | 32 +- 4 files changed, 395 insertions(+), 167 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +16 -13
@@ -105,7 +105,8 @@ static inline int tracecmd_host_bigendian(void)/* --- Opening and Reading the trace.dat file --- */ enum tracecmd_file_states { -TRACECMD_FILE_INIT =1 , +TRACECMD_FILE_ALLOCATED =0 , +TRACECMD_FILE_INIT ,TRACECMD_FILE_HEADERS ,TRACECMD_FILE_FTRACE_EVENTS ,TRACECMD_FILE_ALL_EVENTS ,
@@ -271,20 +272,22 @@ struct tracecmd_event_list {struct tracecmd_option ;struct tracecmd_msg_handle ; -struct tracecmd_output *tracecmd_create_file_latency (const char *output_file,int cpus); -struct tracecmd_output * -tracecmd_create_init_file_glob (const char *output_file, -struct tracecmd_event_list *list); +struct tracecmd_output *tracecmd_output_allocate (int fd); +int tracecmd_output_set_msg (struct tracecmd_output *handler, +struct tracecmd_msg_handle *msg_handle); +int tracecmd_output_set_trace_dir (struct tracecmd_output *handler,const char *tracing_dir); +int tracecmd_output_set_kallsyms (struct tracecmd_output *handler,const char *kallsyms); +int tracecmd_output_set_from_input (struct tracecmd_output *handler,struct tracecmd_input *ihandle); +int tracecmd_output_set_version (struct tracecmd_output *handler,int file_version); +int tracecmd_output_write_init (struct tracecmd_output *handler); +int tracecmd_output_write_headers (struct tracecmd_output *handler, +struct tracecmd_event_list *list); + +struct tracecmd_output *tracecmd_create_file_latency (const char *output_file,int cpus, +int file_version);struct tracecmd_output *tracecmd_create_init_fd (int fd); -struct tracecmd_output * -tracecmd_create_init_fd_glob (int fd,struct tracecmd_event_list *list); -struct tracecmd_output * -tracecmd_create_init_fd_msg (struct tracecmd_msg_handle *msg_handle, -struct tracecmd_event_list *list); +struct tracecmd_output *tracecmd_create_init_file (const char *output_file); -struct tracecmd_output *tracecmd_create_init_file_override (const char *output_file, -const char *tracing_dir, -const char *kallsyms);struct tracecmd_option *tracecmd_add_option (struct tracecmd_output *handle,unsigned short id,int size,const void *data);
lib/trace-cmd/trace-output.c +292 -145
548 lines not on this page · raw message
tracecmd/trace-record.c +57 -7
108 lines not on this page · raw message
tracecmd/trace-restore.c +30 -2
@@ -22,6 +22,35 @@#include "trace-local.h" +static struct tracecmd_output *create_output (const char *file, +const char *tracing_dir,const char *kallsyms) +{ +struct tracecmd_output *out; +int fd; + + fd =open (file,O_RDWR |O_CREAT |O_TRUNC |O_LARGEFILE ,0644 ); +if (fd <0 ) +return NULL ; + + out =tracecmd_output_allocate (fd); +if (!out) + goto error; +if (tracing_dir &&tracecmd_output_set_trace_dir (out, tracing_dir)) + goto error; +if (kallsyms &&tracecmd_output_set_kallsyms (out, kallsyms)) + goto error; +if (tracecmd_output_write_headers (out,NULL )) + goto error; +return out; +error: +if (out) +tracecmd_output_close (out); +else +close (fd); +unlink (file); +return NULL ; +} +void trace_restore (int argc,char **argv) {struct tracecmd_output *handle;
@@ -90,8 +119,7 @@ void trace_restore (int argc, char **argv)usage (argv); } - handle =tracecmd_create_init_file_override (output, tracing_dir, - kallsyms); + handle =create_output (output, tracing_dir, kallsyms);if (!handle)die ("Unabled to create output file %s" , output);if (tracecmd_write_cmdlines (handle) <0 )
Signature · 1 line
2.31.1
PATCH 14/87 trace-cmd library: Reuse within the library the function that checks file state.
In reply to Tzvetomir Stoyanov (VMware)Make the function, that checks if the next file state is valid, global for the tracmd-library, so it can be reused. It is important the same check logic to be used in the whole library.
--- lib/trace-cmd/include/trace-cmd-local.h | 4 ++ lib/trace-cmd/trace-input.c | 5 +++ lib/trace-cmd/trace-output.c | 59 +++++++------------------ lib/trace-cmd/trace-util.c | 31 +++++++++++++ 4 files changed, 57 insertions(+), 42 deletions(-)
lib/trace-cmd/include/trace-cmd-local.h +4 -0
@@ -27,6 +27,10 @@ void tracecmd_info(const char *fmt, ...);void tracecmd_compress_init (void );void tracecmd_compress_free (void ); +bool check_file_state (unsigned long file_version,int current_state,int new_state); +bool check_in_state (struct tracecmd_input *handle,int new_state); +bool check_out_state (struct tracecmd_output *handle,int new_state); +int out_uncompress_block (struct tracecmd_output *handle);int out_compression_start (struct tracecmd_output *handle);int out_compression_end (struct tracecmd_output *handle);
lib/trace-cmd/trace-input.c +5 -0
@@ -4260,3 +4260,8 @@ int tracecmd_enable_tsync(struct tracecmd_input *handle, bool enable)return 0 ; } + +__hidden bool check_in_state(struct tracecmd_input *handle, int new_state) +{ +return check_file_state (handle->file_version, handle->file_state, new_state); +}
lib/trace-cmd/trace-output.c +17 -42
126 lines not on this page · raw message
lib/trace-cmd/trace-util.c +31 -0
@@ -635,4 +635,35 @@ static void __attribute__((destructor)) tracecmd_lib_free(void)tracecmd_compress_free (); } +__hidden bool check_file_state(unsigned long file_version, int current_state, int new_state) +{ +if (file_version >=7 ) { +if (current_state <TRACECMD_FILE_INIT ) +return false; +return true; + } +switch (new_state) { +case TRACECMD_FILE_HEADERS : +case TRACECMD_FILE_FTRACE_EVENTS : +case TRACECMD_FILE_ALL_EVENTS : +case TRACECMD_FILE_KALLSYMS : +case TRACECMD_FILE_PRINTK : +case TRACECMD_FILE_CMD_LINES : +case TRACECMD_FILE_CPU_COUNT : +if (current_state == (new_state -1 )) +return true; +break ; +case TRACECMD_FILE_OPTIONS : +if (file_version <7 && current_state ==TRACECMD_FILE_CPU_COUNT ) +return true; +break ; +case TRACECMD_FILE_CPU_LATENCY : +case TRACECMD_FILE_CPU_FLYRECORD : +if (current_state ==TRACECMD_FILE_OPTIONS ) +return true; +break ; + } + +return false; +}
Signature · 1 line
2.31.1
PATCH 15/87 trace-cmd library: New API to get the version of output handler
In reply to Tzvetomir Stoyanov (VMware)There are cases where the version of the file, associated with given output handler must be retrieved. Added a new API to get that version:
tracecmd_get_out_file_version()
--- lib/trace-cmd/include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-output.c | 9 +++++++++ 2 files changed, 10 insertions(+)
lib/trace-cmd/include/private/trace-cmd-private.h +1 -0
@@ -316,6 +316,7 @@ int tracecmd_append_buffer_cpu_data(struct tracecmd_output *handle, int cpus, char * const *cpu_data_files);struct tracecmd_output *tracecmd_get_output_handle_fd (int fd); +unsigned long tracecmd_get_out_file_version (struct tracecmd_output *handle);/* --- Reading the Fly Recorder Trace --- */
lib/trace-cmd/trace-output.c +9 -0
@@ -1843,3 +1843,12 @@ __hidden bool check_out_state(struct tracecmd_output *handle, int new_state)return check_file_state (handle->file_version, handle->file_state, new_state); } +/** +* tracecmd_get_out_file_version - return the trace.dat file version +* @handle: output handle for the trace.dat file +*/ +unsigned long tracecmd_get_out_file_version (struct tracecmd_output *handle) +{ +return handle->file_version; +} +
Signature · 1 line
2.31.1
PATCH 16/87 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.
--- .../include/private/trace-cmd-private.h | 2 ++ lib/trace-cmd/trace-input.c | 16 ++++++++++++++++ lib/trace-cmd/trace-output.c | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+)
lib/trace-cmd/include/private/trace-cmd-private.h +2 -0
@@ -239,6 +239,8 @@ tracecmd_get_cursor(struct tracecmd_input *handle, int cpu);unsigned long tracecmd_get_in_file_version (struct tracecmd_input *handle);size_t tracecmd_get_options_offset (struct tracecmd_input *handle); +int tracecmd_get_file_compress_proto (struct tracecmd_input *handle, +const char **name,const char **version);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 +16 -0
@@ -4115,6 +4115,22 @@ unsigned long tracecmd_get_in_file_version(struct tracecmd_input *handle)return handle->file_version; } +/** +* tracecmd_get_file_compress_proto - get name and version of compression algorithm, +* used to compress the trace file +* @handle: input handle for the trace.dat file +* @name: return, name of the compression algorithm. +* @version: return, version of the compression algorithm. +* +* Returns 0 on success, or -1 in case of an error. If 0 is returned, the name and version of the +* algorithm are stored in @name and @version. The returned strings must *not* be freed. +*/ +int tracecmd_get_file_compress_proto (struct tracecmd_input *handle, +const char **name,const char **version) +{ +return tracecmd_compress_proto_get_name (handle->compress, name, version); +} +/** * tracecmd_get_use_trace_clock - return use_trace_clock * @handle: input handle for the trace.dat file
lib/trace-cmd/trace-output.c +19 -0
@@ -1077,6 +1077,9 @@ int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *ka*/ int tracecmd_output_set_from_input (struct tracecmd_output *handler,struct tracecmd_input *ihandle) { +const char *cname =NULL ; +const char *cver =NULL ; +if (!handler || !ihandle || handler->file_state !=TRACECMD_FILE_ALLOCATED )return -1 ;
@@ -1091,6 +1094,14 @@ int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct traceelse handler->big_endian = false; +if (!tracecmd_get_file_compress_proto (ihandle, &cname, &cver)) { + handler->compress =tracecmd_compress_alloc (cname, cver, handler->fd, + handler->pevent, handler->msg_handle); +if (!handler->compress) +return -1 ; +if (handler->file_version <7 ) + handler->file_version =7 ; + }return 0 ; }
@@ -1716,6 +1727,8 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd) {struct tracecmd_output *handle =NULL ;struct tracecmd_input *ihandle; +const char *cname =NULL ; +const char *cver =NULL ;int fd2;/* Move the file descriptor to the beginning */
@@ -1754,6 +1767,12 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd) handle->options_start =tracecmd_get_options_offset (ihandle);list_head_init (&handle->options); +if (!tracecmd_get_file_compress_proto (ihandle, &cname, &cver)) { + handle->compress =tracecmd_compress_alloc (cname, cver, handle->fd, + handle->pevent, handle->msg_handle); +if (!handle->compress) + goto out_free; + }tracecmd_close (ihandle);return handle;
Signature · 1 line
2.31.1
PATCH 17/87 trace-cmd library: New API to configure compression on an output handler
In reply to Tzvetomir Stoyanov (VMware)New API can be used to configure compression algorithm on a output handler to a trace file.
tracecmd_output_set_compression()
--- .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-output.c | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+)
lib/trace-cmd/include/private/trace-cmd-private.h +1 -0
@@ -281,6 +281,7 @@ int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *tint tracecmd_output_set_kallsyms (struct tracecmd_output *handler,const char *kallsyms);int tracecmd_output_set_from_input (struct tracecmd_output *handler,struct tracecmd_input *ihandle);int tracecmd_output_set_version (struct tracecmd_output *handler,int file_version); +int tracecmd_output_set_compression (struct tracecmd_output *handler,const char *compression);int tracecmd_output_write_init (struct tracecmd_output *handler);int tracecmd_output_write_headers (struct tracecmd_output *handler,struct tracecmd_event_list *list);
lib/trace-cmd/trace-output.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 18/87 trace-cmd record: Add compression to the trace context
In reply to Tzvetomir Stoyanov (VMware)As the trace-cmd libray supports trace file compression, trace-cmd record command should have a way to configure this functionality. Trace context is extended to hold the compression algorithm, used to compress the file.
--- tracecmd/trace-record.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
tracecmd/trace-record.c +19 -0
@@ -199,6 +199,7 @@ struct common_record_context {char *date2ts;char *user;const char *clock; +const char *compression;struct tsc_nsec tsc2nsec;int data_flags;int tsync_loop_interval;
@@ -3702,6 +3703,12 @@ static struct tracecmd_output *create_net_output(struct common_record_context *c goto error;if (tracecmd_output_set_msg (out, msg_handle)) goto error; +if (ctx->compression) { +if (tracecmd_output_set_compression (out, ctx->compression)) + goto error; + }else if (ctx->file_version >=7 ) { +tracecmd_output_set_compression (out,"any" ); + }if (tracecmd_output_write_headers (out, listed_events)) goto error;
@@ -3745,6 +3752,12 @@ setup_connection(struct buffer_instance *instance, struct common_record_context goto error;if (tracecmd_output_set_version (network_handle, ctx->file_version)) goto error; +if (ctx->compression) { +if (tracecmd_output_set_compression (network_handle, ctx->compression)) + goto error; + }else if (ctx->file_version >=7 ) { +tracecmd_output_set_compression (network_handle,"any" ); + }if (tracecmd_output_write_headers (network_handle, listed_events)) goto error;tracecmd_set_quiet (network_handle, quiet);
@@ -4475,6 +4488,12 @@ static struct tracecmd_output *create_output(struct common_record_context *ctx) goto error;if (ctx->file_version &&tracecmd_output_set_version (out, ctx->file_version)) goto error; +if (ctx->compression) { +if (tracecmd_output_set_compression (out, ctx->compression)) + goto error; + }else if (ctx->file_version >=7 ) { +tracecmd_output_set_compression (out,"any" ); + }if (tracecmd_output_write_headers (out, listed_events)) goto error;return out;
Signature · 1 line
2.31.1
PATCH 19/87 trace-cmd library: Write compression header in the trace file
In reply to Tzvetomir Stoyanov (VMware)If there is a compression configured on the output file handler and if the file version is at least 7, write compression header in the file. The compression header is two null terminated strings - name and version of the compression algorithm, used to compress some parts of the file. The header is located after the page size in the file. The new header is mandatory for trace files version 7. If no compression is used, the string "none" is saved as name of the compression algorithm and empty string as compression algorithm version.
--- lib/trace-cmd/trace-output.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
lib/trace-cmd/trace-output.c +23 -0
@@ -941,6 +941,24 @@ out_free:return ret; } +static int write_compression_header (struct tracecmd_output *handle) +{ +const char *name =NULL ; +const char *ver =NULL ; +int ret; + + ret =tracecmd_compress_proto_get_name (handle->compress, &name, &ver); +if (ret <0 || !name || !ver) { + name ="none" ; + ver ="" ; + } +if (do_write_check (handle, name,strlen (name) +1 )) +return -1 ; +if (do_write_check (handle, ver,strlen (ver) +1 )) +return -1 ; +return 0 ; +} +/** * tracecmd_output_allocate - allocate new output handler to a trace file * @handle: file descriptor to an empty file, it can be -1 if the handler
@@ -1222,6 +1240,11 @@ int tracecmd_output_write_init(struct tracecmd_output *handler) endian4 =convert_endian_4 (handler, handler->page_size);if (do_write_check (handler, &endian4,4 ))return -1 ; +if (handler->file_version >=7 ) { +if (write_compression_header (handler)) +return -1 ; + } + handler->file_state =TRACECMD_FILE_INIT ;return 0 ; }
Signature · 1 line
2.31.1
PATCH 20/87 trace-cmd library: Compress part of the trace file
In reply to Tzvetomir Stoyanov (VMware)Compress part of the trace.dat file metadata. If there is compression support, 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
--- lib/trace-cmd/trace-output.c | 131 ++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 39 deletions(-)
lib/trace-cmd/trace-output.c +92 -39
@@ -366,12 +366,12 @@ int tracecmd_ftrace_enable(int set)return ret; } -static int read_header_files (struct tracecmd_output *handle) +static int read_header_files (struct tracecmd_output *handle,bool compress) {tsize_t size, check_size, endian8;struct stat st;char *path; -int fd; +int fd =-1 ;int ret;if (!check_out_state (handle,TRACECMD_FILE_HEADERS )) {
@@ -384,26 +384,30 @@ static int read_header_files(struct tracecmd_output *handle)if (!path)return -1 ; +if (compress) +out_compression_start (handle); ret =stat (path, &st);if (ret <0 ) {/* old style did not show this info, just add zero */ put_tracing_file (path);if (do_write_check (handle,"header_page" ,12 )) -return -1 ; + goto out_close; size =0 ;if (do_write_check (handle, &size,8 )) -return -1 ; + goto out_close;if (do_write_check (handle,"header_event" ,13 )) -return -1 ; + goto out_close;if (do_write_check (handle, &size,8 )) -return -1 ; + goto out_close; +if (compress &&out_compression_end (handle)) + goto out_close;return 0 ; } fd =open (path,O_RDONLY );if (fd <0 ) {tracecmd_warning ("can't read '%s'" , path); -return -1 ; + goto out_close; }/* unfortunately, you can not stat debugfs files for size */
@@ -419,18 +423,18 @@ static int read_header_files(struct tracecmd_output *handle)if (size != check_size) {tracecmd_warning ("wrong size for '%s' size=%lld read=%lld" , path, size, check_size); errno =EINVAL ; -return -1 ; + goto out_close; }put_tracing_file (path); path =get_tracing_file (handle,"events/header_event" );if (!path) -return -1 ; + goto out_close; fd =open (path,O_RDONLY );if (fd <0 ) {tracecmd_warning ("can't read '%s'" , path); -return -1 ; + goto out_close; } size =get_size_fd (fd);
@@ -444,16 +448,19 @@ static int read_header_files(struct tracecmd_output *handle)close (fd);if (size != check_size) {tracecmd_warning ("wrong size for '%s'" , path); -return -1 ; + goto out_close; }put_tracing_file (path); - +if (compress &&out_compression_end (handle)) + goto out_close; handle->file_state =TRACECMD_FILE_HEADERS ;return 0 ; out_close: -close (fd); +out_compression_reset (handle); +if (fd >=0 ) +close (fd);return -1 ; }
@@ -680,7 +687,7 @@ create_event_list_item(struct tracecmd_output *handle,tracecmd_warning ("Insufficient memory" ); } -static int read_ftrace_files (struct tracecmd_output *handle) +static int read_ftrace_files (struct tracecmd_output *handle,bool compress) {struct list_event_system *systems =NULL ;struct tracecmd_event_list list = { .glob ="ftrace/*" };
@@ -693,9 +700,15 @@ static int read_ftrace_files(struct tracecmd_output *handle) }create_event_list_item (handle, &systems, &list); - +if (compress) +out_compression_start (handle); ret =copy_event_system (handle, systems); - +if (compress) { +if (!ret) + ret =out_compression_end (handle); +else +out_compression_reset (handle); + }free_list_events (systems); handle->file_state =TRACECMD_FILE_FTRACE_EVENTS ;
@@ -717,7 +730,7 @@ create_event_list(struct tracecmd_output *handle, }static int read_event_files (struct tracecmd_output *handle, -struct tracecmd_event_list *event_list) +struct tracecmd_event_list *event_list,bool compress) {struct list_event_system *systems;struct list_event_system *slist;
@@ -748,12 +761,12 @@ static int read_event_files(struct tracecmd_output *handle,for (slist = systems; slist; slist = slist->next) count++; - +if (compress) +out_compression_start (handle); ret =-1 ; endian4 =convert_endian_4 (handle, count);if (do_write_check (handle, &endian4,4 )) goto out_free; - ret =0 ;for (slist = systems; !ret && slist; slist = slist->next) { if (do_write_check(handle, slist->name,
@@ -763,9 +776,19 @@ static int read_event_files(struct tracecmd_output *handle, } ret =copy_event_system (handle, slist); } - - handle->file_state =TRACECMD_FILE_ALL_EVENTS ; +if (ret) + goto out_free; +if (compress) { + ret =out_compression_end (handle); +if (ret) + goto out_free; + } out_free: +if (!ret) + handle->file_state =TRACECMD_FILE_ALL_EVENTS ; +else +out_compression_reset (handle); +free_list_events (systems);return ret;
@@ -811,7 +834,7 @@ err:tracecmd_warning ("can't set kptr_restrict" ); } -static int read_proc_kallsyms (struct tracecmd_output *handle) +static int read_proc_kallsyms (struct tracecmd_output *handle,bool compress) {unsigned int size, check_size, endian4;const char *path ="/proc/kallsyms" ;
@@ -827,19 +850,21 @@ static int read_proc_kallsyms(struct tracecmd_output *handle)if (handle->kallsyms) path = handle->kallsyms; +if (compress) +out_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);
@@ -847,16 +872,25 @@ 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 ; +if (compress) { + ret =out_compression_end (handle); +if (ret) + goto out; + } +out: +if (!ret) + handle->file_state =TRACECMD_FILE_KALLSYMS ; +else +out_compression_reset (handle); +return ret; } -static int read_ftrace_printk (struct tracecmd_output *handle) +static int read_ftrace_printk (struct tracecmd_output *handle,bool compress) {unsigned int size, check_size, endian4;struct stat st;
@@ -873,6 +907,8 @@ static int read_ftrace_printk(struct tracecmd_output *handle)if (!path)return -1 ; +if (compress) +out_compression_start (handle); ret =stat (path, &st);if (ret <0 ) {/* not found */
@@ -894,11 +930,14 @@ static int read_ftrace_printk(struct tracecmd_output *handle) } out: - handle->file_state =TRACECMD_FILE_PRINTK ;put_tracing_file (path); +if (compress &&out_compression_end (handle)) +return -1 ; + handle->file_state =TRACECMD_FILE_PRINTK ;return 0 ; fail:put_tracing_file (path); +out_compression_reset (handle);return -1 ; }
@@ -1267,21 +1306,25 @@ int tracecmd_output_write_init(struct tracecmd_output *handler)int tracecmd_output_write_headers (struct tracecmd_output *handler,struct tracecmd_event_list *list) { +bool compress = false; +if (!handler || handler->file_state <TRACECMD_FILE_ALLOCATED )return -1 ;/* Write init data, if not written yet */ if (handler->file_state <TRACECMD_FILE_INIT &&tracecmd_output_write_init (handler))return -1 ; -if (read_header_files (handler)) +if (handler->compress) + compress = true; +if (read_header_files (handler, compress))return -1 ; -if (read_ftrace_files (handler)) +if (read_ftrace_files (handler, compress))return -1 ; -if (read_event_files (handler, list)) +if (read_event_files (handler, list, compress))return -1 ; -if (read_proc_kallsyms (handler)) +if (read_proc_kallsyms (handler, compress))return -1 ; -if (read_ftrace_printk (handler)) +if (read_ftrace_printk (handler, compress))return -1 ;return 0 ; }
@@ -1526,9 +1569,19 @@ int tracecmd_write_cmdlines(struct tracecmd_output *handle) handle->file_state);return -1 ; } + +if (handle->compress) +out_compression_start (handle); + ret =save_tracing_file_data (handle,"saved_cmdlines" ); -if (ret <0 ) +if (ret <0 ) { +out_compression_reset (handle);return ret; + } + +if (handle->compress &&out_compression_end (handle)) +return -1 ; + handle->file_state =TRACECMD_FILE_CMD_LINES ;return 0 ; }
Signature · 1 line
2.31.1
PATCH 21/87 trace-cmd library: Add internal helper functon for writing headers before file sections
In reply to Tzvetomir Stoyanov (VMware)Introduce headers before each file section, in trace file version 7. The section header has the following format:
<2 bytes>, header ID
<string>, null terminated ASCII string, description of the header <2 bytes>, section flags:
1: the section is compressed
<4 bytes>, size of the section
--- include/trace-cmd/trace-cmd.h | 5 ++ .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/include/trace-cmd-local.h | 4 ++ lib/trace-cmd/trace-output.c | 70 +++++++++++++++++++ 4 files changed, 80 insertions(+)
include/trace-cmd/trace-cmd.h +5 -0
@@ -15,6 +15,11 @@ enum tracecmd_open_flags {TRACECMD_FL_LOAD_NO_PLUGINS =1 <<0 ,/* Do not load plugins */ TRACECMD_FL_LOAD_NO_SYSTEM_PLUGINS = 1 << 1, /* Do not load system plugins */ }; + +enum tracecmd_section_flags { +TRACECMD_SEC_FL_COMPRESS =1 <<0 ,/* the section is compressed */ +}; +struct tracecmd_input *tracecmd_open_head (const char *file,int flags);struct tracecmd_input *tracecmd_open (const char *file,int flags);struct tracecmd_input *tracecmd_open_fd (int fd,int flags);
lib/trace-cmd/include/private/trace-cmd-private.h +1 -0
@@ -135,6 +135,7 @@ enum {TRACECMD_OPTION_TIME_SHIFT ,TRACECMD_OPTION_GUEST ,TRACECMD_OPTION_TSC2NSEC , + TRACECMD_OPTION_MAX, }; enum {
lib/trace-cmd/include/trace-cmd-local.h +4 -0
@@ -42,6 +42,10 @@ int in_uncompress_block(struct tracecmd_input *handle);unsigned long long out_copy_fd_compress (struct tracecmd_output *handle,int fd,unsigned long long max,unsigned long long *write_size); +unsigned long long +out_write_section_header (struct tracecmd_output *handle,unsigned short header_id, +char *description,enum tracecmd_section_flags flags,bool option); +int out_update_section_header (struct tracecmd_output *handle,unsigned long long offset);off64_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off_t offset,int whence);
lib/trace-cmd/trace-output.c +70 -0
76 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 22/87 trace-cmd library: Write header before file sections
In reply to Tzvetomir Stoyanov (VMware)Headers are added before these file secrtions, in trace
file version 7:
- 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
New options are defined for each of these sections, holding the section's offset into the trace file.
--- .../include/private/trace-cmd-private.h | 6 ++ lib/trace-cmd/trace-output.c | 69 +++++++++++++++++++ 2 files changed, 75 insertions(+)
lib/trace-cmd/include/private/trace-cmd-private.h +6 -0
@@ -135,6 +135,12 @@ enum {TRACECMD_OPTION_TIME_SHIFT ,TRACECMD_OPTION_GUEST ,TRACECMD_OPTION_TSC2NSEC , +TRACECMD_OPTION_HEADER_INFO , +TRACECMD_OPTION_FTRACE_EVENTS , +TRACECMD_OPTION_EVENT_FORMATS , +TRACECMD_OPTION_KALLSYMS , +TRACECMD_OPTION_PRINTK , +TRACECMD_OPTION_CMDLINES , TRACECMD_OPTION_MAX, };
lib/trace-cmd/trace-output.c +69 -0
195 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 23/87 trace-cmd library: Refactor the logic for writing trace data in the file
In reply to Tzvetomir Stoyanov (VMware)When a trace buffer data are written in the trace file, the buffer option in the file metadata is updated with the file offset of the tracing data. Hide this logic into the trace-cmd library. Added new APIs:
tracecmd_add_buffer_info() tracecmd_write_buffer_info()
Changed APIs:
tracecmd_append_buffer_cpu_data()
Removed APIs:
tracecmd_add_buffer_option()
Refactored the internal logic of tracecmd_write_cpu_data() API to be suitable for adding trace data compression. The size and the offset of the trace data is saved in the file right after the data is written. The old logic calculates the size and offset in advance, but when the trace data is compressed it is hard to use that approach.
--- .../include/private/trace-cmd-private.h | 10 +- lib/trace-cmd/include/trace-cmd-local.h | 16 + lib/trace-cmd/trace-output.c | 314 ++++++++++++------ tracecmd/trace-listen.c | 2 +- tracecmd/trace-record.c | 18 +- 5 files changed, 240 insertions(+), 120 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +4 -6
@@ -305,8 +305,8 @@ struct tracecmd_option * tracecmd_add_option_v(struct tracecmd_output *handle, unsigned short id, const struct iovec *vector, int count); -struct tracecmd_option *tracecmd_add_buffer_option (struct tracecmd_output *handle, -const char *name,int cpus); +int tracecmd_add_buffer_info (struct tracecmd_output *handle,const char *name,int cpus); +int tracecmd_write_buffer_info (struct tracecmd_output *handle);int tracecmd_write_cpus (struct tracecmd_output *handle,int cpus);int tracecmd_write_cmdlines (struct tracecmd_output *handle);
@@ -318,13 +318,11 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char *file);int tracecmd_write_cpu_data (struct tracecmd_output *handle, -int cpus,char *const *cpu_data_files); +int cpus,char *const *cpu_data_files,const char *buff_name);int tracecmd_append_cpu_data (struct tracecmd_output *handle,int cpus,char *const *cpu_data_files);int tracecmd_append_buffer_cpu_data (struct tracecmd_output *handle, -struct tracecmd_option *option, -int cpus,char *const *cpu_data_files); - +const char *name,int cpus,char *const *cpu_data_files);struct tracecmd_output *tracecmd_get_output_handle_fd (int fd);unsigned long tracecmd_get_out_file_version (struct tracecmd_output *handle);
lib/trace-cmd/include/trace-cmd-local.h +16 -0
@@ -24,6 +24,14 @@ void tracecmd_info(const char *fmt, ...);#endif #endif +struct data_file_write { +unsigned long long file_size; +unsigned long long write_size; +unsigned long long soffset; +unsigned long long data_offset; +unsigned long long doffset; +}; +void tracecmd_compress_init (void );void tracecmd_compress_free (void );
@@ -47,6 +55,14 @@ out_write_section_header(struct tracecmd_output *handle, unsigned short header_i char *description, enum tracecmd_section_flags flags, bool option);int out_update_section_header (struct tracecmd_output *handle,unsigned long long offset); +struct cpu_data_source { +int fd; +int size; +off64_t offset; +}; + +int out_write_cpu_data (struct tracecmd_output *handle,int cpus, +struct cpu_data_source *data,const char *buff_name);off64_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off_t offset,int whence);
lib/trace-cmd/trace-output.c +213 -101
437 lines not on this page · raw message
tracecmd/trace-listen.c +1 -1
@@ -610,7 +610,7 @@ static int put_together_file(int cpus, int ofd, const char *node,if (ret) goto out; } - ret =tracecmd_write_cpu_data (handle, cpus, temp_files); + ret =tracecmd_write_cpu_data (handle, cpus, temp_files,"" ); out:tracecmd_output_close (handle);
tracecmd/trace-record.c +6 -12
@@ -4187,7 +4187,6 @@ static void touch_file(const char *file) }static void append_buffer (struct tracecmd_output *handle, -struct tracecmd_option *buffer_option,struct buffer_instance *instance,char **temp_files) {
@@ -4215,7 +4214,7 @@ static void append_buffer(struct tracecmd_output *handle,touch_file (temp_files[i]); } -tracecmd_append_buffer_cpu_data (handle, buffer_option, +tracecmd_append_buffer_cpu_data (handle,tracefs_instance_get_name (instance->tracefs), cpu_count, temp_files);for (i =0 ; i < instance->cpu_count; i++) {
@@ -4465,7 +4464,7 @@ static void write_guest_file(struct buffer_instance *instance)die ("failed to allocate memory" ); } -if (tracecmd_write_cpu_data (handle, cpu_count, temp_files) <0 ) +if (tracecmd_write_cpu_data (handle, cpu_count, temp_files,"" ) <0 )die ("failed to write CPU data" );tracecmd_output_close (handle);
@@ -4508,7 +4507,6 @@ error:static void record_data (struct common_record_context *ctx) { -struct tracecmd_option **buffer_options;struct tracecmd_output *handle;struct buffer_instance *instance;bool local = false;
@@ -4578,9 +4576,6 @@ static void record_data(struct common_record_context *ctx) }if (buffers) { - buffer_options =malloc (sizeof (*buffer_options) * buffers); -if (!buffer_options) -die ("Failed to allocate buffer options" ); i =0 ;for_each_instance (instance) { int cpus = instance->cpu_count != local_cpu_count ?
@@ -4588,10 +4583,9 @@ static void record_data(struct common_record_context *ctx)if (instance->msg_handle)continue ; - - buffer_options[i++] =tracecmd_add_buffer_option (handle, -tracefs_instance_get_name (instance->tracefs), - cpus); +tracecmd_add_buffer_info (handle, +tracefs_instance_get_name (instance->tracefs), + cpus);add_buffer_stat (handle, instance); } }
@@ -4626,7 +4620,7 @@ static void record_data(struct common_record_context *ctx)if (instance->msg_handle)continue ;print_stat (instance); -append_buffer (handle, buffer_options[i++], instance, temp_files); +append_buffer (handle, instance, temp_files); } }
Signature · 1 line
2.31.1
Re: [PATCH 23/87] trace-cmd library: Refactor the logic for writing trace data in the file
lib/trace-cmd/include/trace-cmd-local.h void tracecmd_info(const char *fmt, ...); · line 30
Quoted 8 lines · On Wed, 28 Jul 2021 16:31:46 +0300 "Tzvetomir Stoyanov (VMware)"…
lib/trace-cmd/include/trace-cmd-local.h +4
-0@@ -24,6 +24,14 @@ void tracecmd_info(const char *fmt, ...);#endif #endif +struct data_file_write { +unsigned long long file_size; +unsigned long long write_size; +unsigned long long soffset;
Please add comments. What is soffset?
lib/trace-cmd/include/trace-cmd-local.h void tracecmd_info(const char *fmt, ...); · line 32
Quoted 2 lines
lib/trace-cmd/include/trace-cmd-local.h +2
-0+unsigned long long data_offset; +unsigned long long doffset;
And what is doffset?
Quoted 188 lines
lib/trace-cmd/include/trace-cmd-local.h +10
-0+}; +void tracecmd_compress_init (void );void tracecmd_compress_free (void );@@ -47,6 +55,14 @@ out_write_section_header(struct tracecmd_output *handle, unsigned short header_i char *description, enum tracecmd_section_flags flags, bool option);int out_update_section_header (struct tracecmd_output *handle,unsigned long long offset); +struct cpu_data_source { +int fd; +int size; +off64_t offset; +}; + +int out_write_cpu_data (struct tracecmd_output *handle,int cpus, +struct cpu_data_source *data,const char *buff_name);off64_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off_t offset,int whence);lib/trace-cmd/trace-output.c +98
-4@@ -39,6 +39,14 @@ struct tracecmd_option {struct list_head list; }; +struct tracecmd_buffer { +int cpus; +void *name; +tsize_t offset; +struct tracecmd_option *option; +struct list_head list; +}; +enum {OUTPUT_FL_SEND_META = (1 <<0 ), };@@ -61,6 +69,7 @@ struct tracecmd_output {struct tracecmd_compression *compress;struct list_head options; +struct list_head buffers;struct tracecmd_msg_handle *msg_handle;char *trace_clock; };@@ -201,6 +210,7 @@ bool tracecmd_get_quiet(struct tracecmd_output *handle)void tracecmd_output_free (struct tracecmd_output *handle) {struct tracecmd_option *option; +struct tracecmd_buffer *buffer;if (!handle)return ;@@ -211,6 +221,13 @@ void tracecmd_output_free(struct tracecmd_output *handle)if (handle->pevent)tep_unref (handle->pevent); +while (!list_empty (&handle->buffers)) { + buffer =container_of (handle->buffers.next, + struct tracecmd_buffer, list); +list_del (&buffer->list); +free (buffer->name); +free (buffer); + }while (!list_empty (&handle->options)) { option =container_of (handle->options.next, struct tracecmd_option, list);@@ -1157,6 +1174,7 @@ struct tracecmd_output *tracecmd_output_allocate(int fd) handle->big_endian = false;list_head_init (&handle->options); +list_head_init (&handle->buffers); handle->file_state =TRACECMD_FILE_ALLOCATED ;@@ -1657,15 +1675,14 @@ int tracecmd_append_options(struct tracecmd_output *handle)return 0 ; } -struct tracecmd_option * -tracecmd_add_buffer_option (struct tracecmd_output *handle,const char *name, -int cpus) +static struct tracecmd_option * +add_buffer_option (struct tracecmd_output *handle,const char *name,int cpus) {struct tracecmd_option *option;char *buf;int size =8 +strlen (name) +1 ; - buf =malloc (size); + buf =calloc (1 , size);if (!buf) {tracecmd_warning ("Failed to malloc buffer" );return NULL ;@@ -1687,6 +1704,52 @@ tracecmd_add_buffer_option(struct tracecmd_output *handle, const char *name,return option; } +int tracecmd_add_buffer_info (struct tracecmd_output *handle,const char *name,int cpus) +{ +struct tracecmd_buffer *buf; + + buf =calloc (1 ,sizeof (struct tracecmd_buffer )); +if (!buf) +return -1 ; + buf->name =strdup (name); + buf->cpus = cpus; +if (!buf->name) { +free (buf); +return -1 ; + } +list_add_tail (&buf->list, &handle->buffers); +return 0 ; +} + +int tracecmd_write_buffer_info (struct tracecmd_output *handle) +{ +struct tracecmd_option *option; +struct tracecmd_buffer *buf; + +list_for_each_entry (buf, &handle->buffers, list) { + option =add_buffer_option (handle, buf->name, buf->cpus); +if (!option) +return -1 ; + buf->option = option; + } + +return 0 ; +} + +static tsize_t get_buffer_file_offset (struct tracecmd_output *handle,const char *name) +{ +struct tracecmd_buffer *buf; + +list_for_each_entry (buf, &handle->buffers, list) { +if (strlen (name) ==strlen (buf->name) && !strcmp (name, buf->name)) { +if (!buf->option) +break ; +return buf->option->offset; + } + } +return 0 ; +} +int tracecmd_write_cmdlines (struct tracecmd_output *handle) {enum tracecmd_section_flags flags =0 ;@@ -1804,6 +1867,37 @@ out:return ret; } +static int update_buffer_cpu_offset (struct tracecmd_output *handle, +const char *name,tsize_t offset) +{ +tsize_t b_offset; +tsize_t current; + + b_offset =get_buffer_file_offset (handle, name); +if (!b_offset) { +tracecmd_warning ("Cannot find description for buffer %s\n" , name); +return -1 ; + } + current =do_lseek (handle,0 ,SEEK_CUR ); + +/* Go to the option data, where will write the offest */ +if (do_lseek (handle, b_offset,SEEK_SET ) == (off64_t)-1 ) { +tracecmd_warning ("could not seek to %lld\n" , b_offset); +return -1 ; + } + +if (do_write_check (handle, &offset,8 )) +return -1 ; + +/* Go back to end of file */ +if (do_lseek (handle, current,SEEK_SET ) == (off64_t)-1 ) { +tracecmd_warning ("could not seek to %lld\n" , offset); +return -1 ; + } +return 0 ; +} + +static char *get_clock (struct tracecmd_output *handle) {struct tracefs_instance *inst;
lib/trace-cmd/trace-output.c static char *get_clock(struct tracecmd_output *handle) · line 1921
Quoted 7 lines
lib/trace-cmd/trace-output.c +2
-2@@ -1823,120 +1917,158 @@ static char *get_clock(struct tracecmd_output *handle)return handle->trace_clock; } -int tracecmd_write_cpu_data (struct tracecmd_output *handle, -int cpus,char *const *cpu_data_files) + +__hidden int out_write_cpu_data(struct tracecmd_output *handle,
Nit, but "out_write_cpu_data" is an awkward name, and I'm not sure what it is doing. Should have a comment, and possibly be called "write_out_cpu_data()"?
Quoted 187 lines
lib/trace-cmd/trace-output.c +75
-68+ int cpus, struct cpu_data_source *data, const char *buff_name) { -off64_t *offsets =NULL ; -unsigned long long *sizes =NULL ; -off64_t offset; + struct data_file_write *data_files = NULL; +tsize_t data_offs, offset;unsigned long long endian8; -char *clock =NULL ; -off64_t check_size; -char *file; -struct stat st; +unsigned long long read_size; +char *clock;int ret;int i;/* This can be called multiple times (when recording instances) */ ret = handle->file_state ==TRACECMD_FILE_CPU_FLYRECORD ?0 : -check_out_state (handle,TRACECMD_FILE_CPU_FLYRECORD ); +check_file_state (handle->file_version, + handle->file_state, +TRACECMD_FILE_CPU_FLYRECORD );if (ret <0 ) {tracecmd_warning ("Cannot write trace data into the file, unexpected state 0x%X" , handle->file_state); goto out_free; } + data_offs =do_lseek (handle,0 ,SEEK_CUR );if (do_write_check (handle,"flyrecord" ,10 )) goto out_free; - offsets =malloc (sizeof (*offsets) * cpus); -if (!offsets) + data_files =calloc (cpus,sizeof (struct data_file_write )); +if (!data_files) goto out_free; - sizes =malloc (sizeof (*sizes) * cpus); -if (!sizes) - goto out_free; - - offset =lseek64 (handle->fd,0 ,SEEK_CUR ); -/* hold any extra data for data */ - offset += cpus * (16 ); +for (i =0 ; i < cpus; i++) { + data_files[i].file_size = data[i].size; +/* Write 0 for trace data offset and size and store offsets of these fields */ +if (handle->file_version <7 ) { + endian8 =0 ; + data_files[i].doffset =do_lseek (handle,0 ,SEEK_CUR ); +if (do_write_check (handle, &endian8,8 )) + goto out_free; + data_files[i].soffset =do_lseek (handle,0 ,SEEK_CUR ); +if (do_write_check (handle, &endian8,8 )) + goto out_free; + } + } -/* -* Unfortunately, the trace_clock data was placed after the -* cpu data, and wasn't accounted for with the offsets. -* We need to save room for the trace_clock file. This means -* we need to find the size of it before we define the final -* offsets. -*/ +update_buffer_cpu_offset (handle, buff_name, data_offs); clock =get_clock (handle); -if (!clock) +if (clock &&save_clock (handle, clock)) goto out_free; -/* Save room for storing the size */ - offset +=8 ; - offset +=strlen (clock); -/* 2 bytes for [] around the clock */ - offset +=2 ; - -/* Page align offset */ - offset = (offset + (handle->page_size -1 )) & ~(handle->page_size -1 );for (i =0 ; i < cpus; i++) { - file = cpu_data_files[i]; - ret =stat (file, &st); -if (ret <0 ) { -tracecmd_warning ("can not stat '%s'" , file); + data_files[i].data_offset =do_lseek (handle,0 ,SEEK_CUR ); +/* Page align offset */ + data_files[i].data_offset = (data_files[i].data_offset + (handle->page_size -1 )) & ~(handle->page_size -1 ); + data_files[i].data_offset =do_lseek (handle, data_files[i].data_offset,SEEK_SET ); +if (data_files[i].data_offset == (off64_t)-1 ) + goto out_free; +if (!tracecmd_get_quiet (handle)) +fprintf (stderr,"CPU%d data recorded at offset=0x%llx\n" , + i, (unsigned long long ) data_files[i].data_offset); +if (lseek64 (data[i].fd, data[i].offset,SEEK_SET ) == (off64_t)-1 ) goto out_free; +if (data[i].size) { + read_size =copy_file_fd (handle, data[i].fd); +if (read_size != data_files[i].file_size) { + errno =EINVAL ; +tracecmd_warning ("did not match size of %lld to %lld" , + read_size, data_files[i].file_size); + goto out_free; + } + }else { + data_files[i].write_size =0 ; } - offsets[i] = offset; - sizes[i] = st.st_size; - offset += st.st_size; - offset = (offset + (handle->page_size -1 )) & ~(handle->page_size -1 ); - endian8 =convert_endian_8 (handle, offsets[i]); -if (do_write_check (handle, &endian8,8 )) +/* Write the real CPU data offset in the file */ +if (do_lseek (handle, data_files[i].doffset,SEEK_SET ) == (off64_t)-1 ) goto out_free; - endian8 =convert_endian_8 (handle, sizes[i]); + endian8 =convert_endian_8 (handle, data_files[i].data_offset);if (do_write_check (handle, &endian8,8 )) goto out_free; - } - -if (save_clock (handle, clock)) - goto out_free; - -for (i =0 ; i < cpus; i++) { -if (!tracecmd_get_quiet (handle)) -fprintf (stderr,"CPU%d data recorded at offset=0x%llx\n" , - i, (unsigned long long ) offsets[i]); - offset =lseek64 (handle->fd, offsets[i],SEEK_SET ); -if (offset == (off64_t)-1 ) { -tracecmd_warning ("could not seek to %lld\n" , offsets[i]); +/* Write the real CPU data size in the file */ +if (do_lseek (handle, data_files[i].soffset,SEEK_SET ) == (off64_t)-1 ) goto out_free; - } - check_size =copy_file (handle, cpu_data_files[i]); -if (check_size != sizes[i]) { - errno =EINVAL ; -tracecmd_warning ("did not match size of %lld to %lld" , - check_size, sizes[i]); + endian8 =convert_endian_8 (handle, data_files[i].write_size); +if (do_write_check (handle, &endian8,8 )) + goto out_free; + offset = data_files[i].data_offset + data_files[i].write_size; +if (do_lseek (handle, offset,SEEK_SET ) == (off64_t)-1 ) goto out_free; - }if (!tracecmd_get_quiet (handle))fprintf (stderr," %llu bytes in size\n" , - (unsigned long long )check_size); + (unsigned long long )data_files[i].write_size); } -free (offsets); -free (sizes); +if (do_lseek (handle,0 ,SEEK_END ) == (off64_t)-1 ) + goto out_free; +free (data_files); handle->file_state =TRACECMD_FILE_CPU_FLYRECORD ;return 0 ; out_free: -free (offsets); -free (sizes); +do_lseek (handle,0 ,SEEK_END ); +free (data_files);return -1 ; } +int tracecmd_write_cpu_data (struct tracecmd_output *handle, +int cpus,char *const *cpu_data_files,const char *buff_name) +{ +struct cpu_data_source *data; +struct stat st; +int size =0 ; +int ret; +int i; + + data =calloc (cpus,sizeof (struct cpu_data_source )); +if (!data) +return -1 ; +for (i =0 ; i < cpus; i++)
lib/trace-cmd/trace-output.c static char *get_clock(struct tracecmd_output *handle) · line 2050
Quoted 10 lines
lib/trace-cmd/trace-output.c +10
-0+ data[i].fd =-1 ; +for (i =0 ; i < cpus; i++) { + ret =stat (cpu_data_files[i], &st); +if (ret <0 ) { +tracecmd_warning ("can not stat '%s'" , cpu_data_files[i]); +break ; + } + data[i].fd =open (cpu_data_files[i],O_RDONLY ); +if (data[i].fd <0 ) { +tracecmd_warning ("Can't read '%s'" , data[i].fd);
I would add ret = -1 here.
lib/trace-cmd/trace-output.c static char *get_clock(struct tracecmd_output *handle) · line 2062
Quoted 12 lines
lib/trace-cmd/trace-output.c +12
-0+break ; + } + + data[i].size = st.st_size; + data[i].offset =0 ; + size += st.st_size; + } + +if (i < cpus) + ret =-1 ; +else + ret =out_write_cpu_data (handle, cpus, data, buff_name);
Then the above can be:
if (i == cpus) ret = write_out_cpu_data(handle, cpus, data, buff_name);
And not have the else statement. Makes the code flow a bit nicer.
Quoted 47 lines
lib/trace-cmd/trace-output.c +14
-18+ +for (i =0 ; i < cpus; i++) { +if (data[i].fd >=0 ) +close (data[i].fd); + } +free (data); +return ret; +} +int tracecmd_append_cpu_data (struct tracecmd_output *handle,int cpus,char *const *cpu_data_files) {@@ -1945,41 +2077,20 @@ int tracecmd_append_cpu_data(struct tracecmd_output *handle, ret =tracecmd_write_cpus (handle, cpus);if (ret)return ret; - + ret =tracecmd_write_buffer_info (handle); +if (ret) +return ret; ret =tracecmd_write_options (handle);if (ret)return ret; -return tracecmd_write_cpu_data (handle, cpus, cpu_data_files); +return tracecmd_write_cpu_data (handle, cpus, cpu_data_files,"" ); }int tracecmd_append_buffer_cpu_data (struct tracecmd_output *handle, -struct tracecmd_option *option, -int cpus,char *const *cpu_data_files) +const char *name,int cpus,char *const *cpu_data_files) { -tsize_t offset; -stsize_t ret; - - offset =lseek64 (handle->fd,0 ,SEEK_CUR ); - -/* Go to the option data, where will write the offest */ - ret =lseek64 (handle->fd, option->offset,SEEK_SET ); -if (ret == (off64_t)-1 ) { -tracecmd_warning ("could not seek to %lld\n" , option->offset); -return -1 ; - } - -if (do_write_check (handle, &offset,8 )) -return -1 ;
lib/trace-cmd/trace-output.c int tracecmd_append_cpu_data(struct tracecmd_output *handle, · line 2093
Quoted 10 lines
lib/trace-cmd/trace-output.c +1
-9- -/* Go back to end of file */ - ret =lseek64 (handle->fd, offset,SEEK_SET ); -if (ret == (off64_t)-1 ) { -tracecmd_warning ("could not seek to %lld\n" , offset); -return -1 ; - } - -return tracecmd_write_cpu_data (handle, cpus, cpu_data_files); +return tracecmd_write_cpu_data (handle, cpus, cpu_data_files, name);
Now tracecmd_append_buffer_cpu_data() is equivalent to tracecmd_write_cpu_data(). Why have both?
-- Steve
Quoted 95 lines
lib/trace-cmd/trace-output.c +1
-0}struct tracecmd_output *tracecmd_get_output_handle_fd (int fd)@@ -2025,6 +2136,7 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd) handle->file_version =tracecmd_get_in_file_version (ihandle); handle->options_start =tracecmd_get_options_offset (ihandle);list_head_init (&handle->options); +list_head_init (&handle->buffers);if (!tracecmd_get_file_compress_proto (ihandle, &cname, &cver)) { handle->compress = tracecmd_compress_alloc(cname, cver, handle->fd,tracecmd/trace-listen.c +1
-1@@ -610,7 +610,7 @@ static int put_together_file(int cpus, int ofd, const char *node,if (ret) goto out; } - ret =tracecmd_write_cpu_data (handle, cpus, temp_files); + ret =tracecmd_write_cpu_data (handle, cpus, temp_files,"" ); out:tracecmd_output_close (handle);tracecmd/trace-record.c +6
-12@@ -4187,7 +4187,6 @@ static void touch_file(const char *file) }static void append_buffer (struct tracecmd_output *handle, -struct tracecmd_option *buffer_option,struct buffer_instance *instance,char **temp_files) {@@ -4215,7 +4214,7 @@ static void append_buffer(struct tracecmd_output *handle,touch_file (temp_files[i]); } -tracecmd_append_buffer_cpu_data (handle, buffer_option, +tracecmd_append_buffer_cpu_data (handle,tracefs_instance_get_name (instance->tracefs), cpu_count, temp_files);for (i =0 ; i < instance->cpu_count; i++) {@@ -4465,7 +4464,7 @@ static void write_guest_file(struct buffer_instance *instance)die ("failed to allocate memory" ); } -if (tracecmd_write_cpu_data (handle, cpu_count, temp_files) <0 ) +if (tracecmd_write_cpu_data (handle, cpu_count, temp_files,"" ) <0 )die ("failed to write CPU data" );tracecmd_output_close (handle);@@ -4508,7 +4507,6 @@ error:static void record_data (struct common_record_context *ctx) { -struct tracecmd_option **buffer_options;struct tracecmd_output *handle;struct buffer_instance *instance;bool local = false;@@ -4578,9 +4576,6 @@ static void record_data(struct common_record_context *ctx) }if (buffers) { - buffer_options =malloc (sizeof (*buffer_options) * buffers); -if (!buffer_options) -die ("Failed to allocate buffer options" ); i =0 ;for_each_instance (instance) { int cpus = instance->cpu_count != local_cpu_count ?@@ -4588,10 +4583,9 @@ static void record_data(struct common_record_context *ctx)if (instance->msg_handle)continue ; - - buffer_options[i++] =tracecmd_add_buffer_option (handle, -tracefs_instance_get_name (instance->tracefs), - cpus); +tracecmd_add_buffer_info (handle, +tracefs_instance_get_name (instance->tracefs), + cpus);add_buffer_stat (handle, instance); } }@@ -4626,7 +4620,7 @@ static void record_data(struct common_record_context *ctx)if (instance->msg_handle)continue ;print_stat (instance); -append_buffer (handle, buffer_options[i++], instance, temp_files); +append_buffer (handle, instance, temp_files); } }
PATCH 24/87 trace-cmd library: Add local helper function for data compression
In reply to Tzvetomir Stoyanov (VMware)The newly added helper functions read data from a file and compress it, before writing into the trace file. The trace data is comressed in chunks, which are page aligned. A new local define is introduced:
PAGES_IN_CHUNK
which can be used to tune how big a compression chunk is.
--- lib/trace-cmd/trace-output.c | 70 ++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 6 deletions(-)
lib/trace-cmd/trace-output.c +64 -6
@@ -285,18 +285,26 @@ static unsigned long get_size(const char *file)return size; } -static tsize_t copy_file_fd (struct tracecmd_output *handle,int fd) +static tsize_t copy_file_fd (struct tracecmd_output *handle,int fd,unsigned long long max) { +tsize_t rsize =0 ;tsize_t size =0 ;char buf[BUFSIZ ];stsize_t r;do { - r =read (fd, buf,BUFSIZ ); +if (max >0 && (max - size) <BUFSIZ ) + rsize = (max - size); +else + rsize =BUFSIZ ; + + r =read (fd, buf, rsize);if (r >0 ) { size += r;if (do_write_check (handle, buf, r))return 0 ; +if (max >0 && size >= max) +break ; } }while (r >0 );
@@ -314,12 +322,62 @@ static tsize_t copy_file(struct tracecmd_output *handle,tracecmd_warning ("Can't read '%s'" , file);return 0 ; } - size =copy_file_fd (handle, fd); + size =copy_file_fd (handle, fd,0 );close (fd);return size; } +#define PAGES_IN_CHUNK 10 +__hidden unsigned long long out_copy_fd_compress (struct tracecmd_output *handle, +int fd,unsigned long long max, +unsigned long long *write_size) +{ +unsigned long long rsize =0 ; +unsigned long long wsize =0 ; +unsigned long long size; +int ret; + +if (handle->compress) { + rsize = max; + ret =tracecmd_compress_copy_from (handle->compress, fd, +PAGES_IN_CHUNK * handle->page_size, + &rsize, &wsize); +if (ret <0 ) +return 0 ; + + size = rsize; +if (write_size) + *write_size = wsize; + }else { + size =copy_file_fd (handle, fd, max); +if (write_size) + *write_size = size; + } + +return size; +} + +static tsize_t copy_file_compress (struct tracecmd_output *handle, +const char *file,unsigned long long *write_size) +{ +int ret; +int fd; + + fd =open (file,O_RDONLY ); +if (fd <0 ) { +tracecmd_warning ("Can't read '%s'" , file); +return 0 ; + } + + ret =out_copy_fd_compress (handle, fd,0 , write_size); +if (!ret) +tracecmd_warning ("Can't compress '%s'" , file); + +close (fd); +return ret; +} +/* * Finds the path to the debugfs/tracing * Allocates the string and stores it.
@@ -516,7 +574,7 @@ static int read_header_files(struct tracecmd_output *handle, bool compress) endian8 =convert_endian_8 (handle, size);if (do_write_check (handle, &endian8,8 )) goto out_close; - check_size =copy_file_fd (handle, fd); + check_size =copy_file_fd (handle, fd,0 );close (fd);if (size != check_size) {tracecmd_warning ("wrong size for '%s' size=%lld read=%lld" , path, size, check_size);
@@ -542,7 +600,7 @@ static int read_header_files(struct tracecmd_output *handle, bool compress) endian8 =convert_endian_8 (handle, size);if (do_write_check (handle, &endian8,8 )) goto out_close; - check_size =copy_file_fd (handle, fd); + check_size =copy_file_fd (handle, fd,0 );close (fd);if (size != check_size) {tracecmd_warning ("wrong size for '%s'" , path);
@@ -1980,7 +2038,7 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle,if (lseek64 (data[i].fd, data[i].offset,SEEK_SET ) == (off64_t)-1 ) goto out_free;if (data[i].size) { - read_size =copy_file_fd (handle, data[i].fd); + read_size =copy_file_fd (handle, data[i].fd, data[i].size);if (read_size != data_files[i].file_size) { errno =EINVAL ; tracecmd_warning("did not match size of %lld to %lld",
Signature · 1 line
2.31.1
PATCH 25/87 trace-cmd library: Compress the trace data
In reply to Tzvetomir Stoyanov (VMware)If the output file handler supports compression, use it to compress the flyrecord and latency trace data.
--- lib/trace-cmd/trace-output.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/trace-cmd/trace-output.c +3 -2
@@ -1891,7 +1891,7 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, inif (!path) goto out_free; -copy_file (handle, path); +copy_file_compress (handle, path,NULL );put_tracing_file (path);
@@ -2038,7 +2038,8 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle,if (lseek64 (data[i].fd, data[i].offset,SEEK_SET ) == (off64_t)-1 ) goto out_free;if (data[i].size) { - read_size =copy_file_fd (handle, data[i].fd, data[i].size); + read_size =out_copy_fd_compress (handle, data[i].fd, + data[i].size, &data_files[i].write_size);if (read_size != data_files[i].file_size) { errno =EINVAL ; tracecmd_warning("did not match size of %lld to %lld",
Signature · 1 line
2.31.1
PATCH 26/87 tarce-cmd library: Add multiple options sections in trace file version 7
In reply to Tzvetomir Stoyanov (VMware)Introduced chain of options sections in trace file version 7. Extended the "DONE" option to hold the offset into the file to the next options section.
Format of trace file version 7 is extended with a new mandatory field after the compression algorithm header:
<8 bytes>, unsigned long long integer - offset into the trace file
where the first options section is located. This allows to place this section anywhere in the file. As all other sections have corresponding options, describing their offsets into the trace file, this change makes the structure of trace file version 7 flexible.
--- lib/trace-cmd/trace-output.c | 110 ++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 14 deletions(-)
lib/trace-cmd/trace-output.c +96 -14
@@ -63,7 +63,7 @@ struct tracecmd_output {bool quiet;unsigned long file_state;unsigned long file_version; -size_t options_start; +tsize_t options_start;bool big_endian;bool do_compress;struct tracecmd_compression *compress;
@@ -1449,6 +1449,7 @@ int tracecmd_output_set_compression(struct tracecmd_output *handler, const char*/ int tracecmd_output_write_init (struct tracecmd_output *handler) { +unsigned long long offset;char buf[BUFSIZ ];int endian4;
@@ -1485,6 +1486,11 @@ int tracecmd_output_write_init(struct tracecmd_output *handler)if (handler->file_version >=7 ) {if (write_compression_header (handler))return -1 ; +/* Write 0 as options offset and save its location */ + offset =0 ; + handler->options_start =do_lseek (handler,0 ,SEEK_CUR ); +if (do_write_check (handler, &offset,8 )) +return -1 ; } handler->file_state =TRACECMD_FILE_INIT ;
@@ -1559,7 +1565,7 @@ tracecmd_add_option_v(struct tracecmd_output *handle,* We can only add options before tracing data were written. * This may change in the future. */ -if (handle->file_state >TRACECMD_FILE_OPTIONS ) +if (handle->file_version <7 && handle->file_state >TRACECMD_FILE_OPTIONS )return NULL ;for (i =0 ; i < count; i++)
@@ -1572,8 +1578,7 @@ tracecmd_add_option_v(struct tracecmd_output *handle,return NULL ; } } - - option =malloc (sizeof (*option)); + option =calloc (1 ,sizeof (*option));if (!option) {tracecmd_warning ("Could not allocate space for option" );free (data);
@@ -1636,7 +1641,7 @@ int tracecmd_write_cpus(struct tracecmd_output *handle, int cpus)return 0 ; } -int tracecmd_write_options (struct tracecmd_output *handle) +static int write_options_v6 (struct tracecmd_output *handle) {struct tracecmd_option *options;unsigned short option;
@@ -1654,7 +1659,7 @@ int tracecmd_write_options(struct tracecmd_output *handle)if (do_write_check (handle,"options " ,10 ))return -1 ; - + handle->options_start =do_lseek (handle,0 ,SEEK_CUR );list_for_each_entry (options, &handle->options, list) { endian2 =convert_endian_2 (handle, options->id);if (do_write_check (handle, &endian2,2 ))
@@ -1665,7 +1670,7 @@ int tracecmd_write_options(struct tracecmd_output *handle)return -1 ;/* Save the data location in case it needs to be updated */ - options->offset =lseek64 (handle->fd,0 ,SEEK_CUR ); + options->offset =do_lseek (handle,0 ,SEEK_CUR );if (do_write_check (handle, options->data, options->size))
@@ -1678,11 +1683,83 @@ int tracecmd_write_options(struct tracecmd_output *handle)return -1 ; handle->file_state =TRACECMD_FILE_OPTIONS ; +return 0 ; +} + +static int write_options_v7 (struct tracecmd_output *handle) +{ +struct tracecmd_option *options; +unsigned long long endian8; +unsigned short endian2; +unsigned int endian4; +bool new = false; +tsize_t offset; + +/* Check if there are unsaved options */ +list_for_each_entry (options, &handle->options, list) { +if (!options->offset) { + new = true; +break ; + } + } + +if (!new) +return 0 ; + offset =do_lseek (handle,0 ,SEEK_CUR ); +/* Append to the previous options section, if any */ +if (handle->options_start) { +if (do_lseek (handle, handle->options_start,SEEK_SET ) == (off64_t)-1 ) +return -1 ; + endian8 =convert_endian_8 (handle, offset); +if (do_write_check (handle, &endian8,8 )) +return -1 ; +if (do_lseek (handle, offset,SEEK_SET ) == (off_t)-1 ) +return -1 ; + } + offset =out_write_section_header (handle,TRACECMD_OPTION_DONE ,"options" ,0 , false); +if (offset == (off_t)-1 ) +return -1 ; +list_for_each_entry (options, &handle->options, list) { +/* Option is already saved, skip it */ +if (options->offset) +continue ; + endian2 =convert_endian_2 (handle, options->id); +if (do_write_check (handle, &endian2,2 )) +return -1 ; + endian4 =convert_endian_4 (handle, options->size); +if (do_write_check (handle, &endian4,4 )) +return -1 ; +/* Save the data location */ + options->offset =do_lseek (handle,0 ,SEEK_CUR ); +if (do_write_check (handle, options->data, options->size)) +return -1 ; + } + + endian2 =convert_endian_2 (handle,TRACECMD_OPTION_DONE ); +if (do_write_check (handle, &endian2,2 )) +return -1 ; + endian4 =convert_endian_4 (handle,8 ); +if (do_write_check (handle, &endian4,4 )) +return -1 ; + endian8 =0 ; + handle->options_start =do_lseek (handle,0 ,SEEK_CUR ); +if (do_write_check (handle, &endian8,8 )) +return -1 ; +if (out_update_section_header (handle, offset)) +return -1 ;return 0 ; } -int tracecmd_append_options (struct tracecmd_output *handle) +int tracecmd_write_options (struct tracecmd_output *handle) +{ +if (handle->file_version <7 ) +return write_options_v6 (handle); +return write_options_v7 (handle); +} + + +static int append_options_v6 (struct tracecmd_output *handle) {struct tracecmd_option *options;unsigned short option;
@@ -1697,14 +1774,12 @@ int tracecmd_append_options(struct tracecmd_output *handle)*/ if (handle->file_state !=TRACECMD_FILE_OPTIONS )return -1 ; - -if (lseek64 (handle->fd,0 ,SEEK_END ) == (off_t)-1 ) +if (do_lseek (handle,0 ,SEEK_END ) ==-1 )return -1 ; - offset =lseek64 (handle->fd,-2 ,SEEK_CUR ); + offset =do_lseek (handle,-2 ,SEEK_CUR );if (offset == (off_t)-1 )return -1 ; - - r =pread (handle->fd, &option,2 , offset); + r =do_preed (handle, &option,2 , offset);if (r !=2 || option !=TRACECMD_OPTION_DONE )return -1 ;
@@ -1718,7 +1793,7 @@ int tracecmd_append_options(struct tracecmd_output *handle)return -1 ;/* Save the data location in case it needs to be updated */ - options->offset =lseek64 (handle->fd,0 ,SEEK_CUR ); + options->offset =do_lseek (handle,0 ,SEEK_CUR );if (do_write_check (handle, options->data, options->size))
@@ -1733,6 +1808,13 @@ int tracecmd_append_options(struct tracecmd_output *handle)return 0 ; } +int tracecmd_append_options (struct tracecmd_output *handle) +{ +if (handle->file_version <7 ) +return append_options_v6 (handle); +return write_options_v7 (handle); +} +static struct tracecmd_option *add_buffer_option (struct tracecmd_output *handle,const char *name,int cpus) {
Signature · 1 line
2.31.1
PATCH 27/87 trace-cmd library: Do not write CPU count section in trace files version 7
In reply to Tzvetomir Stoyanov (VMware)Writing CPU count as a separate section in the trace file is redundant, as there is already an option for that. Use that option in trace files version 7.
--- lib/trace-cmd/trace-output.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
lib/trace-cmd/trace-output.c +10 -4
@@ -1633,10 +1633,16 @@ int tracecmd_write_cpus(struct tracecmd_output *handle, int cpus) handle->file_state);return -1 ; } - cpus =convert_endian_4 (handle, cpus); - ret =do_write_check (handle, &cpus,4 ); -if (ret <0 ) -return ret; + +if (handle->file_version <7 ) { + cpus =convert_endian_4 (handle, cpus); + ret =do_write_check (handle, &cpus,4 ); +if (ret <0 ) +return ret; + }else { +tracecmd_add_option (handle,TRACECMD_OPTION_CPUCOUNT ,sizeof (int ), &cpus); + } + handle->file_state =TRACECMD_FILE_CPU_COUNT ;return 0 ; }
Signature · 1 line
2.31.1
PATCH 28/87 trace-cmd library: Move CPU flyrecord trace metadata into the buffer option, for trace file version 7
In reply to Tzvetomir Stoyanov (VMware)Extended the BUFFER trace option in trace file version 7 with CPU flyrecord trace metadata. In the version 6 of the trace file, this metadata is located at several places in the file. Part of the metadata is only for the top trace instance, thus limiting per-instance configuration. Moving all CPU trace related metadata in the BUFFER option simplifies the parsing and makes per-instance configuration more flexible. In the new file structure, the top instance is treated as any other instances. The format of the extended BUFFER option is:
- offset of the buffer in the trace file
- name of the buffer
- trace clock, used in this buffer for events timestamps
- count of CPUs with trace data
- array, describing each CPU with trace data:
- CPU id
- offset of CPU trace data in the trace file
- size of the recorded CPU trace data
--- lib/trace-cmd/trace-output.c | 171 ++++++++++++++++++++++++++--------- 1 file changed, 127 insertions(+), 44 deletions(-)
lib/trace-cmd/trace-output.c +127 -44
@@ -1822,7 +1822,7 @@ int tracecmd_append_options(struct tracecmd_output *handle) }static struct tracecmd_option * -add_buffer_option (struct tracecmd_output *handle,const char *name,int cpus) +add_buffer_option_v6 (struct tracecmd_output *handle,const char *name,int cpus) {struct tracecmd_option *option;char *buf;
@@ -1872,8 +1872,11 @@ int tracecmd_write_buffer_info(struct tracecmd_output *handle)struct tracecmd_option *option;struct tracecmd_buffer *buf; +if (handle->file_version >=7 ) +return 0 ; +list_for_each_entry (buf, &handle->buffers, list) { - option =add_buffer_option (handle, buf->name, buf->cpus); + option =add_buffer_option_v6 (handle, buf->name, buf->cpus);if (!option)return -1 ; buf->option = option;
@@ -1934,6 +1937,98 @@ int tracecmd_write_cmdlines(struct tracecmd_output *handle)return 0 ; } +static char *get_clock (struct tracecmd_output *handle) +{ +struct tracefs_instance *inst; + +if (handle->trace_clock) +return handle->trace_clock; + +/* +* If no clock is set on this handle, get the trace clock of +* the top instance in the handle's tracing dir +*/ + inst =tracefs_instance_alloc (handle->tracing_dir,NULL ); +if (!inst) +return NULL ; + handle->trace_clock =tracefs_get_clock (inst); +tracefs_instance_free (inst); +return handle->trace_clock; +} + +__hidden struct tracecmd_option * +out_add_buffer_option_v7 (struct tracecmd_output *handle,const char *name, +unsigned short id,unsigned long long data_offset, +int cpus,struct data_file_write *cpu_data) +{ +struct tracecmd_option *option; +int i, j =0 , k =0 ; +int *cpu_ids =NULL ; +struct iovec *vect; +char *clock; + +if (handle->file_version <7 ) +return NULL ; + + clock =get_clock (handle); + +/* Buffer flyrecord option, v7: +* - trace data offset in the file +* - buffer name +* - buffer clock +* - CPU count +* - for each CPU: +* - CPU id +* - CPU trace data offset in the file +* - CPU trace data size +*/ + +/* Buffer latency option, v7: +* - trace data offset in the file +* - buffer name +* - buffer clock +*/ + + vect =calloc (5 + (cpus *3 ),sizeof (struct iovec )); +if (!vect) +return NULL ; +if (cpus) { + cpu_ids =calloc (cpus,sizeof (int )); +if (!cpu_ids) { +free (vect); +return NULL ; + } + } + vect[j].iov_base = (void *) &data_offset; + vect[j++].iov_len =8 ; + vect[j].iov_base = (void *) name; + vect[j++].iov_len =strlen (name) +1 ; + vect[j].iov_base = (void *) clock; + vect[j++].iov_len =strlen (clock) +1 ; +if (id ==TRACECMD_OPTION_BUFFER ) { + vect[j].iov_base = (void *) &k; + vect[j++].iov_len =4 ; +for (i =0 ; i < cpus; i++) { +if (!cpu_data[i].file_size) +continue ; + cpu_ids[i] = i; + vect[j].iov_base = &cpu_ids[i]; + vect[j++].iov_len =4 ; + vect[j].iov_base = &cpu_data[i].data_offset; + vect[j++].iov_len =8 ; + vect[j].iov_base = &cpu_data[i].write_size; + vect[j++].iov_len =8 ; + k++; + } + } + + option =tracecmd_add_option_v (handle, id, vect, j); +free (vect); +free (cpu_ids); + +return option; +} +struct tracecmd_output *tracecmd_create_file_latency (const char *output_file,int cpus,int file_version) {
@@ -2013,7 +2108,7 @@ out:return ret; } -static int update_buffer_cpu_offset (struct tracecmd_output *handle, +static int update_buffer_cpu_offset_v6 (struct tracecmd_output *handle,const char *name,tsize_t offset) {tsize_t b_offset;
@@ -2043,27 +2138,6 @@ static int update_buffer_cpu_offset(struct tracecmd_output *handle,return 0 ; } - -static char *get_clock (struct tracecmd_output *handle) -{ -struct tracefs_instance *inst; - -if (handle->trace_clock) -return handle->trace_clock; - -/* -* If no clock is set on this handle, get the trace clock of -* the top instance in the handle's tracing dir -*/ - inst =tracefs_instance_alloc (handle->tracing_dir,NULL ); -if (!inst) -return NULL ; - handle->trace_clock =tracefs_get_clock (inst); -tracefs_instance_free (inst); -return handle->trace_clock; -} - - __hidden int out_write_cpu_data(struct tracecmd_output *handle,int cpus,struct cpu_data_source *data,const char *buff_name) {
@@ -2087,7 +2161,7 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, } data_offs =do_lseek (handle,0 ,SEEK_CUR ); -if (do_write_check (handle,"flyrecord" ,10 )) +if (handle->file_version <7 &&do_write_check (handle,"flyrecord" ,10 )) goto out_free; data_files =calloc (cpus,sizeof (struct data_file_write ));
@@ -2108,10 +2182,12 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, } } -update_buffer_cpu_offset (handle, buff_name, data_offs); - clock =get_clock (handle); -if (clock &&save_clock (handle, clock)) - goto out_free; +if (handle->file_version <7 ) { +update_buffer_cpu_offset_v6 (handle, buff_name, data_offs); + clock =get_clock (handle); +if (clock &&save_clock (handle, clock)) + goto out_free; + }for (i =0 ; i < cpus; i++) { data_files[i].data_offset =do_lseek (handle,0 ,SEEK_CUR );
@@ -2138,26 +2214,33 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, data_files[i].write_size =0 ; } -/* Write the real CPU data offset in the file */ -if (do_lseek (handle, data_files[i].doffset,SEEK_SET ) == (off64_t)-1 ) - goto out_free; - endian8 =convert_endian_8 (handle, data_files[i].data_offset); -if (do_write_check (handle, &endian8,8 )) - goto out_free; -/* Write the real CPU data size in the file */ -if (do_lseek (handle, data_files[i].soffset,SEEK_SET ) == (off64_t)-1 ) - goto out_free; - endian8 =convert_endian_8 (handle, data_files[i].write_size); -if (do_write_check (handle, &endian8,8 )) - goto out_free; - offset = data_files[i].data_offset + data_files[i].write_size; -if (do_lseek (handle, offset,SEEK_SET ) == (off64_t)-1 ) - goto out_free; +if (handle->file_version <7 ) { +/* Write the real CPU data offset in the file */ +if (do_lseek (handle, data_files[i].doffset,SEEK_SET ) == (off64_t)-1 ) + goto out_free; + endian8 =convert_endian_8 (handle, data_files[i].data_offset); +if (do_write_check (handle, &endian8,8 )) + goto out_free; +/* Write the real CPU data size in the file */ +if (do_lseek (handle, data_files[i].soffset,SEEK_SET ) == (off64_t)-1 ) + goto out_free; + endian8 =convert_endian_8 (handle, data_files[i].write_size); +if (do_write_check (handle, &endian8,8 )) + goto out_free; + offset = data_files[i].data_offset + data_files[i].write_size; +if (do_lseek (handle, offset,SEEK_SET ) == (off64_t)-1 ) + goto out_free; + }if (!tracecmd_get_quiet (handle))fprintf (stderr," %llu bytes in size\n" , (unsigned long long )data_files[i].write_size); } +if (handle->file_version >=7 && + !out_add_buffer_option_v7 (handle, buff_name, +TRACECMD_OPTION_BUFFER , data_offs, cpus, data_files)) + goto out_free; +if (do_lseek (handle,0 ,SEEK_END ) == (off64_t)-1 ) goto out_free;
Signature · 1 line
2.31.1
PATCH 29/87 trace-cmd record: Append trace options after the trace data are written
In reply to Tzvetomir Stoyanov (VMware)In trace file version 7, the CPU trace metadata is saved in a trace option. As this metadata has file offsets, which depend on the CPU trace data, the option must be written in the file after the CPU trace data.
--- tracecmd/trace-record.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tracecmd/trace-record.c +5 -1
@@ -4466,6 +4466,9 @@ static void write_guest_file(struct buffer_instance *instance)if (tracecmd_write_cpu_data (handle, cpu_count, temp_files,"" ) <0 )die ("failed to write CPU data" ); +if (tracecmd_get_out_file_version (handle) >=7 ) +tracecmd_write_options (handle); +tracecmd_output_close (handle);for (i =0 ; i < cpu_count; i++)
@@ -4623,7 +4626,8 @@ static void record_data(struct common_record_context *ctx)append_buffer (handle, instance, temp_files); } } - +if (tracecmd_get_out_file_version (handle) >=7 ) +tracecmd_write_options (handle);free (temp_files); }if (!handle)
Signature · 1 line
2.31.1
PATCH 30/87 trace-cmd library: Add section header before flyrecord trace data
In reply to Tzvetomir Stoyanov (VMware)In trace file version 7, write a section header at the beginning of each section with flyrecord trace data.
--- lib/trace-cmd/trace-output.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
lib/trace-cmd/trace-output.c +15 -0
@@ -2142,10 +2142,12 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, int cpus, struct cpu_data_source *data, const char *buff_name) { struct data_file_write *data_files = NULL; +enum tracecmd_section_flags flags =0 ;tsize_t data_offs, offset;unsigned long long endian8;unsigned long long read_size;char *clock; +char *str;int ret;int i;
@@ -2164,6 +2166,16 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle,if (handle->file_version <7 &&do_write_check (handle,"flyrecord" ,10 )) goto out_free; +if (handle->compress) + flags |=TRACECMD_SEC_FL_COMPRESS ; +if (asprintf (&str,"buffer flyrecord %s" , buff_name) <1 ) + goto out_free; + + offset =out_write_section_header (handle,TRACECMD_OPTION_BUFFER , str, flags, false); +free (str); +if (offset == (off_t)-1 ) + goto out_free; + data_files =calloc (cpus,sizeof (struct data_file_write ));if (!data_files) goto out_free;
@@ -2244,6 +2256,9 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle,if (do_lseek (handle,0 ,SEEK_END ) == (off64_t)-1 ) goto out_free; +if (out_update_section_header (handle, offset)) + goto out_free; +free (data_files); handle->file_state =TRACECMD_FILE_CPU_FLYRECORD ;
Signature · 1 line
2.31.1
PATCH 31/87 trace-cmd library: Fit CPU latency trace data in the new trace file version 7 format
In reply to Tzvetomir Stoyanov (VMware)Trace file version 7 format is based on sections. To fit the latency trace data in this structure, a new section and option for it is defined:
BUFFER_LAT
It is similar to the BUFFER section which holds the flyrecord data, but has a latency specific design. The BUFFER_LAT section has:
- section header, as all other sections
- compression of the trace data, optional
- corresponding trace option, pointing to the section
--- .../include/private/trace-cmd-private.h | 3 +- lib/trace-cmd/trace-output.c | 36 ++++++++++++++++--- tracecmd/trace-record.c | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +2 -1
@@ -135,6 +135,7 @@ enum {TRACECMD_OPTION_TIME_SHIFT ,TRACECMD_OPTION_GUEST ,TRACECMD_OPTION_TSC2NSEC , +TRACECMD_OPTION_BUFFER_LAT ,TRACECMD_OPTION_HEADER_INFO ,TRACECMD_OPTION_FTRACE_EVENTS , TRACECMD_OPTION_EVENT_FORMATS,
@@ -294,7 +295,7 @@ int tracecmd_output_write_headers(struct tracecmd_output *handler, struct tracecmd_event_list *list);struct tracecmd_output *tracecmd_create_file_latency (const char *output_file,int cpus, -int file_version); +int file_version,const char *compression);struct tracecmd_output *tracecmd_create_init_fd (int fd);struct tracecmd_output *tracecmd_create_init_file (const char *output_file);
lib/trace-cmd/trace-output.c +32 -4
@@ -2030,9 +2030,11 @@ out_add_buffer_option_v7(struct tracecmd_output *handle, const char *name, }struct tracecmd_output *tracecmd_create_file_latency (const char *output_file,int cpus, -int file_version) +int file_version,const char *compression) { +enum tracecmd_section_flags flags =0 ;struct tracecmd_output *handle; +tsize_t offset;char *path;int fd;
@@ -2045,6 +2047,12 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in goto out_free;if (file_version &&tracecmd_output_set_version (handle, file_version)) goto out_free; +if (compression) { +if (tracecmd_output_set_compression (handle, compression)) + goto out_free; + }else if (file_version >=7 ) { +tracecmd_output_set_compression (handle,"any" ); + }if (tracecmd_output_write_init (handle)) goto out_free;if (tracecmd_output_write_headers (handle,NULL ))
@@ -2057,7 +2065,8 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, inif (tracecmd_write_cpus (handle, cpus) <0 ) goto out_free; - +if (tracecmd_write_buffer_info (handle) <0 ) + goto out_free;if (tracecmd_write_options (handle) <0 ) goto out_free;
@@ -2067,23 +2076,42 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in goto out_free; } -if (do_write_check (handle,"latency " ,10 )) +if (handle->file_version <7 &&do_write_check (handle,"latency " ,10 )) goto out_free; path =get_tracing_file (handle,"trace" );if (!path) goto out_free; + offset =do_lseek (handle,0 ,SEEK_CUR ); +if (handle->file_version >=7 && + !out_add_buffer_option_v7 (handle,"" ,TRACECMD_OPTION_BUFFER_LAT , offset,0 ,NULL )) + goto out_free; +if (handle->compress) + flags |=TRACECMD_SEC_FL_COMPRESS ; + + offset =out_write_section_header (handle,TRACECMD_OPTION_BUFFER_LAT , +"buffer latency" , flags, false); +copy_file_compress (handle, path,NULL ); +if (out_update_section_header (handle, offset)) + goto out_free;put_tracing_file (path); handle->file_state =TRACECMD_FILE_CPU_LATENCY ; +if (tracecmd_get_out_file_version (handle) >=7 ) +tracecmd_write_options (handle); +return handle; out_free: -tracecmd_output_close (handle); +if (handle) +tracecmd_output_close (handle); +else +close (fd); +unlink (output_file);return NULL ; }
tracecmd/trace-record.c +1 -1
@@ -4531,7 +4531,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, ctx->compression);tracecmd_set_quiet (handle, quiet); }else {if (!local_cpu_count)
Signature · 1 line
2.31.1
PATCH 32/87 trace-cmd library: Do not write CPUs with empty trace data
In reply to Tzvetomir Stoyanov (VMware)Trace file version 7 has more flexible design, which allows to write only CPUs with trace data in the file. If a CPU has no recorded trace data, do not put it in the trace file version 7.
--- lib/trace-cmd/trace-output.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/trace-cmd/trace-output.c +3 -1
@@ -2331,8 +2331,10 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle,if (i < cpus) ret =-1 ; -else +else if (size || handle->file_version <7 )/* do not write empty trace buffer in v7 files*/ ret =out_write_cpu_data (handle, cpus, data, buff_name); +else + ret =0 ;for (i =0 ; i < cpus; i++) {if (data[i].fd >=0 )
Signature · 1 line
2.31.1
PATCH 33/87 trace-cmd library: Add macro to check file state on reading
In reply to Tzvetomir Stoyanov (VMware)Trace file version 7 has flexible structure. It allows reading almost any part of the file at any time, unlike the version 6 file when reading state must be validated at each step. Added a macro to handle these checks.
--- lib/trace-cmd/trace-input.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
lib/trace-cmd/trace-input.c +10 -8
@@ -166,6 +166,8 @@ struct tracecmd_input { __threadstruct tracecmd_input *tracecmd_curr_thread_handle; +#define CHECK_READ_STATE (H ,S ) ((H)->file_version < 7 && (H)->file_state >= (S)) +static int read_options_type (struct tracecmd_input *handle);void tracecmd_set_flag (struct tracecmd_input *handle,int flag)
@@ -416,7 +418,7 @@ static int read_header_files(struct tracecmd_input *handle)char *header;char buf[BUFSIZ ]; -if (handle->file_state >=TRACECMD_FILE_HEADERS ) +if (CHECK_READ_STATE (handle,TRACECMD_FILE_HEADERS ))return 0 ;if (do_read_check (handle, buf,12 ))
@@ -623,7 +625,7 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex)int unique;int ret; -if (handle->file_state >=TRACECMD_FILE_FTRACE_EVENTS ) +if (CHECK_READ_STATE (handle,TRACECMD_FILE_FTRACE_EVENTS ))return 0 ;if (regex) {
@@ -694,7 +696,7 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex)int unique;int ret; -if (handle->file_state >=TRACECMD_FILE_ALL_EVENTS ) +if (CHECK_READ_STATE (handle,TRACECMD_FILE_ALL_EVENTS ))return 0 ;if (regex) {
@@ -779,7 +781,7 @@ static int read_proc_kallsyms(struct tracecmd_input *handle)unsigned int size;char *buf; -if (handle->file_state >=TRACECMD_FILE_KALLSYMS ) +if (CHECK_READ_STATE (handle,TRACECMD_FILE_KALLSYMS ))return 0 ;if (read4 (handle, &size) <0 )
@@ -810,7 +812,7 @@ static int read_ftrace_printk(struct tracecmd_input *handle)unsigned int size;char *buf; -if (handle->file_state >=TRACECMD_FILE_PRINTK ) +if (CHECK_READ_STATE (handle,TRACECMD_FILE_PRINTK ))return 0 ;if (read4 (handle, &size) <0 )
@@ -856,7 +858,7 @@ static int read_cpus(struct tracecmd_input *handle) {unsigned int cpus; -if (handle->file_state >=TRACECMD_FILE_CPU_COUNT ) +if (CHECK_READ_STATE (handle,TRACECMD_FILE_CPU_COUNT ))return 0 ;if (read4 (handle, &cpus) <0 )
@@ -2862,7 +2864,7 @@ static int read_options_type(struct tracecmd_input *handle) {char buf[10 ]; -if (handle->file_state >=TRACECMD_FILE_CPU_LATENCY ) +if (CHECK_READ_STATE (handle,TRACECMD_FILE_CPU_LATENCY ))return 0 ;if (do_read_check (handle, buf,10 ))
@@ -3026,7 +3028,7 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle)unsigned long long size;char *cmdlines; -if (handle->file_state >=TRACECMD_FILE_CMD_LINES ) +if (CHECK_READ_STATE (handle,TRACECMD_FILE_CMD_LINES ))return 0 ;if (read_data_and_size (handle, &cmdlines, &size) <0 )
Signature · 1 line
2.31.1
PATCH 34/87 trace-cmd library: Introduce sections in trace file reading logic
In reply to Tzvetomir Stoyanov (VMware)Trace file version 7 is based on sections. Added an internal sections database and new helper functions to add, read, open and close file sections.
--- lib/trace-cmd/trace-input.c | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
lib/trace-cmd/trace-input.c +71 -0
@@ -114,6 +114,14 @@ struct tsc2nsec {unsigned long long offset; }; +struct file_section { +int id; +unsigned long long section_offset; +unsigned long long data_offset; +enum tracecmd_section_flags flags; +struct file_section *next; +}; +struct tracecmd_input {struct tep_handle *pevent;unsigned long file_state;
@@ -154,6 +162,7 @@ struct tracecmd_input {struct hook_list *hooks;struct pid_addr_maps *pid_maps;/* file information */ +struct file_section *sections;size_t header_files_start;size_t ftrace_files_start;size_t event_files_start;
@@ -411,6 +420,61 @@ __hidden int in_uncompress_block(struct tracecmd_input *handle)return ret; } +static struct file_section *get_section (struct tracecmd_input *handle,int id) +{ +struct file_section *sec = handle->sections; + +while (sec) { +if (sec->id == id) +return sec; + sec = sec->next; + } +return NULL ; +} + +static struct file_section *open_section (struct tracecmd_input *handle,int id) +{ +struct file_section *sec =get_section (handle, id); + +if (!sec) +return NULL ; + +if (lseek64 (handle->fd, sec->data_offset,SEEK_SET ) == (off64_t)-1 ) +return NULL ; +if ((sec->flags &TRACECMD_SEC_FL_COMPRESS ) &&in_uncompress_block (handle)) +return NULL ; +return sec; +} + +static void close_section (struct tracecmd_input *handle,struct file_section *sec) +{ +if (sec->flags &TRACECMD_SEC_FL_COMPRESS ) +in_uncompress_reset (handle); +} + +static int add_section (struct tracecmd_input *handle,int id,int flags, +unsigned long long soffset,unsigned long long doffset) +{ +struct file_section *sec =get_section (handle, id); + +if (!sec) { + sec =calloc (1 ,sizeof (struct file_section )); +if (!sec) +return -1 ; + sec->next = handle->sections; + handle->sections = sec; + } + sec->id = id; +if (soffset) + sec->section_offset = soffset; +if (doffset) + sec->data_offset = doffset; +if (flags >0 ) + sec->flags = flags; +return 0 ; +} + +static int read_header_files (struct tracecmd_input *handle) {struct tep_handle *pevent = handle->pevent;
@@ -3522,6 +3586,7 @@ void tracecmd_ref(struct tracecmd_input *handle)*/ void tracecmd_close (struct tracecmd_input *handle) { +struct file_section *del_sec;int i;if (!handle)
@@ -3560,6 +3625,11 @@ void tracecmd_close(struct tracecmd_input *handle)free (handle->version);close (handle->fd); +while (handle->sections) { + del_sec = handle->sections; + handle->sections = handle->sections->next; +free (del_sec); + }for (i =0 ; i < handle->nr_buffers; i++)free (handle->buffers[i].name);
@@ -4006,6 +4076,7 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx) new_handle->nr_buffers =0 ; new_handle->buffers =NULL ; new_handle->version =NULL ; + new_handle->sections =NULL ; new_handle->guest =NULL ; new_handle->ref =1 ;if (handle->trace_clock) {
Signature · 1 line
2.31.1
PATCH 35/87 trace-cmd library: Initialize internal sections database on file read
In reply to Tzvetomir Stoyanov (VMware)Add sections in internal database on file reading and parsing. In trace file version 7, sections are initialized when parsing corresponding trace options. In version 6 files, sections are retrieved on file reading, as there they are in a fixed position file.
--- lib/trace-cmd/trace-input.c | 55 +++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 15 deletions(-)
lib/trace-cmd/trace-input.c +40 -15
@@ -165,7 +165,6 @@ struct tracecmd_input {struct file_section *sections;size_t header_files_start;size_t ftrace_files_start; -size_t event_files_start;size_t options_start;size_t total_file_size;
@@ -485,6 +484,10 @@ static int read_header_files(struct tracecmd_input *handle)if (CHECK_READ_STATE (handle,TRACECMD_FILE_HEADERS ))return 0 ; +if (handle->file_version <7 ) +add_section (handle,TRACECMD_OPTION_HEADER_INFO ,0 ,0 , +lseek64 (handle->fd,0 ,SEEK_CUR )); +if (do_read_check (handle, buf,12 ))return -1 ;
@@ -528,9 +531,6 @@ static int read_header_files(struct tracecmd_input *handle)free (header); - handle->ftrace_files_start = -lseek64 (handle->fd,0 ,SEEK_CUR ); - handle->file_state =TRACECMD_FILE_HEADERS ;return 0 ;
@@ -692,6 +692,10 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex)if (CHECK_READ_STATE (handle,TRACECMD_FILE_FTRACE_EVENTS ))return 0 ; +if (handle->file_version <7 ) +add_section (handle,TRACECMD_OPTION_FTRACE_EVENTS ,0 ,0 , +lseek64 (handle->fd,0 ,SEEK_CUR )); +if (regex) { sreg = &spreg; ereg = &epreg;
@@ -730,9 +734,6 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex)return -1 ; } - handle->event_files_start = -lseek64 (handle->fd,0 ,SEEK_CUR ); -if (sreg) {regfree (sreg);regfree (ereg);
@@ -763,6 +764,10 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex)if (CHECK_READ_STATE (handle,TRACECMD_FILE_ALL_EVENTS ))return 0 ; +if (handle->file_version <7 ) +add_section (handle,TRACECMD_OPTION_EVENT_FORMATS ,0 ,0 , +lseek64 (handle->fd,0 ,SEEK_CUR )); +if (regex) { sreg = &spreg; ereg = &epreg;
@@ -848,6 +853,11 @@ static int read_proc_kallsyms(struct tracecmd_input *handle)if (CHECK_READ_STATE (handle,TRACECMD_FILE_KALLSYMS ))return 0 ; +if (handle->file_version <7 ) +add_section (handle,TRACECMD_OPTION_KALLSYMS ,0 ,0 , +lseek64 (handle->fd,0 ,SEEK_CUR )); + +if (read4 (handle, &size) <0 )return -1 ;if (!size)
@@ -879,6 +889,11 @@ static int read_ftrace_printk(struct tracecmd_input *handle)if (CHECK_READ_STATE (handle,TRACECMD_FILE_PRINTK ))return 0 ; +if (handle->file_version <7 ) +add_section (handle,TRACECMD_OPTION_PRINTK ,0 ,0 , +lseek64 (handle->fd,0 ,SEEK_CUR )); + +if (read4 (handle, &size) <0 )return -1 ;if (!size)
@@ -2910,6 +2925,16 @@ static int handle_options(struct tracecmd_input *handle) handle->tsc_calc.offset =tep_read_number (handle->pevent, buf +8 ,8 );break ; +case TRACECMD_OPTION_HEADER_INFO : +case TRACECMD_OPTION_FTRACE_EVENTS : +case TRACECMD_OPTION_EVENT_FORMATS : +case TRACECMD_OPTION_KALLSYMS : +case TRACECMD_OPTION_PRINTK : +case TRACECMD_OPTION_CMDLINES : +if (size <8 ) +break ; +add_section (handle, option,-1 ,tep_read_number (handle->pevent, buf,8 ),0 ); +break ;default :tracecmd_warning ("unknown option %d" , option);break ;
@@ -3095,6 +3120,10 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle)if (CHECK_READ_STATE (handle,TRACECMD_FILE_CMD_LINES ))return 0 ; +if (handle->file_version <7 ) +add_section (handle,TRACECMD_OPTION_CMDLINES ,0 ,0 , +lseek64 (handle->fd,0 ,SEEK_CUR )); +if (read_data_and_size (handle, &cmdlines, &size) <0 )return -1 ; cmdlines[size] =0 ;
@@ -3384,6 +3413,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)struct tracecmd_input *handle;char test[] =TRACECMD_MAGIC ;unsigned int page_size; +size_t offset;char *version;char buf[BUFSIZ ];unsigned long ver;
@@ -3444,14 +3474,9 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)read4 (handle, &page_size); handle->page_size = page_size; - handle->header_files_start = -lseek64 (handle->fd,0 ,SEEK_CUR ); - - handle->total_file_size = -lseek64 (handle->fd,0 ,SEEK_END ); - - handle->header_files_start = -lseek64 (handle->fd, handle->header_files_start,SEEK_SET ); + offset =lseek64 (handle->fd,0 ,SEEK_CUR ); + handle->total_file_size =lseek64 (handle->fd,0 ,SEEK_END ); +lseek64 (handle->fd, offset,SEEK_SET ); handle->file_state =TRACECMD_FILE_INIT ;
Signature · 1 line
2.31.1
PATCH 36/87 trace-cmd library: Use sections database when reading parts of the trace file
In reply to Tzvetomir Stoyanov (VMware)Utilize the internal database with file sections, when reading parts of a trace file. This logic unifies the way trace file version 6 and 7 are processed.
--- lib/trace-cmd/trace-input.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-)
lib/trace-cmd/trace-input.c +21 -13
@@ -163,8 +163,6 @@ struct tracecmd_input {struct pid_addr_maps *pid_maps;/* file information */ struct file_section *sections; -size_t header_files_start; -size_t ftrace_files_start;size_t options_start;size_t total_file_size;
@@ -3301,21 +3299,26 @@ int tracecmd_make_pipe(struct tracecmd_input *handle, int cpu, int fd, int cpus)*/ void tracecmd_print_events (struct tracecmd_input *handle,const char *regex) { -int ret; +struct file_section *sec;if (!regex) regex =".*" ; -if (!handle->ftrace_files_start) { -lseek64 (handle->fd, handle->header_files_start,SEEK_SET ); + sec =open_section (handle,TRACECMD_OPTION_HEADER_INFO ); +if (sec) {read_header_files (handle); +close_section (handle, sec); + } + sec =open_section (handle,TRACECMD_OPTION_FTRACE_EVENTS ); +if (sec) { +read_ftrace_files (handle, regex); +close_section (handle, sec); + } + sec =open_section (handle,TRACECMD_OPTION_EVENT_FORMATS ); +if (sec) { +read_event_files (handle, regex); +close_section (handle, sec); } - ret =read_ftrace_files (handle, regex); -if (ret <0 ) -return ; - -read_event_files (handle, regex); -return ; }/* Show the cpu data stats */
@@ -3905,6 +3908,7 @@ int tracecmd_copy_headers(struct tracecmd_input *handle, int fd,enum tracecmd_file_states start_state, enum tracecmd_file_states end_state) { + struct file_section *sec;int ret;if (!start_state)
@@ -3920,13 +3924,17 @@ int tracecmd_copy_headers(struct tracecmd_input *handle, int fd,if (handle->file_state >= start_state) {/* Set the handle to just before the start state */ -lseek64 (handle->fd, handle->header_files_start,SEEK_SET ); + sec =open_section (handle,TRACECMD_OPTION_HEADER_INFO ); +if (!sec) +return -1 ;/* Now that the file handle has moved, change its state */ handle->file_state =TRACECMD_FILE_INIT ; } -/* Try to bring the input up to the start state - 1 */ ret =tracecmd_read_headers (handle, start_state -1 ); +if (sec) +close_section (handle, sec); +if (ret <0 ) goto out;
Signature · 1 line
2.31.1
PATCH 37/87 trace-cmd library: Set log size to the input tep handler when it is read from the file
In reply to Tzvetomir Stoyanov (VMware)Setting the long size to the input tep handler in tracecmd_read_headers() API may be too late, as this tep handler is used to read and parse data from the file before that. The most suitable place for that is tracecmd_alloc_fd() API, right after reading the long size from the file.
--- lib/trace-cmd/trace-input.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/trace-cmd/trace-input.c +1 -2
@@ -977,8 +977,6 @@ int tracecmd_read_headers(struct tracecmd_input *handle,if (ret <0 )return -1 ; -tep_set_long_size (handle->pevent, handle->long_size); -if (state <= handle->file_state)return 0 ;
@@ -3473,6 +3471,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)do_read_check (handle, buf,1 ); handle->long_size = buf[0 ]; +tep_set_long_size (handle->pevent, handle->long_size);read4 (handle, &page_size); handle->page_size = page_size;
Signature · 1 line
2.31.1
PATCH 38/87 trace-cmd library: Fix possible memory leak in read_ftrace_files()
In reply to Tzvetomir Stoyanov (VMware)Some error paths in read_ftrace_files() may lead to a memory leak. Improved the error handling of this internal function to avoid it.
--- lib/trace-cmd/trace-input.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
lib/trace-cmd/trace-input.c +11 -8
@@ -721,25 +721,28 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex) } } -if (read4 (handle, &count) <0 ) -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->file_state =TRACECMD_FILE_FTRACE_EVENTS ; + ret =0 ; +out:if (sreg) {regfree (sreg);regfree (ereg); } - handle->file_state =TRACECMD_FILE_FTRACE_EVENTS ; - -return 0 ; +return ret; }static int read_event_files (struct tracecmd_input *handle,const char *regex)
Signature · 1 line
2.31.1
PATCH 39/87 trace-cmd library: Fix possible memory leak in read_event_files()
In reply to Tzvetomir Stoyanov (VMware)Some error paths in read_event_files() may lead to a memory leak. Improved the error handling of this internal function to avoid it.
--- lib/trace-cmd/trace-input.c | 39 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-)
lib/trace-cmd/trace-input.c +19 -20
@@ -748,7 +748,7 @@ out: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 ;
@@ -777,13 +777,16 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex)return -1 ; } -if (read4 (handle, &systems) <0 ) -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 ;
@@ -810,39 +813,35 @@ 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:if (sreg) {regfree (sreg);regfree (ereg); }free (system); -return -1 ; +return ret; }static int read_proc_kallsyms (struct tracecmd_input *handle)
Signature · 1 line
2.31.1
PATCH 40/87 trace-cmd library: Fix possible memory leak in read_proc_kallsyms()
In reply to Tzvetomir Stoyanov (VMware)Some error paths in read_proc_kallsyms() may lead to a memory leak. Improved the error handling of this internal function to avoid it.
--- lib/trace-cmd/trace-input.c | 40 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-)
lib/trace-cmd/trace-input.c +22 -18
@@ -846,9 +846,10 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex)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 (CHECK_READ_STATE (handle,TRACECMD_FILE_KALLSYMS ))return 0 ;
@@ -857,28 +858,31 @@ static int read_proc_kallsyms(struct tracecmd_input *handle)add_section (handle,TRACECMD_OPTION_KALLSYMS ,0 ,0 ,lseek64 (handle->fd,0 ,SEEK_CUR )); - -if (read4 (handle, &size) <0 ) -return -1 ; -if (!size) -return 0 ;/* OK? */ + ret =read4 (handle, &size); +if (ret <0 ) + goto out; +if (!size) { + handle->file_state =TRACECMD_FILE_KALLSYMS ; + 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; } - buf[size] =0 ; - -tep_parse_kallsyms (pevent, buf); + ret =do_read_check (handle, buf, size); +if (ret <0 ) + goto out; -free (buf); + buf[size] =0 ; +tep_parse_kallsyms (tep, buf); handle->file_state =TRACECMD_FILE_KALLSYMS ; - -return 0 ; + ret =0 ; +out: +free (buf); +return ret; }static int read_ftrace_printk (struct tracecmd_input *handle)
Signature · 1 line
2.31.1
PATCH 41/87 trace-cmd library: Fix possible memory leak in read_ftrace_printk()
In reply to Tzvetomir Stoyanov (VMware)Some error paths in read_ftrace_printk() may lead to a memory leak. Improved the error handling of this internal function to avoid it.
--- lib/trace-cmd/trace-input.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
lib/trace-cmd/trace-input.c +19 -14
@@ -888,7 +888,8 @@ out:static int read_ftrace_printk (struct tracecmd_input *handle) {unsigned int size; -char *buf; +char *buf =NULL ; +int ret;if (CHECK_READ_STATE (handle,TRACECMD_FILE_PRINTK ))return 0 ;
@@ -897,29 +898,33 @@ static int read_ftrace_printk(struct tracecmd_input *handle)add_section (handle,TRACECMD_OPTION_PRINTK ,0 ,0 ,lseek64 (handle->fd,0 ,SEEK_CUR )); - -if (read4 (handle, &size) <0 ) -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); +return ret; }static int read_and_parse_cmdlines (struct tracecmd_input *handle);
Signature · 1 line
2.31.1
PATCH 42/87 trace-cmd library: Fix possible memory leak in read_and_parse_cmdlines()
In reply to Tzvetomir Stoyanov (VMware)Some error paths in read_and_parse_cmdlines() may lead to a memory leak. Improved the error handling of this internal function to avoid it.
--- lib/trace-cmd/trace-input.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
lib/trace-cmd/trace-input.c +13 -7
@@ -3122,7 +3122,8 @@ 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 (CHECK_READ_STATE (handle,TRACECMD_FILE_CMD_LINES ))return 0 ;
@@ -3131,15 +3132,20 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle)add_section (handle,TRACECMD_OPTION_CMDLINES ,0 ,0 ,lseek64 (handle->fd,0 ,SEEK_CUR )); -if (read_data_and_size (handle, &cmdlines, &size) <0 ) -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); +return ret; }static void extract_trace_clock (struct tracecmd_input *handle,char *line)
Signature · 1 line
2.31.1
PATCH 43/87 trace-cmd library: Track maximum CPUs count in input handler
In reply to Tzvetomir Stoyanov (VMware)In trace file version 7, only CPUs with trace data are stored in the file. Each instance may have its own CPU count, depending on collected traces. As the main input handler is used by the top trace instance, the CPU count there is for the top trace instance and may differ with cpu counts of the other instances. Added a new "max_cpu" member of the input handler, that tracks the maximum CPU count of all instances, recorded in the file.
--- lib/trace-cmd/trace-input.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/trace-cmd/trace-input.c +5 -1
@@ -133,6 +133,7 @@ struct tracecmd_input {int long_size;int page_size;int page_map_size; +int max_cpu;int cpus;int ref;int nr_buffers;/* buffer instances */
@@ -953,6 +954,7 @@ static int read_cpus(struct tracecmd_input *handle)return -1 ; handle->cpus = cpus; + handle->max_cpu = cpus;tep_set_cpus (handle->pevent, handle->cpus); handle->file_state =TRACECMD_FILE_CPU_COUNT ;
@@ -2908,6 +2910,8 @@ static int handle_options(struct tracecmd_input *handle)case TRACECMD_OPTION_CPUCOUNT : cpus = *(int *)buf; handle->cpus =tep_read_number (handle->pevent, &cpus,4 ); + handle->max_cpu = handle->cpus; +tep_set_cpus (handle->pevent, handle->cpus);break ;case TRACECMD_OPTION_PROCMAPS :if (buf[size-1 ] =='\0' )
@@ -4216,7 +4220,7 @@ int tracecmd_page_size(struct tracecmd_input *handle)*/ int tracecmd_cpus (struct tracecmd_input *handle) { -return handle->cpus; +return handle->max_cpu; }/**
Signature · 1 line
2.31.1
PATCH 44/87 trace-cmd library: Set input handler default values in allocation function
In reply to Tzvetomir Stoyanov (VMware)Set usecs flag by default when the input handler is allocated, it makes more sense than setting it when options are handeled. This clean up is needed for parsing version 7 trace files, where multiple options sections may exist.
--- lib/trace-cmd/trace-input.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/trace-cmd/trace-input.c +3 -2
@@ -2795,8 +2795,6 @@ static int handle_options(struct tracecmd_input *handle)int cpus;int ret; -/* By default, use usecs, unless told otherwise */ - handle->flags |=TRACECMD_FL_IN_USECS ; handle->options_start =lseek64 (handle->fd,0 ,SEEK_CUR );for (;;) {
@@ -3448,6 +3446,9 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) handle->fd = fd; handle->ref =1 ; +/* By default, use usecs, unless told otherwise */ + handle->flags |=TRACECMD_FL_IN_USECS ; +if (do_read_check (handle, buf,3 )) goto failed_read;
Signature · 1 line
2.31.1
PATCH 45/87 trace-cmd library: Read headers from trace file version 7
In reply to Tzvetomir Stoyanov (VMware)Trace file version 7 has more flexible structure than version 6, headers are not located at fixed position in the file. A new logic is implemented to read and parse the headers from this new format.
--- lib/trace-cmd/trace-input.c | 150 ++++++++++++++++++++++++++++++++---- 1 file changed, 136 insertions(+), 14 deletions(-)
lib/trace-cmd/trace-input.c +136 -14
@@ -164,7 +164,8 @@ struct tracecmd_input {struct pid_addr_maps *pid_maps;/* file information */ struct file_section *sections; -size_t options_start; +bool options_init; +unsigned long long options_start;size_t total_file_size;/* For custom profilers. */
@@ -961,19 +962,7 @@ static int read_cpus(struct tracecmd_input *handle)return 0 ; } -/** -* tracecmd_read_headers - read the header information from trace.dat -* @handle: input handle for the trace.dat file -* @state: The state to read up to or zero to read up to options. -* -* This reads the trace.dat file for various information. Like the -* format of the ring buffer, event formats, ftrace formats, kallsyms -* and printk. This may be called multiple times with different @state -* values, to read partial data at a time. It will always continue -* where it left off. -*/ -int tracecmd_read_headers (struct tracecmd_input *handle, -enum tracecmd_file_states state) +static int read_headers_v6 (struct tracecmd_input *handle,enum tracecmd_file_states state) {int ret;
@@ -1039,6 +1028,139 @@ int tracecmd_read_headers(struct tracecmd_input *handle,return 0 ; } +static int handle_options (struct tracecmd_input *handle); + +static int read_section_header (struct tracecmd_input *handle,unsigned short *id, +unsigned short *flags,unsigned int *size,char **description) +{ +unsigned short fl; +char *desc =NULL ; +unsigned short sec_id; +unsigned int sz; + +if (read2 (handle, &sec_id)) +return -1 ; + desc =read_string (handle); +if (!desc) +return -1 ; +if (read2 (handle, &fl)) + goto error; +if (read4 (handle, &sz)) + goto error; + +if (id) + *id = sec_id; +if (flags) + *flags = fl; +if (size) + *size = sz; +if (description) + *description = desc; +else +free (desc); +return 0 ; + +error: +free (desc); +return -1 ; +} + +static int handle_section (struct tracecmd_input *handle,struct file_section *section) +{ +unsigned short id, flags; +unsigned int size; +int ret; + +if (lseek64 (handle->fd, section->section_offset,SEEK_SET ) == (off_t)-1 ) +return -1 ; +if (read_section_header (handle, &id, &flags, &size,NULL )) +return -1 ; + section->flags = flags; +if (id != section->id) +return -1 ; + + section->data_offset =lseek64 (handle->fd,0 ,SEEK_CUR ); +if ((section->flags &TRACECMD_SEC_FL_COMPRESS ) &&in_uncompress_block (handle)) +return -1 ; + +switch (section->id) { +case TRACECMD_OPTION_HEADER_INFO : + ret =read_header_files (handle); +break ; +case TRACECMD_OPTION_FTRACE_EVENTS : + ret =read_ftrace_files (handle,NULL ); +break ; +case TRACECMD_OPTION_EVENT_FORMATS : + ret =read_event_files (handle,NULL ); +break ; +case TRACECMD_OPTION_KALLSYMS : + ret =read_proc_kallsyms (handle); +break ; +case TRACECMD_OPTION_PRINTK : + ret =read_ftrace_printk (handle); +break ; +case TRACECMD_OPTION_CMDLINES : + ret =read_and_parse_cmdlines (handle); +break ; +default : + ret =0 ; +break ; + } + +if (section->flags &TRACECMD_SEC_FL_COMPRESS ) +in_uncompress_reset (handle); + +return ret; +} + +static int read_headers_v7 (struct tracecmd_input *handle) +{ +struct file_section *section; + +if (handle->options_init) +return 0 ; + +if (!handle->options_start) +return -1 ; + +if (lseek64 (handle->fd, handle->options_start,SEEK_SET ) == (off64_t)-1 ) { +tracecmd_warning ("Filed to goto options offset %lld" , handle->options_start); +return -1 ; + } + +if (handle_options (handle)) +return -1 ; + + section = handle->sections; +while (section) { +if (handle_section (handle, section)) +return -1 ; + section = section->next; + } + + handle->options_init = true; +return 0 ; +} + +/** +* tracecmd_read_headers - read the header information from trace.dat +* @handle: input handle for the trace.dat file +* @state: The state to read up to or zero to read up to options. +* +* This reads the trace.dat file for various information. Like the +* format of the ring buffer, event formats, ftrace formats, kallsyms +* and printk. This may be called multiple times with different @state +* values, to read partial data at a time. It will always continue +* where it left off. +*/ +int tracecmd_read_headers (struct tracecmd_input *handle, +enum tracecmd_file_states state) +{ +if (handle->file_version <7 ) +return read_headers_v6 (handle, state); +return read_headers_v7 (handle); +} +static unsigned long long calc_page_offset (struct tracecmd_input *handle,unsigned long long offset) {
Signature · 1 line
2.31.1
PATCH 46/87 tarce-cmd library: Do not use local variables when reading CPU stat option
In reply to Tzvetomir Stoyanov (VMware)Trace file version 7 can have more than one options section. Assuming that all CPUSTAT options are in a single options section could be wrong, that's why using local variable to track the CPUSTAT size is not correct. Use input handler context instead.
--- lib/trace-cmd/trace-input.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
lib/trace-cmd/trace-input.c +11 -7
@@ -150,6 +150,7 @@ struct tracecmd_input {struct host_trace_info host;double ts2secs; +unsigned int cpustats_size;char * cpustats;char * uname;char * version;
@@ -2910,7 +2911,6 @@ static int handle_options(struct tracecmd_input *handle)unsigned short option;unsigned int size;char *cpustats =NULL ; -unsigned int cpustats_size =0 ;struct input_buffer_instance *buffer;struct hook_list *hook;char *buf;
@@ -2988,12 +2988,16 @@ static int handle_options(struct tracecmd_input *handle)break ;case TRACECMD_OPTION_CPUSTAT : buf[size-1 ] ='\n' ; - cpustats =realloc (cpustats, cpustats_size + size +1 ); -if (!cpustats) -return -ENOMEM ; -memcpy (cpustats + cpustats_size, buf, size); - cpustats_size += size; - cpustats[cpustats_size] =0 ; + cpustats =realloc (handle->cpustats, + handle->cpustats_size + size +1 ); +if (!cpustats) { + ret = -ENOMEM ; +return ret; + } +memcpy (cpustats + handle->cpustats_size, buf, size); + handle->cpustats_size += size; + cpustats[handle->cpustats_size] =0 ; + handle->cpustats = cpustats;break ;case TRACECMD_OPTION_BUFFER :/* A buffer instance is saved at the end of the file */
Signature · 1 line
2.31.1
PATCH 47/87 trace-cmd library: Read handle header and compression of the option section
In reply to Tzvetomir Stoyanov (VMware)In trace file version 7, options section has a section header and possible compression of the data. Extend the options handling logic with this new format.
--- lib/trace-cmd/trace-input.c | 50 ++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 15 deletions(-)
lib/trace-cmd/trace-input.c +35 -15
@@ -2910,30 +2910,47 @@ static int handle_options(struct tracecmd_input *handle)long long offset;unsigned short option;unsigned int size; +unsigned short id, flags;char *cpustats =NULL ;struct input_buffer_instance *buffer;struct hook_list *hook; +bool comperss = false;char *buf;int cpus;int ret; - handle->options_start =lseek64 (handle->fd,0 ,SEEK_CUR ); - -for (;;) { -if (read2 (handle, &option)) +if (handle->file_version <7 ) { + handle->options_start =lseek64 (handle->fd,0 ,SEEK_CUR ); + }else { +if (read_section_header (handle, &id, &flags,NULL ,NULL ))return -1 ; +if (id !=TRACECMD_OPTION_DONE ) +return -1 ; +if (flags &TRACECMD_SEC_FL_COMPRESS ) + comperss = true; + } -if (option ==TRACECMD_OPTION_DONE ) +if (comperss &&in_uncompress_block (handle)) +return -1 ; +for (;;) { + ret =read2 (handle, &option); +if (ret) + goto out; +if (handle->file_version <7 && option ==TRACECMD_OPTION_DONE )break ;/* next 4 bytes is the size of the option */ -if (read4 (handle, &size)) -return -1 ; + ret =read4 (handle, &size); +if (ret) + goto out; buf =malloc (size); -if (!buf) -return -ENOMEM ; -if (do_read_check (handle, buf, size)) -return -1 ; +if (!buf) { + ret = -ENOMEM ; + goto out; + } + ret =do_read_check (handle, buf, size); +if (ret) + goto out;switch (option) {case TRACECMD_OPTION_DATE :
@@ -2983,7 +3000,7 @@ static int handle_options(struct tracecmd_input *handle) buf + 8, 4); ret =tsync_cpu_offsets_load (handle, buf +12 , size -12 );if (ret <0 ) -return ret; + goto out;tracecmd_enable_tsync (handle, true);break ;case TRACECMD_OPTION_CPUSTAT :
@@ -2992,7 +3009,7 @@ static int handle_options(struct tracecmd_input *handle) handle->cpustats_size + size + 1);if (!cpustats) { ret = -ENOMEM ; -return ret; + goto out; }memcpy (cpustats + handle->cpustats_size, buf, size); handle->cpustats_size += size;
@@ -3079,9 +3096,12 @@ static int handle_options(struct tracecmd_input *handle) } - handle->cpustats = cpustats; + ret =0 ; -return 0 ; +out: +if (comperss) +in_uncompress_reset (handle); +return ret; }static int read_options_type (struct tracecmd_input *handle)
Signature · 1 line
2.31.1
PATCH 48/87 trace-cmd library: Read extended BUFFER option
In reply to Tzvetomir Stoyanov (VMware)The BUFFER option is extended in trace file version 7. It holds CPU metadata related to the recorded CPU traces. Also, there is a new BUFFER_LAT option for describing the latency trace data. A new logic is implemented for these new options.
In trace file version 7, the top buffer is saved as other buffers in the file, no special treatment. But saving the top buffer in the list of buffers in the input handler causes problems. It breaks the legacy logic of trace-cmd library users, which have special logic for trace buffers processing. That's why "top_buffer" member is added in the input handler structure, to hold the top buffer.
--- lib/trace-cmd/trace-input.c | 116 ++++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 18 deletions(-)
lib/trace-cmd/trace-input.c +98 -18
@@ -74,9 +74,19 @@ struct cpu_data {int pipe_fd; }; +struct cpu_file_data { +int cpu; +unsigned long long offset; +unsigned long long size; +}; +struct input_buffer_instance {char *name;size_t offset; +char *clock; +bool latency; +int cpus; +struct cpu_file_data *cpu_data; };struct ts_offset_sample {
@@ -155,6 +165,7 @@ struct tracecmd_input {char * uname;char * version;char * trace_clock; +struct input_buffer_instance top_buffer;struct input_buffer_instance *buffers;int parsing_failures;struct guest_trace_info *guest;
@@ -2905,6 +2916,80 @@ tracecmd_search_task_map(struct tracecmd_input *handle,return lib; } +#define save_read_number (R ,C ) \ + do { \ + if ((C) > size) \ + return -1; \ + (R) = tep_read_number(handle->pevent, (data + rsize), (C)); \ + rsize += (C); \ + size -= (C); \ + } while (0) + +#define save_read_string (R ) \ + do { \ + if (size < 1) \ + return -1; \ + (R) = strdup(data + rsize); \ + if (!(R)) \ + return -1; \ + rsize += (strlen((R)) + 1); \ + size -= (strlen((R)) + 1); \ + if (size < 0) \ + return -1; \ + } while (0) + +static int handle_buffer_option (struct tracecmd_input *handle, +unsigned short id,char *data,int size) +{ +struct input_buffer_instance *buff; +unsigned long long offset; +int rsize =0 ; +char *name; +int i; + +save_read_number (offset,8 ); +save_read_string (name); + +if (*name =='\0' ) { +/* top buffer */ + buff = &handle->top_buffer; + }else { + buff =realloc (handle->buffers,sizeof (*handle->buffers) * (handle->nr_buffers +1 )); +if (!buff) { +free (name); +return -1 ; + } + handle->buffers = buff; + handle->nr_buffers++; + + buff = &handle->buffers[handle->nr_buffers -1 ]; + } +memset (buff,0 ,sizeof (struct input_buffer_instance )); + buff->name = name; + buff->offset = offset; +if (handle->file_version <7 ) +return 0 ; + +/* file version >= 7 specific data */ +save_read_string (buff->clock); +if (id ==TRACECMD_OPTION_BUFFER ) { +save_read_number (buff->cpus,4 ); +if (!buff->cpus) +return 0 ; + buff->cpu_data =calloc (buff->cpus,sizeof (struct cpu_file_data )); +if (!buff->cpu_data) +return -1 ; +for (i =0 ; i < buff->cpus; i++) { +save_read_number (buff->cpu_data[i].cpu,4 ); +save_read_number (buff->cpu_data[i].offset,8 ); +save_read_number (buff->cpu_data[i].size,8 ); + } + }else { + buff->latency = true; + } +return 0 ; +} +static int handle_options (struct tracecmd_input *handle) {long long offset;
@@ -2912,7 +2997,6 @@ static int handle_options(struct tracecmd_input *handle)unsigned int size;unsigned short id, flags;char *cpustats =NULL ; -struct input_buffer_instance *buffer;struct hook_list *hook;bool comperss = false;char *buf;
@@ -3017,21 +3101,10 @@ static int handle_options(struct tracecmd_input *handle) handle->cpustats = cpustats;break ;case TRACECMD_OPTION_BUFFER : -/* A buffer instance is saved at the end of the file */ - handle->nr_buffers++; - handle->buffers =realloc (handle->buffers, -sizeof (*handle->buffers) * handle->nr_buffers); -if (!handle->buffers) -return -ENOMEM ; - buffer = &handle->buffers[handle->nr_buffers -1 ]; - buffer->name =strdup (buf +8 ); -if (!buffer->name) { -free (handle->buffers); - handle->buffers =NULL ; -return -ENOMEM ; - } - offset = *(unsigned long long *)buf; - buffer->offset =tep_read_number (handle->pevent, &offset,8 ); +case TRACECMD_OPTION_BUFFER_LAT : + ret =handle_buffer_option (handle, option, buf, size); +if (ret <0 ) + goto out;break ;case TRACECMD_OPTION_TRACECLOCK :if (!handle->ts2secs)
@@ -3825,9 +3898,15 @@ void tracecmd_close(struct tracecmd_input *handle) handle->sections = handle->sections->next;free (del_sec); } -for (i =0 ; i < handle->nr_buffers; i++) -free (handle->buffers[i].name); +free (handle->top_buffer.name); +free (handle->top_buffer.clock); +free (handle->top_buffer.cpu_data); +for (i =0 ; i < handle->nr_buffers; i++) { +free (handle->buffers[i].name); +free (handle->buffers[i].clock); +free (handle->buffers[i].cpu_data); + }free (handle->buffers);tracecmd_free_hooks (handle->hooks);
@@ -4272,6 +4351,7 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx)return NULL ; *new_handle = *handle; +memset (&new_handle->top_buffer,0 ,sizeof (new_handle->top_buffer)); new_handle->cpu_data =NULL ; new_handle->nr_buffers =0 ; new_handle->buffers =NULL ;
Signature · 1 line
2.31.1
PATCH 49/87 trace-cmd library: Handle the extended DONE option
In reply to Tzvetomir Stoyanov (VMware)In trace file version 7 the DONE option is extended to store the offset in the file to the next options section. This way a list of options sections can be stored in the file. Added logic to recursively read all option sections from the file.
--- lib/trace-cmd/include/trace-cmd-local.h | 2 +- lib/trace-cmd/trace-input.c | 31 +++++++++++++++++++++++++ lib/trace-cmd/trace-output.c | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-)
lib/trace-cmd/include/trace-cmd-local.h +1 -1
@@ -64,6 +64,6 @@ struct cpu_data_source {int out_write_cpu_data (struct tracecmd_output *handle,int cpus,struct cpu_data_source *data,const char *buff_name);off64_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off_t offset,int whence); - +unsigned long long get_last_option_offset (struct tracecmd_input *handle);#endif /* _TRACE_CMD_LOCAL_H */
lib/trace-cmd/trace-input.c +31 -0
@@ -178,6 +178,7 @@ struct tracecmd_input {struct file_section *sections;bool options_init;unsigned long long options_start; +unsigned long long options_last_offset;size_t total_file_size;/* For custom profilers. */
@@ -2916,6 +2917,30 @@ tracecmd_search_task_map(struct tracecmd_input *handle,return lib; } +__hidden unsigned long long get_last_option_offset (struct tracecmd_input *handle) +{ +return handle->options_last_offset; +} + +static int handle_option_done (struct tracecmd_input *handle,char *buf,int size) +{ +unsigned long long offset; + +if (size <8 ) +return -1 ; + offset =lseek64 (handle->fd,0 ,SEEK_CUR ); +if (offset >= size) + handle->options_last_offset = offset - size; + offset =tep_read_number (handle->pevent, buf,8 ); +if (!offset) +return 0 ; + +if (lseek64 (handle->fd, offset,SEEK_SET ) == (off_t)-1 ) +return -1 ; + +return handle_options (handle); +} +#define save_read_number (R ,C ) \ do { \ if ((C) > size) \
@@ -3160,6 +3185,12 @@ static int handle_options(struct tracecmd_input *handle)break ;add_section (handle, option,-1 ,tep_read_number (handle->pevent, buf,8 ),0 );break ; +case TRACECMD_OPTION_DONE : +if (comperss) +in_uncompress_reset (handle); + ret =handle_option_done (handle, buf, size); +free (buf); +return ret;default :tracecmd_warning ("unknown option %d" , option);break ;
lib/trace-cmd/trace-output.c +1 -1
@@ -2409,7 +2409,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_in_file_version (ihandle); - handle->options_start =tracecmd_get_options_offset (ihandle); + handle->options_start =get_last_option_offset (ihandle);list_head_init (&handle->options);list_head_init (&handle->buffers);
Signature · 1 line
2.31.1
PATCH 50/87 trace-cmd library: Read compression header
In reply to Tzvetomir Stoyanov (VMware)Trace file version 7 introduced new mandatory compression header, storing information about the compression algorithm used to compress the trace file. Added code to read that header and to initialize compression context according to it.
--- lib/trace-cmd/trace-input.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
lib/trace-cmd/trace-input.c +33 -2
@@ -3684,7 +3684,9 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)char test[] =TRACECMD_MAGIC ;unsigned int page_size;size_t offset; -char *version; +char *version =NULL ; +char *zver =NULL ; +char *zname =NULL ;char buf[BUFSIZ ];unsigned long ver;
@@ -3723,6 +3725,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) } handle->file_version = ver;free (version); + version =NULL ;if (do_read_check (handle, buf,1 )) goto failed_read;
@@ -3752,11 +3755,38 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) handle->total_file_size =lseek64 (handle->fd,0 ,SEEK_END );lseek64 (handle->fd, offset,SEEK_SET ); +if (handle->file_version >=7 ) { + zname =read_string (handle); +if (!zname) + goto failed_read; + zver =read_string (handle); +if (!zver) + goto failed_read; +if (strcmp (zname,"none" )) { + handle->compress =tracecmd_compress_alloc (zname, zver, + handle->fd, + handle->pevent,NULL ); +if (!handle->compress) { +tracecmd_warning ("Unsupported file compression %s %s" , zname, zver); + goto failed_read; + } + } +if (read8 (handle, &(handle->options_start))) { +tracecmd_warning ("Filed to read the offset of the first option section" ); + goto failed_read; + } +free (zname); +free (zver); + } + handle->file_state =TRACECMD_FILE_INIT ;return handle; failed_read: +free (version); +free (zname); +free (zver);free (handle);return NULL ;
@@ -3952,7 +3982,8 @@ void tracecmd_close(struct tracecmd_input *handle)if (handle->flags &TRACECMD_FL_BUFFER_INSTANCE )tracecmd_close (handle->parent);else { -/* Only main handle frees plugins and pevent */ +/* Only main handle frees plugins, pevent and compression context */ +tracecmd_compress_destroy (handle->compress);tep_unload_plugins (handle->plugin_list, handle->pevent);tep_free (handle->pevent); }
Signature · 1 line
2.31.1
PATCH 51/87 trace-cmd library: Extend the input handler with trace data decompression context
In reply to Tzvetomir Stoyanov (VMware)The CPU tarce data is compressed in chunks, as chunk's size is multiple trace pages. The input handler is extended with the necessary structures, to control the data decompression. There are two approaches for data decompression, both are supported and can be used in different use cases:
- in-memory decompression, page by page.
- using a temporary file
--- lib/trace-cmd/trace-input.c | 66 ++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 12 deletions(-)
lib/trace-cmd/trace-input.c +54 -12
@@ -29,6 +29,9 @@#define COMMIT_MASK ((1 << 27) - 1) +/* force uncompressing in memory */ +#define INMEMORY_DECOMPRESS +/* for debugging read instead of mmap */ static int force_read =0 ;
@@ -54,6 +57,24 @@ struct page {#endif }; +struct zchunk_cache { +struct list_head list; +struct tracecmd_compress_chunk *chunk; +void *map; +int ref; +}; + +struct cpu_zdata { +/* uncompressed cpu data */ +int fd; +char file[26 ];/* strlen(COMPR_TEMP_FILE) */ +unsigned int count; +unsigned int last_chunk; +struct list_head cache; +struct tracecmd_compress_chunk *chunks; +}; + +#define COMPR_TEMP_FILE "/tmp/trace_cpu_dataXXXXXX"struct cpu_data {/* the first two never change */ unsigned long long file_offset;
@@ -72,6 +93,7 @@ struct cpu_data {int page_cnt;int cpu;int pipe_fd; +struct cpu_zdata compress; };struct cpu_file_data {
@@ -150,6 +172,8 @@ struct tracecmd_input {bool use_trace_clock;bool read_page;bool use_pipe; +bool read_zpage;/* uncompress pages in memory, do not use tmp files */ +bool cpu_compressed;int file_version;struct cpu_data *cpu_data;long long ts_offset;
@@ -3284,7 +3308,7 @@ static int read_cpu_data(struct tracecmd_input *handle)unsigned long long offset; handle->cpu_data[cpu].cpu = cpu; - + handle->cpu_data[cpu].compress.fd =-1 ; handle->cpu_data[cpu].kbuf =kbuffer_alloc (long_size, endian);if (!handle->cpu_data[cpu].kbuf) goto out_free;
@@ -3701,6 +3725,9 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)/* By default, use usecs, unless told otherwise */ handle->flags |=TRACECMD_FL_IN_USECS ; +#ifdef INMEMORY_DECOMPRESS + handle->read_zpage =1 ; +#endif if (do_read_check (handle, buf,3 )) goto failed_read;
@@ -3915,6 +3942,7 @@ void tracecmd_ref(struct tracecmd_input *handle)*/ void tracecmd_close (struct tracecmd_input *handle) { +struct zchunk_cache *cache;struct file_section *del_sec;int i;
@@ -3933,17 +3961,31 @@ void tracecmd_close(struct tracecmd_input *handle)/* The tracecmd_peek_data may have cached a record */ free_next (handle, i);free_page (handle, i); -if (handle->cpu_data && handle->cpu_data[i].kbuf) { -kbuffer_free (handle->cpu_data[i].kbuf); -if (handle->cpu_data[i].page_map) -free_page_map (handle->cpu_data[i].page_map); - -if (handle->cpu_data[i].page_cnt) -tracecmd_warning ("%d pages still allocated on cpu %d%s" , - handle->cpu_data[i].page_cnt, i, -show_records (handle->cpu_data[i].pages, - handle->cpu_data[i].nr_pages)); -free (handle->cpu_data[i].pages); +if (handle->cpu_data) { +if (handle->cpu_data[i].kbuf) { +kbuffer_free (handle->cpu_data[i].kbuf); +if (handle->cpu_data[i].page_map) +free_page_map (handle->cpu_data[i].page_map); + +if (handle->cpu_data[i].page_cnt) +tracecmd_warning ("%d pages still allocated on cpu %d%s" , + handle->cpu_data[i].page_cnt, i, +show_records (handle->cpu_data[i].pages, + handle->cpu_data[i].nr_pages)); +free (handle->cpu_data[i].pages); + } +if (handle->cpu_data[i].compress.fd >=0 ) { +close (handle->cpu_data[i].compress.fd); +unlink (handle->cpu_data[i].compress.file); + } +while (!list_empty (&handle->cpu_data[i].compress.cache)) { + cache =container_of (handle->cpu_data[i].compress.cache.next, + struct zchunk_cache, list); +list_del (&cache->list); +free (cache->map); +free (cache); + } +free (handle->cpu_data[i].compress.chunks); } }
Signature · 1 line
2.31.1
PATCH 52/87 trace-cmd library: Initialize CPU data decompression logic
In reply to Tzvetomir Stoyanov (VMware)On CPU data initialization stage, initialize decompression context for both in-memory and temporary file decompression logics.
--- lib/trace-cmd/trace-input.c | 70 +++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-)
lib/trace-cmd/trace-input.c +67 -3
@@ -1276,6 +1276,7 @@ static void *allocate_page_map(struct tracecmd_input *handle,off64_t map_offset;void *map;int ret; +int fd;if (handle->read_page) { map =malloc (handle->page_size);
@@ -1315,12 +1316,15 @@ static void *allocate_page_map(struct tracecmd_input *handle, map_size -= map_offset + map_size - (cpu_data->file_offset + cpu_data->file_size); +if (cpu_data->compress.fd >=0 ) + fd = cpu_data->compress.fd; +else + fd = handle->fd; again: page_map->size = map_size; page_map->offset = map_offset; - page_map->map =mmap (NULL , map_size,PROT_READ ,MAP_PRIVATE , - handle->fd, map_offset); + page_map->map =mmap (NULL , map_size,PROT_READ ,MAP_PRIVATE , fd, map_offset);if (page_map->map ==MAP_FAILED ) {/* Try a smaller map */
@@ -2512,16 +2516,76 @@ tracecmd_read_prev(struct tracecmd_input *handle, struct tep_record *record)/* Not reached */ } -static int init_cpu (struct tracecmd_input *handle,int cpu) +static int init_cpu_zfile (struct tracecmd_input *handle,int cpu) +{ +struct cpu_data *cpu_data; +unsigned long long size; +off64_t offset; + + cpu_data = &handle->cpu_data[cpu]; + offset =lseek64 (handle->fd,0 ,SEEK_CUR ); +if (lseek64 (handle->fd, cpu_data->file_offset,SEEK_SET ) == (off_t)-1 ) +return -1 ; +strcpy (cpu_data->compress.file,COMPR_TEMP_FILE ); + cpu_data->compress.fd =mkstemp (cpu_data->compress.file); +if (cpu_data->compress.fd <0 ) +return -1 ; +if (tracecmd_uncompress_copy_to (handle->compress, cpu_data->compress.fd,NULL , &size)) +return -1 ; +if (lseek64 (handle->fd, offset,SEEK_SET ) == (off_t)-1 ) +return -1 ; + cpu_data->offset =0 ; + cpu_data->file_offset =0 ; + cpu_data->file_size = size; + cpu_data->size = size; +return 0 ; +} + +static int init_cpu_zpage (struct tracecmd_input *handle,int cpu) {struct cpu_data *cpu_data = &handle->cpu_data[cpu]; +int count;int i; +if (lseek64 (handle->fd, cpu_data->file_offset,SEEK_SET ) == (off_t)-1 ) +return -1 ; + + count =tracecmd_load_chunks_info (handle->compress, &cpu_data->compress.chunks); +if (count <0 ) +return -1 ; + cpu_data->compress.count = count; + cpu_data->compress.last_chunk =0 ; + + cpu_data->file_offset =0 ; + cpu_data->file_size =0 ; +for (i =0 ; i < count; i++) + cpu_data->file_size += cpu_data->compress.chunks[i].size; cpu_data->offset = cpu_data->file_offset; cpu_data->size = cpu_data->file_size; +return 0 ; +} + +static int init_cpu (struct tracecmd_input *handle,int cpu) +{ +struct cpu_data *cpu_data = &handle->cpu_data[cpu]; +int ret; +int i; + +if (handle->cpu_compressed && cpu_data->file_size >0 ) { +if (handle->read_zpage) + ret =init_cpu_zpage (handle, cpu); +else + ret =init_cpu_zfile (handle, cpu); +if (ret) +return ret; + }else { + cpu_data->offset = cpu_data->file_offset; + cpu_data->size = cpu_data->file_size; + } cpu_data->timestamp =0 ;list_head_init (&cpu_data->page_maps); +list_head_init (&cpu_data->compress.cache);if (!cpu_data->size) {printf ("CPU %d is empty\n" , cpu);
Signature · 1 line
2.31.1
PATCH 53/87 trace-cmd library: Initialize CPU data for reading from version 7 trace files
In reply to Tzvetomir Stoyanov (VMware)In version 7 trace files, CPU trace data is written in slightly different way than in version 6 files. Added new CPU data initialization flow, to handle version 7 files:
- the top trace instance is saved in the same way as the other trace instances.
- per CPU trace metadata is stored in the buffer option.
- trace data section has section header.
- trace data can be compressed.
--- lib/trace-cmd/trace-input.c | 178 +++++++++++++++++++++++++----------- 1 file changed, 124 insertions(+), 54 deletions(-)
lib/trace-cmd/trace-input.c +124 -54
@@ -3327,34 +3327,18 @@ static int read_options_type(struct tracecmd_input *handle)return 0 ; } -static int read_cpu_data (struct tracecmd_input *handle) +static int init_cpu_data (struct tracecmd_input *handle) { -struct tep_handle *pevent = handle->pevent;enum kbuffer_long_size long_size;enum kbuffer_endian endian; -unsigned long long size;unsigned long long max_size =0 ;unsigned long long pages; -int cpus;int cpu; -/* -* Check if this is a latency report or not. -*/ -if (handle->file_state ==TRACECMD_FILE_CPU_LATENCY ) -return 1 ; -/* We expect this to be flyrecord */ if (handle->file_state !=TRACECMD_FILE_CPU_FLYRECORD )return -1 ; - cpus = handle->cpus; - - handle->cpu_data =malloc (sizeof (*handle->cpu_data) * handle->cpus); -if (!handle->cpu_data) -return -1 ; -memset (handle->cpu_data,0 ,sizeof (*handle->cpu_data) * handle->cpus); -if (force_read) handle->read_page = true;
@@ -3369,32 +3353,15 @@ static int read_cpu_data(struct tracecmd_input *handle) endian =KBUFFER_ENDIAN_LITTLE ;for (cpu =0 ; cpu < handle->cpus; cpu++) { -unsigned long long offset; - - handle->cpu_data[cpu].cpu = cpu; handle->cpu_data[cpu].compress.fd =-1 ; handle->cpu_data[cpu].kbuf =kbuffer_alloc (long_size, endian);if (!handle->cpu_data[cpu].kbuf) goto out_free; -if (tep_is_old_format (pevent)) +if (tep_is_old_format (handle->pevent))kbuffer_set_old_format (handle->cpu_data[cpu].kbuf); -read8 (handle, &offset); -read8 (handle, &size); - - handle->cpu_data[cpu].file_offset = offset; - handle->cpu_data[cpu].file_size = size; -if (size > max_size) - max_size = size; - -if (size && (offset + size > handle->total_file_size)) { -/* this happens if the file got truncated */ -printf ("File possibly truncated. " -"Need at least %llu, but file size is %zu.\n" , - offset + size, handle->total_file_size); - errno =EINVAL ; - goto out_free; - } +if (handle->cpu_data[cpu].file_size > max_size) + max_size = handle->cpu_data[cpu].file_size; }/* Calculate about a meg of pages for buffering */
@@ -3412,6 +3379,102 @@ static int read_cpu_data(struct tracecmd_input *handle) goto out_free; } +return 0 ; + + out_free: +for ( ; cpu >=0 ; cpu--) { +free_page (handle, cpu); +kbuffer_free (handle->cpu_data[cpu].kbuf); + handle->cpu_data[cpu].kbuf =NULL ; + } +return -1 ; +} + +static int init_buffer_cpu_data (struct tracecmd_input *handle,struct input_buffer_instance *buffer) +{ +unsigned long long offset; +unsigned long long size; +unsigned short id, flags; +int cpu; + +if (handle->cpu_data) +return -1 ; + +if (lseek64 (handle->fd, buffer->offset,SEEK_SET ) == (off_t)-1 ) +return -1 ; +if (read_section_header (handle, &id, &flags,NULL ,NULL )) +return -1 ; +if (flags &TRACECMD_SEC_FL_COMPRESS ) + handle->cpu_compressed = true; + handle->file_state =TRACECMD_FILE_CPU_FLYRECORD ; + handle->cpus = buffer->cpus; +if (handle->max_cpu < handle->cpus) + handle->max_cpu = handle->cpus; + + handle->cpu_data =calloc (handle->cpus,sizeof (*handle->cpu_data)); +if (!handle->cpu_data) +return -1 ; + +for (cpu =0 ; cpu < handle->cpus; cpu++) { + handle->cpu_data[cpu].cpu = buffer->cpu_data[cpu].cpu; + offset = buffer->cpu_data[cpu].offset; + size = buffer->cpu_data[cpu].size; + handle->cpu_data[cpu].file_offset = offset; + handle->cpu_data[cpu].file_size = size; +if (size && (offset + size > handle->total_file_size)) { +/* this happens if the file got truncated */ +printf ("File possibly truncated. " +"Need at least %llu, but file size is %zu.\n" , + offset + size, handle->total_file_size); + errno =EINVAL ; +return -1 ; + } + } + +return init_cpu_data (handle); +} + +static int read_cpu_data (struct tracecmd_input *handle) +{ +unsigned long long size; +int cpus; +int cpu; + +/* +* Check if this is a latency report or not. +*/ +if (handle->file_state ==TRACECMD_FILE_CPU_LATENCY ) +return 1 ; + +/* We expect this to be flyrecord */ +if (handle->file_state !=TRACECMD_FILE_CPU_FLYRECORD ) +return -1 ; + + cpus = handle->cpus; + + handle->cpu_data =malloc (sizeof (*handle->cpu_data) * handle->cpus); +if (!handle->cpu_data) +return -1 ; +memset (handle->cpu_data,0 ,sizeof (*handle->cpu_data) * handle->cpus); + +for (cpu =0 ; cpu < handle->cpus; cpu++) { +unsigned long long offset; + + handle->cpu_data[cpu].cpu = cpu; +read8 (handle, &offset); +read8 (handle, &size); + handle->cpu_data[cpu].file_offset = offset; + handle->cpu_data[cpu].file_size = size; +if (size && (offset + size > handle->total_file_size)) { +/* this happens if the file got truncated */ +printf ("File possibly truncated. " +"Need at least %llu, but file size is %zu.\n" , + offset + size, handle->total_file_size); + errno =EINVAL ; +return -1 ; + } + } +/* * It is possible that an option changed the number of CPUs. * If that happened, then there's "empty" cpu data saved for
@@ -3431,15 +3494,7 @@ static int read_cpu_data(struct tracecmd_input *handle) } } -return 0 ; - - out_free: -for ( ; cpu >=0 ; cpu--) { -free_page (handle, cpu); -kbuffer_free (handle->cpu_data[cpu].kbuf); - handle->cpu_data[cpu].kbuf =NULL ; - } -return -1 ; +return init_cpu_data (handle); } static int read_data_and_size(struct tracecmd_input *handle,
@@ -3542,14 +3597,7 @@ static int read_and_parse_trace_clock(struct tracecmd_input *handle,return 0 ; } -/** -* tracecmd_init_data - prepare reading the data from trace.dat -* @handle: input handle for the trace.dat file -* -* This prepares reading the data from trace.dat. This is called -* after tracecmd_read_headers() and before tracecmd_read_data(). -*/ -int tracecmd_init_data (struct tracecmd_input *handle) +static int init_data_v6 (struct tracecmd_input *handle) {struct tep_handle *pevent = handle->pevent;int ret;
@@ -3571,7 +3619,29 @@ int tracecmd_init_data(struct tracecmd_input *handle)tracecmd_parse_trace_clock (handle, clock,8 ); } } +return ret; +} + +static int init_data_v7 (struct tracecmd_input *handle) +{ +return init_buffer_cpu_data (handle, &handle->top_buffer); +} + +/** +* tracecmd_init_data - prepare reading the data from trace.dat +* @handle: input handle for the trace.dat file +* +* This prepares reading the data from trace.dat. This is called +* after tracecmd_read_headers() and before tracecmd_read_data(). +*/ +int tracecmd_init_data (struct tracecmd_input *handle) +{ +int ret; +if (handle->file_version <7 ) + ret =init_data_v6 (handle); +else + ret =init_data_v7 (handle);tracecmd_blk_hack (handle);return ret;
Signature · 1 line
2.31.1
PATCH 54/87 trace-cmd library: Add logic for in-memory decompression
In reply to Tzvetomir Stoyanov (VMware)There are two approaches to read compressed trace data:
- use a temporary file to decompress entire trace data before reading
- use in-memory decompression of requested trace data chunk only
In-memory decompression seems to be more efficient, but selecting which approach to use depends in the use case.
A compression chunk consists of multiple trace pages, that's why a small cache with uncompressed chunks is implemented. The chunk stays in the cache until there are pages which have reference to it.
--- lib/trace-cmd/trace-input.c | 104 ++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+)
lib/trace-cmd/trace-input.c +104 -0
@@ -1267,6 +1267,105 @@ static void free_page_map(struct page_map *page_map)free (page_map); } +#define CHUNK_CHECK_OFFSET (C ,O ) ((O) >= (C)->offset && (O) < ((C)->offset + (C)->size)) +static struct tracecmd_compress_chunk *get_zchunk (struct cpu_data *cpu,off64_t offset) +{ +struct cpu_zdata *cpuz = &cpu->compress; +int min, mid, max; + +if (!cpuz->chunks) +return NULL ; +if (offset > (cpuz->chunks[cpuz->count -1 ].offset + cpuz->chunks[cpuz->count -1 ].size)) +return NULL ; + +/* check if the requested offset is in the last requested chunk or in the next chunk */ +if (CHUNK_CHECK_OFFSET (cpuz->chunks + cpuz->last_chunk, offset)) +return cpuz->chunks + cpuz->last_chunk; + cpuz->last_chunk++; +if (cpuz->last_chunk < cpuz->count && +CHUNK_CHECK_OFFSET (cpuz->chunks + cpuz->last_chunk, offset)) +return cpuz->chunks + cpuz->last_chunk; + +/* do a binary search to find the chunk holding the given offset */ + min =0 ; + max = cpuz->count -1 ; + mid = (min + max)/2 ; +while (min <= max) { +if (offset < cpuz->chunks[mid].offset) + max = mid -1 ; +else if (offset > (cpuz->chunks[mid].offset + cpuz->chunks[mid].size)) + min = mid +1 ; +else +break ; + mid = (min + max)/2 ; + } + cpuz->last_chunk = mid; +return cpuz->chunks + mid; +} + +static void free_zpage (struct cpu_data *cpu_data,void *map) +{ +struct zchunk_cache *cache; + +list_for_each_entry (cache, &cpu_data->compress.cache, list) { +if (map <= cache->map && map > (cache->map + cache->chunk->size)) + goto found; + } +return ; + +found: + cache->ref--; +if (cache->ref) +return ; +list_del (&cache->list); +free (cache->map); +free (cache); +} + +static void *read_zpage (struct tracecmd_input *handle,int cpu,off64_t offset) +{ +struct cpu_data *cpu_data = &handle->cpu_data[cpu]; +struct tracecmd_compress_chunk *chunk; +struct zchunk_cache *cache; +void *map =NULL ; +int pindex; +int size; + +/* Look in the cache of already loaded chunks */ +list_for_each_entry (cache, &cpu_data->compress.cache, list) { +if (CHUNK_CHECK_OFFSET (cache->chunk, offset)) { + cache->ref++; + goto out; + } + } + + chunk =get_zchunk (cpu_data, offset); +if (!chunk) +return NULL ; + size = handle->page_size > chunk->size ? handle->page_size : chunk->size; + map =malloc (size); +if (!map) +return NULL ; +if (tracecmd_uncompress_chunk (handle->compress, chunk, map) <0 ) + goto error; + + cache =calloc (1 ,sizeof (struct zchunk_cache )); +if (!cache) + goto error; + cache->ref =1 ; + cache->chunk = chunk; + cache->map = map; +list_add (&cache->list, &cpu_data->compress.cache); + +/* a chunk can hold multiple pages, get the requested one */ +out: + pindex = (offset - cache->chunk->offset) / handle->page_size; +return cache->map + (pindex * handle->page_size); +error: +free (map); +return NULL ; +} +static void *allocate_page_map (struct tracecmd_input *handle,struct page *page,int cpu,off64_t offset) {
@@ -1278,6 +1377,9 @@ static void *allocate_page_map(struct tracecmd_input *handle,int ret;int fd; +if (handle->cpu_compressed && handle->read_zpage) +return read_zpage (handle, cpu, offset); +if (handle->read_page) { map =malloc (handle->page_size);if (!map)
@@ -1420,6 +1522,8 @@ static void __free_page(struct tracecmd_input *handle, struct page *page)if (handle->read_page)free (page->map); +else if (handle->read_zpage) +free_zpage (cpu_data, page->map);else free_page_map (page->page_map);
Signature · 1 line
2.31.1
PATCH 55/87 trace-cmd library: Handle latency trace in version 7 files
In reply to Tzvetomir Stoyanov (VMware)Latency trace data is saved the same was as flyrecord buffer data in trace files version 7. There is a BUFFER_LAT option which hols the latency specific trace metadata and points to the secrtion in the file with the trace data. Extended the input hanlder with latency trace context and added new logic to decompress and read the latency data. A new API is added to read latency data:
tracecmd_latency_data_read()
--- .../include/private/trace-cmd-private.h | 2 + lib/trace-cmd/trace-input.c | 91 ++++++++++++++++++- 2 files changed, 91 insertions(+), 2 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +2 -0
@@ -217,6 +217,8 @@ tracecmd_peek_data_ref(struct tracecmd_input *handle, int cpu)return rec; } +int tracecmd_latency_data_read (struct tracecmd_input *handle,char **buf,size_t *size); +struct tep_record *tracecmd_read_prev (struct tracecmd_input *handle,struct tep_record *record);
lib/trace-cmd/trace-input.c +89 -2
127 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 56/87 trace-cmd library: Handle buffer trace data init for version 7 files
In reply to Tzvetomir Stoyanov (VMware)CPU data initialization is different for trace files version 6 and 7. When a new input handler to trace buffer is created, initialize the CPU data according to the file version.
--- lib/trace-cmd/trace-input.c | 55 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 26 deletions(-)
lib/trace-cmd/trace-input.c +29 -26
@@ -4810,34 +4810,37 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx) new_handle->flags |=TRACECMD_FL_BUFFER_INSTANCE ; new_handle->pid_maps =NULL ; +if (handle->file_version <7 ) { +/* Save where we currently are */ + offset =lseek64 (handle->fd,0 ,SEEK_CUR ); -/* Save where we currently are */ - offset =lseek64 (handle->fd,0 ,SEEK_CUR ); - - ret =lseek64 (handle->fd, buffer->offset,SEEK_SET ); -if (ret <0 ) { -tracecmd_warning ("could not seek to buffer %s offset %ld\n" , - buffer->name, buffer->offset); - goto error; - } - -/* -* read_options_type() is called right after the CPU count so update -* file state accordingly. -*/ - new_handle->file_state =TRACECMD_FILE_CPU_COUNT ; - ret =read_options_type (new_handle); -if (!ret) - ret =read_cpu_data (new_handle); -if (ret <0 ) { -tracecmd_warning ("failed to read sub buffer %s\n" , buffer->name); - goto error; - } + ret =lseek64 (handle->fd, buffer->offset,SEEK_SET ); +if (ret == (off64_t)-1 ) { +tracecmd_warning ("could not seek to buffer %s offset %ld\n" , + buffer->name, buffer->offset); + goto error; + } +/* +* read_options_type() is called right after the CPU count so update +* file state accordingly. +*/ + new_handle->file_state =TRACECMD_FILE_CPU_COUNT ; + ret =read_options_type (new_handle); +if (!ret) + ret =read_cpu_data (new_handle); - ret =lseek64 (handle->fd, offset,SEEK_SET ); -if (ret <0 ) { -tracecmd_warning ("could not seek to back to offset %ld\n" , offset); - goto error; +if (ret <0 ) { +tracecmd_warning ("failed to read sub buffer %s\n" , buffer->name); + goto error; + } + ret =lseek64 (handle->fd, offset,SEEK_SET ); +if (ret <0 ) { +tracecmd_warning ("could not seek to back to offset %ld\n" , offset); + goto error; + } + }else { +if (init_buffer_cpu_data (new_handle, buffer) <0 ) + goto error; }return new_handle;
Signature · 1 line
2.31.1
PATCH 57/87 trace-cmd report: Use the new latency API to read data
In reply to Tzvetomir Stoyanov (VMware)When reading latency trace data, use the new API
tracecmd_latency_data_read()
It handles reading latency trace data from both version 6 and 7 trace files.
--- tracecmd/trace-read.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
tracecmd/trace-read.c +11 -8
@@ -948,18 +948,20 @@ void trace_show_data(struct tracecmd_input *handle, struct tep_record *record)printf ("\n" ); } -static void read_rest (void ) +static void read_latency (struct tracecmd_input *handle) { -char buf[BUFSIZ +1 ]; +char *buf =NULL ; +size_t size =0 ;int r;do { - r =read (input_fd, buf,BUFSIZ ); -if (r >0 ) { - buf[r] =0 ; -printf ("%s" , buf); - } + r =tracecmd_latency_data_read (handle, &buf, &size); +if (r >0 ) +printf ("%.*s" , r, buf); }while (r >0 ); + +printf ("\n" ); +free (buf); } static int
@@ -1241,7 +1243,8 @@ static void read_data_info(struct list_head *handle_list, enum output_type otypeif (ret >0 ) {if (multi_inputs)die ("latency traces do not work with multiple inputs" ); -read_rest (); + +read_latency (handles->handle);return ; }
Signature · 1 line
2.31.1
PATCH 58/87 trace-cmd report: Close input file handlers on exit
In reply to Tzvetomir Stoyanov (VMware)When "trace-cmd report" is interrupted with "ctrl-c", close the input hanlders to opened trace files, to delete any temporary files used when reading the trace data.
--- tracecmd/trace-read.c | 7 +++++++ 1 file changed, 7 insertions(+)
tracecmd/trace-read.c +7 -0
@@ -1366,7 +1366,14 @@ struct tracecmd_input *read_trace_header(const char *file, int flags)static void sig_end (int sig) { +struct handle_list *handles; +fprintf (stderr,"trace-cmd: Received SIGINT\n" ); + +list_for_each_entry (handles, &handle_list, list) { +tracecmd_close (handles->handle); + } +exit (0 ); }
Signature · 1 line
2.31.1
PATCH 59/87 trace-cmd report: Do not print empty buffer name
In reply to Tzvetomir Stoyanov (VMware)In trace file version 7, the top buffer is saved with its empty file name, string "". When displaying it, filter those empty strings.
--- tracecmd/trace-read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tracecmd/trace-read.c +1 -1
@@ -1175,7 +1175,7 @@ static void print_handle_file(struct handle_list *handles)/* Only print file names if more than one file is read */ if (!multi_inputs && !instances)return ; -if (handles->file) +if (handles->file && *handles->file !='\0' )printf ("%*s: " , max_file_size, handles->file);else printf ("%*s " , max_file_size,"" );
Signature · 1 line
2.31.1
PATCH 60/87 trace-cmd report: Init the top trace instance earlier
In reply to Tzvetomir Stoyanov (VMware)The instance must be initialized before calling the tracecmd_cpus() API, as in trace files version 7, CPU count is set when the trace data are initialized.
--- tracecmd/trace-read.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tracecmd/trace-read.c +5 -3
@@ -1217,6 +1217,11 @@ static void read_data_info(struct list_head *handle_list, enum output_type otypelist_for_each_entry (handles, handle_list, list) {int cpus; +if (!tracecmd_is_buffer_instance (handles->handle)) { + ret =tracecmd_init_data (handles->handle); +if (ret <0 ) +die ("failed to init data" ); + } cpus =tracecmd_cpus (handles->handle); handles->cpus = cpus; handles->last_timestamp =calloc (cpus,sizeof (*handles->last_timestamp));
@@ -1227,9 +1232,6 @@ static void read_data_info(struct list_head *handle_list, enum output_type otypeif (tracecmd_is_buffer_instance (handles->handle))continue ; - ret =tracecmd_init_data (handles->handle); -if (ret <0 ) -die ("failed to init data" );if (align_ts) { ts =tracecmd_get_first_ts (handles->handle);if (first || first_ts > ts)
Signature · 1 line
2.31.1
PATCH 61/87 trace-cmd: Call additional APIs when creating trace file
In reply to Tzvetomir Stoyanov (VMware)When creating a trace file, two more APIs should be called, compared to the old flow:
- tracecmd_write_buffer_info(), to write version 6 buffers metadata in the file.
- tracecmd_write_options() after the trace data is written, for version 7 trace files, as the buffer metadata is appended to the options at the end.
--- tracecmd/trace-listen.c | 6 ++++++ tracecmd/trace-record.c | 4 ++++ tracecmd/trace-restore.c | 3 ++- tracecmd/trace-split.c | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-)
tracecmd/trace-listen.c +6 -0
@@ -604,6 +604,9 @@ static int put_together_file(int cpus, int ofd, const char *node,if (write_options) { ret =tracecmd_write_cpus (handle, cpus); +if (ret) + goto out; + ret =tracecmd_write_buffer_info (handle);if (ret) goto out; ret =tracecmd_write_options (handle);
@@ -612,6 +615,9 @@ static int put_together_file(int cpus, int ofd, const char *node, } ret =tracecmd_write_cpu_data (handle, cpus, temp_files,"" ); +if (!ret &&tracecmd_get_out_file_version (handle) >=7 ) +tracecmd_write_options (handle); + out:tracecmd_output_close (handle);for (cpu--; cpu >=0 ; cpu--) {
tracecmd/trace-record.c +4 -0
@@ -3738,6 +3738,9 @@ setup_connection(struct buffer_instance *instance, struct common_record_contextif (ret) goto error; ret =tracecmd_write_cpus (network_handle, instance->cpu_count); +if (ret) + goto error; + ret =tracecmd_write_buffer_info (network_handle);if (ret) goto error; ret =tracecmd_write_options (network_handle);
@@ -4109,6 +4112,7 @@ static void setup_agent(struct buffer_instance *instance,add_options (network_handle, ctx);tracecmd_write_cmdlines (network_handle);tracecmd_write_cpus (network_handle, instance->cpu_count); +tracecmd_write_buffer_info (network_handle);tracecmd_write_options (network_handle);tracecmd_msg_finish_sending_data (instance->msg_handle); instance->network_handle = network_handle;
tracecmd/trace-restore.c +2 -1
@@ -163,6 +163,7 @@ void trace_restore (int argc, char **argv)if (tracecmd_append_cpu_data (handle, args, &argv[first_arg]) <0 )die ("failed to append data" ); - +if (tracecmd_get_out_file_version (handle) >=7 ) +tracecmd_write_options (handle);return ; }
tracecmd/trace-split.c +3 -0
@@ -391,6 +391,9 @@ static double parse_file(struct tracecmd_input *handle,if (tracecmd_append_cpu_data (ohandle, cpus, cpu_list) <0 )die ("Failed to append tracing data\n" ); +if (tracecmd_get_out_file_version (ohandle) >=7 ) +tracecmd_write_options (ohandle); + current = end;for (cpu =0 ; cpu < cpus; cpu++) {/* Set the tracecmd cursor to the next set of records */
Signature · 1 line
2.31.1
PATCH 62/87 trace-cmd dump: Add helpers for processing trace file version 7
In reply to Tzvetomir Stoyanov (VMware)New global variables are added, that hold trace file context:
- trace file version
- compression context
Also a few helper functions for reading compressed data.
--- tracecmd/trace-dump.c | 88 ++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 21 deletions(-)
tracecmd/trace-dump.c +67 -21
@@ -26,6 +26,9 @@static struct tep_handle *tep;static unsigned int trace_cpus;static int has_clock; +static unsigned long file_version; +static bool read_compress; +static struct tracecmd_compression *compress;enum dump_items {SUMMARY = (1 <<0 ),
@@ -52,46 +55,69 @@ 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) +{ + +if (read_compress) +return tracecmd_compress_read (compress, dst, len); +return read_fd (fd, dst, len); +} + +static int do_lseek (int fd,int offset,int whence) +{ +if (read_compress) +return tracecmd_compress_lseek (compress, offset, whence); +return lseek64 (fd, offset, whence); +} + +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 +172,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 +193,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 ))
@@ -234,6 +259,27 @@ static void dump_header_event(int fd)read_dump_string (fd, size,HEAD_EVENT ); } +static void uncompress_reset (void ) +{ +if (compress && file_version >=7 ) { + read_compress = false; +tracecmd_compress_reset (compress); + } +} + +static int uncompress_block (void ) +{ +int ret =0 ; + +if (compress && file_version >=7 ) { + ret =tracecmd_uncompress_block (compress); +if (!ret) + read_compress = true; + + } +return ret; +} +static void dump_ftrace_events_format (int fd) {unsigned long long size;
@@ -578,7 +624,7 @@ static void dump_options(int fd)default :do_print (OPTIONS ," %d %d\t[Unknown option, size - skipping]\n" , option, size); -lseek64 (fd, size,SEEK_CUR ); +do_lseek (fd, size,SEEK_CUR );break ; } }
Signature · 1 line
2.31.1
PATCH 63/87 trace-cmd dump: Print compression header
In reply to Tzvetomir Stoyanov (VMware)Dump the compression header of trace file version 7
--- tracecmd/trace-dump.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
tracecmd/trace-dump.c +24 -0
@@ -217,6 +217,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 zname[DUMP_SIZE ]; +char zver[DUMP_SIZE ]; + +if (file_version <7 ) +return ; + +/* get compression header */ +if (read_file_string (fd, zname,DUMP_SIZE )) +die ("no compression header" ); +if (read_file_string (fd, zver,DUMP_SIZE )) +die ("no compression version" ); +do_print ((SUMMARY ),"\t\t%s\t[Compression algorithm]\n" , zname); +do_print ((SUMMARY ),"\t\t%s\t[Compression version]\n" , zver); + +if (strcmp (zname,"none" )) { + compress =tracecmd_compress_alloc (zname, zver, fd, tep,NULL ); +if (!compress) +die ("cannot uncompress the file" ); + } +} +static void dump_header_page (int fd) {unsigned long long size;
@@ -715,6 +738,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.31.1
PATCH 64/87 trace-cmd dump: Add helpers for processing trace file sections
In reply to Tzvetomir Stoyanov (VMware)Added a new local databse for storing sections, found in trace file version 7.
--- tracecmd/trace-dump.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
tracecmd/trace-dump.c +22 -1
@@ -43,8 +43,18 @@ enum dump_items {OPTIONS = (1 <<9 ),FLYRECORD = (1 <<10 ),CLOCK = (1 <<11 ), + SECTIONS = (1 << 12), }; +struct file_section { +int id; +unsigned long long offset; +struct file_section *next; +enum dump_items verbosity; +}; + +static struct file_section *sections; +enum dump_items verbosity;#define DUMP_CHECK (X ) ((X) & verbosity)
@@ -723,6 +733,17 @@ static void dump_therest(int fd) } } +static void free_sections (void ) +{ +struct file_section *del; + +while (sections) { + del = sections; + sections = sections->next; +free (del); + } +} +static void dump_file (const char *file) {int fd;
@@ -748,7 +769,7 @@ static void dump_file(const char *file)dump_cmdlines (fd);dump_cpus_count (fd);dump_therest (fd); - +free_sections ();tep_free (tep); tep =NULL ;close (fd);
Signature · 1 line
2.31.1
PATCH 65/87 trace-cmd dump: Read recursively all options sections
In reply to Tzvetomir Stoyanov (VMware)Trace file version 7 supports multiple options sections in the file. The DONE option is extended to hold the offset to the next options section. A new logic for handling the extended DONE option and to read recursively all options sections is added.
--- tracecmd/trace-dump.c | 77 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 9 deletions(-)
tracecmd/trace-dump.c +68 -9
@@ -422,6 +422,30 @@ static void dump_option_string(int fd, int size, char *desc)read_dump_string (fd, size,OPTIONS ); } +static void dump_section_header (int fd,enum dump_items v,unsigned short *flags) +{ +unsigned long long offset; +unsigned short fl; +char buf[DUMP_SIZE ]; +unsigned short id; +int size; + + offset =lseek64 (fd,0 ,SEEK_CUR ); +if (read_file_number (fd, &id,2 )) +die ("cannot read the section id" ); +if (read_file_string (fd, buf,DUMP_SIZE )) +die ("no section description" ); +if (read_file_number (fd, &fl,2 )) +die ("cannot read the section flags" ); +if (read_file_number (fd, &size,4 )) +die ("cannot read section size" ); +do_print (v,"\t[Section %d @ %lld: \"%s\", flags 0x%X, %d bytes]\n" , + id, offset, buf, fl, size); + +if (flags) + *flags = fl; +} +static void dump_option_buffer (int fd,int size) {unsigned long long offset;
@@ -591,25 +615,47 @@ void dump_option_tsc2nsec(int fd, int size)do_print (OPTIONS ,"%d %d %llu [multiplier, shift, offset]\n" , mult, shift, offset); } -static void dump_options (int fd) +static int dump_options_read (int fd); + +static int dump_option_done (int fd,int size) +{ +unsigned long long offset; + +do_print (OPTIONS ,"\t\t[Option DONE, %d bytes]\n" , size); + +if (file_version <7 || size <8 ) +return 0 ; +if (read_file_number (fd, &offset,8 )) +die ("cannot read the next options offset" ); +do_print (OPTIONS ,"%lld\n" , offset); +if (!offset) +return 0 ; + +if (lseek64 (fd, offset,SEEK_SET ) == (off_t)-1 ) +die ("cannot goto next options offset %lld" , offset); +return dump_options_read (fd); +} + +static int dump_options_read (int fd) { +unsigned short flags =0 ;unsigned short option;unsigned int size;int count =0 ; +if (file_version >=7 ) +dump_section_header (fd,OPTIONS , &flags); +if ((flags &TRACECMD_SEC_FL_COMPRESS ) &&uncompress_block ()) +die ("cannot uncompress file block" ); +for (;;) {if (read_file_number (fd, &option,2 ))die ("cannot read the option id" ); -if (!option) +if (option ==TRACECMD_OPTION_DONE && file_version <7 )break ;if (read_file_number (fd, &size,4 ))die ("cannot read the option size" ); - count++; -if (!DUMP_CHECK (OPTIONS ) && !DUMP_CHECK (CLOCK ) && !DUMP_CHECK (SUMMARY )) { -lseek64 (fd, size,SEEK_CUR ); -continue ; - }switch (option) {case TRACECMD_OPTION_DATE :dump_option_string (fd, size,"DATE" );
@@ -621,7 +667,8 @@ static void dump_options(int fd)dump_option_buffer (fd, size);break ;case TRACECMD_OPTION_TRACECLOCK : -dump_option_string (fd, size,"TRACECLOCK" ); +do_print (OPTIONS ,"\t\t[Option TRACECLOCK, %d bytes]\n" , size); +read_dump_string (fd, size,OPTIONS |CLOCK ); has_clock =1 ;break ;case TRACECMD_OPTION_UNAME :
@@ -654,6 +701,10 @@ static void dump_options(int fd)case TRACECMD_OPTION_TSC2NSEC :dump_option_tsc2nsec (fd, size);break ; +case TRACECMD_OPTION_DONE : +uncompress_reset (); + count +=dump_option_done (fd, size); +return count;default :do_print (OPTIONS ," %d %d\t[Unknown option, size - skipping]\n" , option, size);
@@ -661,8 +712,16 @@ static void dump_options(int fd)break ; } } -do_print (SUMMARY ,"\t[%d options]\n" , count); +uncompress_reset (); +return count; +} + +static void dump_options (int fd) +{ +int count; + count =dump_options_read (fd); +do_print (SUMMARY |OPTIONS ,"\t[%d options]\n" , count); }static void dump_latency (int fd)
Signature · 1 line
2.31.1
PATCH 66/87 trace-cmd dump: Read extended BUFFER option
In reply to Tzvetomir Stoyanov (VMware)In trace file version 7 the BUFFER option is extended to hold a trace metadata, related to the recorded instance. Also, a new BUFFER_LAT option is added for latency trace data. Implemended logic for reading and printing these extended options.
--- tracecmd/trace-dump.c | 64 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-)
tracecmd/trace-dump.c +59 -5
@@ -446,19 +446,72 @@ static void dump_section_header(int fd, enum dump_items v, unsigned short *flags *flags = fl; } -static void dump_option_buffer (int fd,int size) +static void dump_option_buffer (int fd,unsigned short option,int size) { +unsigned long long total_size =0 ; +unsigned long long data_size; +unsigned long long current;unsigned long long offset; +unsigned short flags; +char clock[DUMP_SIZE ]; +char name[DUMP_SIZE ]; +int cpus =0 ; +int id; +int i;if (size <8 )die ("broken buffer option with size %d" , size);if (read_file_number (fd, &offset,8 ))die ("cannot read the offset of the buffer option" ); +if (read_file_string (fd, name,DUMP_SIZE )) +die ("cannot read the name of the buffer option" ); +if (file_version <7 ) { +do_print (OPTIONS |FLYRECORD ,"\t\t[Option BUFFER, %d bytes]\n" , size); +do_print (OPTIONS |FLYRECORD ,"%lld [offset]\n" , offset); +do_print (OPTIONS |FLYRECORD ,"\"%s\" [name]\n" , name); +return ; + } + + current =lseek64 (fd,0 ,SEEK_CUR ); +if (lseek64 (fd, offset,SEEK_SET ) == (off_t)-1 ) +die ("cannot goto buffer offset %lld" , offset); + +dump_section_header (fd,FLYRECORD , &flags); + +if (lseek64 (fd, current,SEEK_SET ) == (off_t)-1 ) +die ("cannot go back to buffer option" ); + +do_print (OPTIONS |FLYRECORD ,"\t\t[Option BUFFER, %d bytes]\n" , size); +do_print (OPTIONS |FLYRECORD ,"%lld [offset]\n" , offset); +do_print (OPTIONS |FLYRECORD ,"\"%s\" [name]\n" , name); + +if (read_file_string (fd, clock,DUMP_SIZE )) +die ("cannot read clock of the buffer option" ); +do_print (OPTIONS |FLYRECORD ,"\"%s\" [clock]\n" , clock); +if (option ==TRACECMD_OPTION_BUFFER ) { +if (read_file_number (fd, &cpus,4 )) +die ("cannot read the cpu count of the buffer option" ); + +do_print (OPTIONS |FLYRECORD ,"%d [CPUs]:\n" , cpus); +for (i =0 ; i < cpus; i++) { +if (read_file_number (fd, &id,4 )) +die ("cannot read the id of cpu %d from the buffer option" , i); +if (read_file_number (fd, &offset,8 )) +die ("cannot read the offset of cpu %d from the buffer option" , i); +if (read_file_number (fd, &data_size,8 )) +die ("cannot read the data size of cpu %d from the buffer option" , i); + total_size += data_size; +do_print (OPTIONS |FLYRECORD ," %d %lld\t%lld\t[id, data offset and size]\n" , + id, offset, data_size); + } +do_print (SUMMARY ,"\t\[buffer \"%s\", \"%s\" clock, " +"%d cpus, %lld bytes flyrecord data]\n" , + name, clock, cpus, total_size); + }else { +do_print (SUMMARY ,"\t\[buffer \"%s\", \"%s\" clock, latency data]\n" , name, clock); + } -do_print (OPTIONS ,"\t\t[Option BUFFER, %d bytes]\n" , size); -do_print (OPTIONS ,"%lld [offset]\n" , offset); -read_dump_string (fd, size -8 ,OPTIONS ); }static void dump_option_int (int fd,int size,char *desc)
@@ -664,7 +717,8 @@ static int dump_options_read(int fd)dump_option_string (fd, size,"CPUSTAT" );break ;case TRACECMD_OPTION_BUFFER : -dump_option_buffer (fd, size); +case TRACECMD_OPTION_BUFFER_LAT : +dump_option_buffer (fd, option, size);break ;case TRACECMD_OPTION_TRACECLOCK :do_print (OPTIONS ,"\t\t[Option TRACECLOCK, %d bytes]\n" , size);
Signature · 1 line
2.31.1
PATCH 67/87 trace-cmd dump: Dump sections
In reply to Tzvetomir Stoyanov (VMware)In trace file version 7, headers are stored as sections. This allows their position in the file not to be fixed. Poters to these sections are stored as trace options. Add logic to handle these new options:
HEADER_INFO
FTRACE_EVENTS
EVENT_FORMATS
KALLSYM
PRINTK
CMDLINES
--- tracecmd/trace-dump.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
tracecmd/trace-dump.c +37 -0
@@ -668,6 +668,24 @@ void dump_option_tsc2nsec(int fd, int size)do_print (OPTIONS ,"%d %d %llu [multiplier, shift, offset]\n" , mult, shift, offset); } +static void dump_option_section (int fd,unsigned int size, +unsigned short id,char *desc,enum dump_items v) +{ +struct file_section *sec; + + sec =calloc (1 ,sizeof (struct file_section )); +if (!sec) +die ("cannot allocate new section" ); + sec->next = sections; + sections = sec; + sec->id = id; + sec->verbosity = v; +if (read_file_number (fd, &sec->offset,8 )) +die ("cannot read the option %d offset" , id); +do_print (OPTIONS ,"\t\t[Option %s, %d bytes]\n" , desc, size); +do_print (OPTIONS ,"%lld\n" , sec->offset); +} +static int dump_options_read (int fd);static int dump_option_done (int fd,int size)
@@ -755,6 +773,25 @@ static int dump_options_read(int fd)case TRACECMD_OPTION_TSC2NSEC :dump_option_tsc2nsec (fd, size);break ; +case TRACECMD_OPTION_HEADER_INFO : +dump_option_section (fd, size, option,"HEADERS" ,HEAD_PAGE |HEAD_EVENT ); +break ; +case TRACECMD_OPTION_FTRACE_EVENTS : +dump_option_section (fd, size, option,"FTRACE EVENTS" ,FTRACE_FORMAT ); +break ; +case TRACECMD_OPTION_EVENT_FORMATS : +dump_option_section (fd, size, option, +"EVENT FORMATS" ,EVENT_SYSTEMS |EVENT_FORMAT ); +break ; +case TRACECMD_OPTION_KALLSYMS : +dump_option_section (fd, size, option,"KALLSYMS" ,KALLSYMS ); +break ; +case TRACECMD_OPTION_PRINTK : +dump_option_section (fd, size, option,"PRINTK" ,TRACE_PRINTK ); +break ; +case TRACECMD_OPTION_CMDLINES : +dump_option_section (fd, size, option,"CMDLINES" ,CMDLINES ); +break ;case TRACECMD_OPTION_DONE :uncompress_reset (); count +=dump_option_done (fd, size);
Signature · 1 line
2.31.1
PATCH 68/87 trace-cmd dump: Dump trace file version 7
In reply to Tzvetomir Stoyanov (VMware)Trace file version 7 has different structure than version 6. Separates parsing both versions in different flows.
--- tracecmd/trace-dump.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-)
tracecmd/trace-dump.c +29 -9
@@ -883,6 +883,31 @@ static void dump_therest(int fd) } } +static void dump_v6_file (int fd) +{ +dump_header_page (fd); +dump_header_event (fd); +dump_ftrace_events_format (fd); +dump_events_format (fd); +dump_kallsyms (fd); +dump_printk (fd); +dump_cmdlines (fd); +dump_cpus_count (fd); +dump_therest (fd); +} + +static void dump_v7_file (int fd) +{ +long long offset; + +if (read_file_number (fd, &offset,8 )) +die ("cannot read offset of the first option section" ); + +if (lseek64 (fd, offset,SEEK_SET ) == (off64_t)-1 ) +die ("cannot goto options offset %lld" , offset); +dump_options (fd); +} +static void free_sections (void ) {struct file_section *del;
@@ -910,15 +935,10 @@ static void dump_file(const char *file)dump_initial_format (fd);dump_compress (fd); -dump_header_page (fd); -dump_header_event (fd); -dump_ftrace_events_format (fd); -dump_events_format (fd); -dump_kallsyms (fd); -dump_printk (fd); -dump_cmdlines (fd); -dump_cpus_count (fd); -dump_therest (fd); +if (file_version <7 ) +dump_v6_file (fd); +else +dump_v7_file (fd);free_sections ();tep_free (tep); tep =NULL ;
Signature · 1 line
2.31.1
PATCH 69/87 trace-cmd dump: Dump sections content
In reply to Tzvetomir Stoyanov (VMware)In trace file version 7, dump the content of the headers content, that are stored as sections. Added logic to dump these headers:
HEADER_INFO
FTRACE_EVENTS
EVENT_FORMATS
KALLSYM
PRINTK
CMDLINES
--- tracecmd/trace-dump.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
tracecmd/trace-dump.c +41 -0
@@ -686,6 +686,46 @@ static void dump_option_section(int fd, unsigned int size,do_print (OPTIONS ,"%lld\n" , sec->offset); } +static void dump_sections (int fd) +{ +struct file_section *sec = sections; +unsigned short flags; + +while (sec) { +if (lseek64 (fd, sec->offset,SEEK_SET ) == (off_t)-1 ) +die ("cannot goto option offset %lld" , sec->offset); + +dump_section_header (fd, sec->verbosity, &flags); + +if ((flags &TRACECMD_SEC_FL_COMPRESS ) &&uncompress_block ()) +die ("cannot uncompress section block" ); + +switch (sec->id) { +case TRACECMD_OPTION_HEADER_INFO : +dump_header_page (fd); +dump_header_event (fd); +break ; +case TRACECMD_OPTION_FTRACE_EVENTS : +dump_ftrace_events_format (fd); +break ; +case TRACECMD_OPTION_EVENT_FORMATS : +dump_events_format (fd); +break ; +case TRACECMD_OPTION_KALLSYMS : +dump_kallsyms (fd); +break ; +case TRACECMD_OPTION_PRINTK : +dump_printk (fd); +break ; +case TRACECMD_OPTION_CMDLINES : +dump_cmdlines (fd); +break ; + } +uncompress_reset (); + sec = sec->next; + } +} +static int dump_options_read (int fd);static int dump_option_done (int fd,int size)
@@ -906,6 +946,7 @@ static void dump_v7_file(int fd)if (lseek64 (fd, offset,SEEK_SET ) == (off64_t)-1 )die ("cannot goto options offset %lld" , offset);dump_options (fd); +dump_sections (fd); }static void free_sections (void )
Signature · 1 line
2.31.1
PATCH 70/87 trace-cmd dump: Add new argument --sections
In reply to Tzvetomir Stoyanov (VMware)The new "trace-cmd dump --sections" argument walks through the sections from a trace file version 7 and prints their headers. The logic does not rely on the options, describing these sections. It could be useful to dump broken or incomplete trace files.
--- tracecmd/trace-dump.c | 70 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-)
tracecmd/trace-dump.c +67 -3
@@ -686,7 +686,7 @@ static void dump_option_section(int fd, unsigned int size,do_print (OPTIONS ,"%lld\n" , sec->offset); } -static void dump_sections (int fd) +static void dump_sections (int fd,int count) {struct file_section *sec = sections;unsigned short flags;
@@ -724,6 +724,7 @@ static void dump_sections(int fd)uncompress_reset (); sec = sec->next; } +do_print (SUMMARY |SECTIONS ,"\t[%d sections]\n" , count); }static int dump_options_read (int fd);
@@ -936,17 +937,76 @@ static void dump_v6_file(int fd)dump_therest (fd); } +static int walk_v7_sections (int fd) +{ +unsigned long long offset, soffset; +unsigned short fl; +char buf[DUMP_SIZE ]; +unsigned short id; +int size, csize, rsize; +int count =0 ; + + offset =lseek64 (fd,0 ,SEEK_CUR ); +do { + soffset =lseek64 (fd,0 ,SEEK_CUR ); +if (read_file_number (fd, &id,2 )) +break ; +if (id >=TRACECMD_OPTION_MAX ) +die ("Unknown section id %d" , id); +if (read_file_string (fd, buf,DUMP_SIZE )) +die ("cannot read section description" ); +if (read_file_number (fd, &fl,2 )) +die ("cannot read section flags" ); +if (read_file_number (fd, &size,4 )) +die ("cannot read section size" ); +if (size <=4 ) +die ("Section %d (%s) is too small, %d bytes" , id, buf, size); + count++; +if (fl &TRACECMD_SEC_FL_COMPRESS ) { +if (id ==TRACECMD_OPTION_BUFFER || + id ==TRACECMD_OPTION_BUFFER_LAT ) { +do_print (SECTIONS , +"\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, " +"%d compressed bytes]\n" , + id, soffset, buf, fl, size); + }else { +if (read_file_number (fd, &csize,4 )) +die ("cannot read section size" ); +if (read_file_number (fd, &rsize,4 )) +die ("cannot read section size" ); +do_print (SECTIONS ,"\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, " +"%d compressed, %d uncompressed]\n" , + id, soffset, buf, fl, csize, rsize); + size -=8 ; + } + }else { +do_print (SECTIONS ,"\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, %d bytes]\n" , + id, soffset, buf, fl, size); + } + +if (lseek64 (fd, size,SEEK_CUR ) == (off_t)-1 ) +break ; + }while (1 ); + +if (lseek64 (fd, offset,SEEK_SET ) == (off_t)-1 ) +die ("cannot restore the original file location" ); +return count; +} +static void dump_v7_file (int fd) {long long offset; +int sections;if (read_file_number (fd, &offset,8 ))die ("cannot read offset of the first option section" ); -if (lseek64 (fd, offset,SEEK_SET ) == (off64_t)-1 ) + sections =walk_v7_sections (fd); + +if (lseek64 (fd, offset,SEEK_SET ) == (off_t)-1 )die ("cannot goto options offset %lld" , offset);dump_options (fd); -dump_sections (fd); +dump_sections (fd, sections); }static void free_sections (void )
@@ -987,6 +1047,7 @@ static void dump_file(const char *file) }enum { + OPT_sections =241 , OPT_verbose =242 , OPT_clock =243 , OPT_all =244 ,
@@ -1030,6 +1091,7 @@ void trace_dump(int argc, char **argv) {"options", no_argument, NULL, OPT_options}, {"flyrecord", no_argument, NULL, OPT_flyrecord}, {"clock", no_argument, NULL, OPT_clock}, + {"sections", no_argument, NULL, OPT_sections}, {"validate", no_argument, NULL, 'v'}, {"help", no_argument, NULL, '?'}, {"verbose", optional_argument, NULL, OPT_verbose},
@@ -1092,6 +1154,8 @@ void trace_dump(int argc, char **argv)case OPT_verbose:if (trace_set_verbose (optarg) <0 )die ("invalid verbose level %s" , optarg); +case OPT_sections: + verbosity |=SECTIONS ;break ;default :usage (argv);
Signature · 1 line
2.31.1
PATCH 71/87 trace-cmd dump: Align better the output of flyrecord dump
In reply to Tzvetomir Stoyanov (VMware)The flyrecord dump prints various file offsets and sizes, that can be huge numbers. Add format arguments to align better the output.
--- tracecmd/trace-dump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tracecmd/trace-dump.c +2 -1
@@ -897,7 +897,7 @@ static void dump_flyrecord(int fd)die ("cannot read the cpu %d offset" , i);if (read_file_number (fd, &cpu_size,8 ))die ("cannot read the cpu %d size" , i); -do_print (FLYRECORD ,"\t\t %lld %lld\t[offset, size of cpu %d]\n" , +do_print (FLYRECORD ,"\t %10.lld %10.lld\t[offset, size of cpu %d]\n" , cpu_offset, cpu_size, i); }dump_clock (fd);
@@ -1154,6 +1154,7 @@ void trace_dump(int argc, char **argv)case OPT_verbose:if (trace_set_verbose (optarg) <0 )die ("invalid verbose level %s" , optarg); +break ;case OPT_sections: verbosity |=SECTIONS ;break ;
Signature · 1 line
2.31.1
PATCH 72/87 trace-cmd library: Add zlib compression algorithm
In reply to Tzvetomir Stoyanov (VMware)Added implementation for zlib compression algorithm, using libz libraray, if available.
--- Makefile | 7 ++ lib/trace-cmd/Makefile | 8 ++ lib/trace-cmd/include/trace-cmd-local.h | 4 + lib/trace-cmd/trace-compress-zlib.c | 109 ++++++++++++++++++++++++ tracecmd/Makefile | 4 + 5 files changed, 132 insertions(+) create mode 100644 lib/trace-cmd/trace-compress-zlib.c
Makefile +7 -0
@@ -311,6 +311,13 @@ ifeq ($(PERF_DEFINED), 1) CFLAGS += -DPERF endif +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) +export ZLIB_INSTALLED +CFLAGS += -DHAVE_ZLIB +$(info Have zlib compression support) +endif + CUNIT_INSTALLED := $(shell if (printf "$(pound)include <CUnit/Basic.h>\n void main(){CU_initialize_registry();}" | $(CC) -o /dev/null -x c - -lcunit >/dev/null 2>&1) ; then echo 1; else echo 0 ; fi) export CUNIT_INSTALLED
lib/trace-cmd/Makefile +8 -0
@@ -26,6 +26,10 @@ 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 OBJS += trace-ftrace.o
@@ -46,6 +50,10 @@ $(LIBTRACECMD_STATIC): $(OBJS) LIBS = $(LIBTRACEEVENT_LDLAGS) $(LIBTRACEFS_LDLAGS) -lpthread +ifeq ($(ZLIB_INSTALLED), 1) +LIBS += -lz +endif + $(LIBTRACECMD_SHARED_VERSION): $(LIBTRACECMD_SHARED) @ln -sf $(<F) $@
lib/trace-cmd/include/trace-cmd-local.h +4 -0
@@ -24,6 +24,10 @@ void tracecmd_info(const char *fmt, ...);#endif #endif +#ifdef HAVE_ZLIB +int tracecmd_zlib_init (void ); +#endif +struct data_file_write {unsigned long long file_size;unsigned long long write_size;
lib/trace-cmd/trace-compress-zlib.c new file +109 -0
109 lines not on this page · raw message
tracecmd/Makefile +4 -0
@@ -51,6 +51,10 @@ CONFIG_INCLUDES = CONFIG_LIBS = -lrt -lpthread $(TRACE_LIBS) CONFIG_FLAGS = +ifeq ($(ZLIB_INSTALLED), 1) +CONFIG_LIBS += -lz +endif + all: $(TARGETS) $(bdir):
Signature · 1 line
2.31.1
PATCH 73/87 trace-cmd library: Reuse local function that writes to output handler
In reply to Tzvetomir Stoyanov (VMware)Reuse do_write_check() internal helper function in the trace-cmd library. It should be used when writing data to an output handler, instead of writing to a fd, as it handles compression and network contexts.
--- lib/trace-cmd/include/trace-cmd-local.h | 2 ++ 1 file changed, 2 insertions(+)
lib/trace-cmd/include/trace-cmd-local.h +2 -0
@@ -59,6 +59,8 @@ out_write_section_header(struct tracecmd_output *handle, unsigned short header_i char *description, enum tracecmd_section_flags flags, bool option);int out_update_section_header (struct tracecmd_output *handle,unsigned long long offset); +long long do_write_check (struct tracecmd_output *handle,const void *data,long long size); +struct cpu_data_source {int fd;int size;
Signature · 1 line
2.31.1
PATCH 74/87 trace-cmd library: Use output handler when copying data from input file
In reply to Tzvetomir Stoyanov (VMware)When copying data between two trace files, use input and output handlers, instead of raw file descriptors. Handlers take care of file version and compression context.
--- .../include/private/trace-cmd-private.h | 3 +- lib/trace-cmd/trace-input.c | 145 +++++++++--------- lib/trace-cmd/trace-output.c | 2 +- 3 files changed, 78 insertions(+), 72 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +2 -1
@@ -179,7 +179,8 @@ int tracecmd_get_parsing_failures(struct tracecmd_input *handle);int tracecmd_long_size (struct tracecmd_input *handle);int tracecmd_page_size (struct tracecmd_input *handle);int tracecmd_cpus (struct tracecmd_input *handle); -int tracecmd_copy_headers (struct tracecmd_input *handle,int fd, +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);void tracecmd_set_flag (struct tracecmd_input *handle,int flag);
lib/trace-cmd/trace-input.c +75 -70
365 lines not on this page · raw message
lib/trace-cmd/trace-output.c +1 -1
@@ -2490,7 +2490,7 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle,if (tracecmd_output_set_from_input (handle, ihandle)) goto out_free;tracecmd_output_write_init (handle); -if (tracecmd_copy_headers (ihandle, handle->fd,0 ,0 ) <0 ) +if (tracecmd_copy_headers (ihandle, handle,0 ,0 ) <0 ) goto out_free; handle->file_state =tracecmd_get_file_state (ihandle);
Signature · 1 line
2.31.1
PATCH 75/87 trace-cmd library: Handle version 7 files when copying headers between files
In reply to Tzvetomir Stoyanov (VMware)When copying header data between trace files, handle the file versions. Internal library functions for copying these headers are fixed to work with trace file version 7:
copy_header_files
copy_ftrace_files
copy_event_files
copy_proc_kallsyms
copy_command_lines
--- lib/trace-cmd/include/trace-cmd-local.h | 1 + lib/trace-cmd/trace-input.c | 191 ++++++++++++++++++++---- lib/trace-cmd/trace-output.c | 5 + 3 files changed, 167 insertions(+), 30 deletions(-)
lib/trace-cmd/include/trace-cmd-local.h +1 -0
@@ -51,6 +51,7 @@ void out_compression_reset(struct tracecmd_output *handle);void in_uncompress_reset (struct tracecmd_input *handle);int in_uncompress_block (struct tracecmd_input *handle); +void out_set_file_state (struct tracecmd_output *handle,int new_state);unsigned long long out_copy_fd_compress (struct tracecmd_output *handle,int fd,unsigned long long max,unsigned long long *write_size);
lib/trace-cmd/trace-input.c +161 -30
322 lines not on this page · raw message
lib/trace-cmd/trace-output.c +5 -0
@@ -2503,6 +2503,11 @@ out_free:return NULL ; } +__hidden void out_set_file_state(struct tracecmd_output *handle, int new_state) +{ + handle->file_state = new_state; +} + __hidden bool check_out_state(struct tracecmd_output *handle, int new_state) {return check_file_state (handle->file_version, handle->file_state, new_state);
Signature · 1 line
2.31.1
PATCH 76/87 tarce-cmd library: Copy CPU count between trace files
In reply to Tzvetomir Stoyanov (VMware)The tracecmd_copy_headers() API should be able to copy CPU count also, as it is part of the headers.
--- lib/trace-cmd/trace-input.c | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
lib/trace-cmd/trace-input.c +40 -0
@@ -4700,6 +4700,33 @@ error:return -1 ; } +static int copy_cpu_count (struct tracecmd_input *in_handle,struct tracecmd_output *out_handle) +{ +unsigned int cpus; + +if (!check_in_state (in_handle,TRACECMD_FILE_CPU_COUNT ) || + !check_out_state (out_handle,TRACECMD_FILE_CPU_COUNT )) +return -1 ; + +if (in_handle->file_version <7 ) { +if (read4 (in_handle, &cpus)) +return -1 ; + }else { + cpus = in_handle->max_cpu; + } + +if (tracecmd_get_out_file_version (out_handle) <7 ) { + cpus =tep_read_number (in_handle->pevent, &cpus,4 ); +if (do_write_check (out_handle, &cpus,4 )) +return -1 ; + } + + in_handle->file_state =TRACECMD_FILE_CPU_COUNT ; +out_set_file_state (out_handle, in_handle->file_state); + +return 0 ; +} +/** * tracecmd_copy_headers - Copy headers from a tracecmd_input handle to a file descriptor * @in_handle: input handle for the trace.dat file to copy from.
@@ -4798,6 +4825,19 @@ int tracecmd_copy_headers(struct tracecmd_input *in_handle,return 0 ; ret =copy_command_lines (in_handle, out_handle); +if (ret <0 ) + goto out; + +/* fallthrough */ +case TRACECMD_FILE_CPU_COUNT : +if (end_state <= in_handle->file_state) +return 0 ; + + ret =copy_cpu_count (in_handle, out_handle); +if (ret <0 ) + goto out; + +/* fallthrough */ default :break ; }
Signature · 1 line
2.31.1
PATCH 77/87 tarce-cmd library: New API to copy buffer description between trace files
In reply to Tzvetomir Stoyanov (VMware)A new library API is introduced, to copy buffers description between trace files:
tracecmd_copy_buffer_descr()
--- lib/trace-cmd/include/private/trace-cmd-private.h | 2 ++ lib/trace-cmd/trace-input.c | 13 +++++++++++++ 2 files changed, 15 insertions(+)
lib/trace-cmd/include/private/trace-cmd-private.h +2 -0
@@ -183,6 +183,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);
lib/trace-cmd/trace-input.c +13 -0
@@ -4846,6 +4846,19 @@ int tracecmd_copy_headers(struct tracecmd_input *in_handle,return ret <0 ?-1 :0 ; } +int tracecmd_copy_buffer_descr (struct tracecmd_input *in_handle, +struct tracecmd_output *out_handle) +{ +int i; + +if (tracecmd_get_out_file_version (out_handle) >=7 ) +return 0 ; + +for (i =0 ; i < in_handle->nr_buffers; i++) +tracecmd_add_buffer_info (out_handle, in_handle->buffers[i].name,0 ); +return tracecmd_write_buffer_info (out_handle); +} +/** * tracecmd_record_at_buffer_start - return true if record is first on subbuffer * @handle: input handle for the trace.dat file
Signature · 1 line
2.31.1
PATCH 78/87 tarce-cmd library: New API to copy options between trace files
In reply to Tzvetomir Stoyanov (VMware)A new library API is introduced, to copy options between trace files:
tracecmd_copy_options()
--- .../include/private/trace-cmd-private.h | 3 + lib/trace-cmd/include/trace-cmd-local.h | 2 + lib/trace-cmd/trace-input.c | 140 ++++++++++++++++++ lib/trace-cmd/trace-output.c | 28 ++++ 4 files changed, 173 insertions(+)
lib/trace-cmd/include/private/trace-cmd-private.h +3 -0
@@ -185,6 +185,8 @@ int tracecmd_copy_headers(struct tracecmd_input *in_handle, enum tracecmd_file_states end_state);int tracecmd_copy_buffer_descr (struct tracecmd_input *in_handle,struct tracecmd_output *out_handle); +int tracecmd_copy_options (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);
@@ -331,6 +333,7 @@ int tracecmd_append_buffer_cpu_data(struct tracecmd_output *handle, const char *name, int cpus, char * const *cpu_data_files);struct tracecmd_output *tracecmd_get_output_handle_fd (int fd);unsigned long tracecmd_get_out_file_version (struct tracecmd_output *handle); +unsigned long long tracecmd_get_out_file_offset (struct tracecmd_output *handle);/* --- Reading the Fly Recorder Trace --- */
lib/trace-cmd/include/trace-cmd-local.h +2 -0
@@ -52,6 +52,8 @@ void in_uncompress_reset(struct tracecmd_input *handle);int in_uncompress_block (struct tracecmd_input *handle);void out_set_file_state (struct tracecmd_output *handle,int new_state); +int out_save_options_offset (struct tracecmd_output *handle, +unsigned long long start);unsigned long long out_copy_fd_compress (struct tracecmd_output *handle,int fd,unsigned long long max,unsigned long long *write_size);
lib/trace-cmd/trace-input.c +140 -0
146 lines not on this page · raw message
lib/trace-cmd/trace-output.c +28 -0
@@ -2513,6 +2513,30 @@ __hidden bool check_out_state(struct tracecmd_output *handle, int new_state)return check_file_state (handle->file_version, handle->file_state, new_state); } +__hidden int out_save_options_offset(struct tracecmd_output *handle, unsigned long long start) +{ +unsigned long long new, en8; + +if (handle->file_version <7 ) { + handle->options_start = start; + }else { +/* Append to the previous options section, if any */ +if (!handle->options_start) +return -1 ; + new =do_lseek (handle,0 ,SEEK_CUR ); +if (do_lseek (handle, handle->options_start,SEEK_SET ) == (off64_t)-1 ) +return -1 ; + + en8 =convert_endian_8 (handle, start); +if (do_write_check (handle, &en8,8 )) +return -1 ; + handle->options_start = new; +if (do_lseek (handle, new,SEEK_SET ) == (off64_t)-1 ) +return -1 ; + } +return 0 ; +} +/** * tracecmd_get_out_file_version - return the trace.dat file version * @handle: output handle for the trace.dat file
@@ -2522,3 +2546,7 @@ unsigned long tracecmd_get_out_file_version(struct tracecmd_output *handle)return handle->file_version; } +unsigned long long tracecmd_get_out_file_offset (struct tracecmd_output *handle) +{ +return do_lseek (handle,0 ,SEEK_CUR ); +}
Signature · 1 line
2.31.1
PATCH 79/87 tarce-cmd library: New API to copy trace data between trace files
In reply to Tzvetomir Stoyanov (VMware)A new library API is introduced, to copy trace data between trace files:
tracecmd_copy_trace_data()
--- .../include/private/trace-cmd-private.h | 2 + lib/trace-cmd/include/trace-cmd-local.h | 6 + lib/trace-cmd/trace-input.c | 161 ++++++++++++++++++ lib/trace-cmd/trace-output.c | 38 +++++ 4 files changed, 207 insertions(+)
lib/trace-cmd/include/private/trace-cmd-private.h +2 -0
@@ -187,6 +187,8 @@ int tracecmd_copy_buffer_descr(struct tracecmd_input *in_handle, struct tracecmd_output *out_handle);int tracecmd_copy_options (struct tracecmd_input *in_handle,struct tracecmd_output *out_handle); +int tracecmd_copy_trace_data (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);
lib/trace-cmd/include/trace-cmd-local.h +6 -0
@@ -64,6 +64,11 @@ int out_update_section_header(struct tracecmd_output *handle, unsigned long longlong long do_write_check (struct tracecmd_output *handle,const void *data,long long size); +struct tracecmd_option * +out_add_buffer_option_v7 (struct tracecmd_output *handle,const char *name, +unsigned short id,unsigned long long data_offset, +int cpus,struct data_file_write *cpu_data); +struct cpu_data_source {int fd;int size;
@@ -72,6 +77,7 @@ struct cpu_data_source {int out_write_cpu_data (struct tracecmd_output *handle,int cpus,struct cpu_data_source *data,const char *buff_name); +int out_write_emty_cpu_data (struct tracecmd_output *handle,int cpus);off64_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off_t offset,int whence);unsigned long long get_last_option_offset (struct tracecmd_input *handle);
lib/trace-cmd/trace-input.c +161 -0
167 lines not on this page · raw message
lib/trace-cmd/trace-output.c +38 -0
@@ -2166,6 +2166,44 @@ static int update_buffer_cpu_offset_v6(struct tracecmd_output *handle,return 0 ; } +__hidden int out_write_emty_cpu_data(struct tracecmd_output *handle, int cpus) +{ +unsigned long long zero =0 ; +char *clock; +int ret; +int i; + +if (handle->file_version >=7 ) +return 0 ; + + ret = handle->file_state ==TRACECMD_FILE_CPU_FLYRECORD ?0 : +check_file_state (handle->file_version, + handle->file_state, +TRACECMD_FILE_CPU_FLYRECORD ); +if (ret <0 ) { +tracecmd_warning ("Cannot write trace data into the file, unexpected state 0x%X" , + handle->file_state); +return ret; + } + +if (do_write_check (handle,"flyrecord" ,10 )) +return -1 ; + +for (i =0 ; i < cpus; i++) { +/* Write 0 for trace data offset and size */ +if (do_write_check (handle, &zero,8 )) +return -1 ; +if (do_write_check (handle, &zero,8 )) +return -1 ; + } + clock =get_clock (handle); +if (clock &&save_clock (handle, clock)) +return -1 ; + handle->file_state =TRACECMD_FILE_CPU_FLYRECORD ; +return 0 ; +} + + __hidden int out_write_cpu_data(struct tracecmd_output *handle,int cpus,struct cpu_data_source *data,const char *buff_name) {
Signature · 1 line
2.31.1
PATCH 80/87 trace-cmd library: Extend tracecmd_copy() API
In reply to Tzvetomir Stoyanov (VMware)The tracecmd_copy() API is used to copy data between trace files. Extended it to support copying data bwteen files from different versions. Added also functionality to copy all sections between the files.
--- .../include/private/trace-cmd-private.h | 5 ++- lib/trace-cmd/trace-output.c | 38 +++++++++++++++---- tracecmd/trace-restore.c | 2 +- tracecmd/trace-split.c | 2 +- 4 files changed, 36 insertions(+), 11 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +3 -2
@@ -324,8 +324,9 @@ 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 file_version, +const char *compression);int tracecmd_write_cpu_data (struct tracecmd_output *handle,int cpus,char *const *cpu_data_files,const char *buff_name);
lib/trace-cmd/trace-output.c +31 -7
@@ -2507,14 +2507,22 @@ struct tracecmd_output *tracecmd_create_init_file(const char *output_file)* 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 +* @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) +struct tracecmd_output *tracecmd_copy (struct tracecmd_input *ihandle,const char *file, +enum tracecmd_file_states state,int file_version, +const char *compression) { +enum tracecmd_file_states fstate;struct tracecmd_output *handle;int fd;
@@ -2527,17 +2535,33 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, goto out_free;if (tracecmd_output_set_from_input (handle, ihandle)) goto out_free; +if (file_version >=FILE_VERSION_MIN ) +tracecmd_output_set_version (handle, file_version); +if (compression &&tracecmd_output_set_compression (handle, compression)) + goto out_free;tracecmd_output_write_init (handle); -if (tracecmd_copy_headers (ihandle, handle,0 ,0 ) <0 ) + fstate = state >TRACECMD_FILE_CPU_COUNT ?TRACECMD_FILE_CPU_COUNT : state; +if (tracecmd_copy_headers (ihandle, handle,0 , fstate) <0 ) goto out_free; - - handle->file_state =tracecmd_get_file_state (ihandle); - +if (tracecmd_copy_buffer_descr (ihandle, handle) <0 ) + goto out_free; +if (state >=TRACECMD_FILE_OPTIONS && +tracecmd_copy_options (ihandle, handle) <0 ) + goto out_free; +if (state >=TRACECMD_FILE_CPU_LATENCY && +tracecmd_copy_trace_data (ihandle, handle) <0 ) + goto out_free; +if (handle->file_version >=7 ) +tracecmd_write_options (handle);/* The file is all ready to have cpu data attached */ return handle; out_free: -tracecmd_output_close (handle); +if (handle) +tracecmd_output_close (handle); +else +close (fd); +unlink (file);return NULL ; }
tracecmd/trace-restore.c +1 -1
@@ -153,7 +153,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 ,0 ,NULL );tracecmd_close (ihandle); }else handle =tracecmd_create_init_file (output);
tracecmd/trace-split.c +1 -1
@@ -348,7 +348,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 ,0 ,NULL ); cpus =tracecmd_cpus (handle); cpu_data =malloc (sizeof (*cpu_data) * cpus);
Signature · 1 line
2.31.1
PATCH 81/87 trace-cmd library: Set correct CPU to the record, retrieved with tracecmd_peek_data
In reply to Tzvetomir Stoyanov (VMware)Trace files version 7 stores only CPUs with trace data in the file, empty CPUs are ommited. Fixed tracecmd_peek_data() to handle that case, set the CPU in the record - do not use CPU indfex, but CPU id.
--- lib/trace-cmd/trace-input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/trace-cmd/trace-input.c +1 -1
@@ -2404,7 +2404,7 @@ read_again: record->ts = handle->cpu_data[cpu].timestamp; record->size =kbuffer_event_size (kbuf); - record->cpu = cpu; + record->cpu = handle->cpu_data[cpu].cpu; record->data = data; record->offset = handle->cpu_data[cpu].offset + index; record->missed_events =kbuffer_missed_events (kbuf);
Signature · 1 line
2.31.1
PATCH 82/87 trace-cmd: Add new subcommand "convert"
In reply to Tzvetomir Stoyanov (VMware)There is a need to convert trace files between different versions. A new "trace-cmd convert" subcommand is introduced, which reads and input trace file and copies to an output trace file. Both files can be from different versions.
trace-cmd convert -i <input file> -o <output file> --file-version <ver>
--compression <compression>
--- tracecmd/Makefile | 1 + tracecmd/include/trace-local.h | 2 + tracecmd/trace-cmd.c | 1 + tracecmd/trace-convert.c | 106 +++++++++++++++++++++++++++++++++ tracecmd/trace-usage.c | 13 ++++ 5 files changed, 123 insertions(+) create mode 100644 tracecmd/trace-convert.c
tracecmd/Makefile +1 -0
@@ -36,6 +36,7 @@ TRACE_CMD_OBJS += trace-usage.o TRACE_CMD_OBJS += trace-dump.o TRACE_CMD_OBJS += trace-clear.o TRACE_CMD_OBJS += trace-vm.o +TRACE_CMD_OBJS += trace-convert.o ifeq ($(VSOCK_DEFINED), 1) TRACE_CMD_OBJS += trace-agent.o
tracecmd/include/trace-local.h +2 -0
@@ -110,6 +110,8 @@ void trace_usage(int argc, char **argv);void trace_dump (int argc,char **argv); +void trace_convert (int argc,char **argv); + int trace_record_agent(struct tracecmd_msg_handle *msg_handle, int cpus, int *fds, int argc, char **argv, bool use_fifos,
tracecmd/trace-cmd.c +1 -0
@@ -133,6 +133,7 @@ struct command commands[] = { {"list", trace_list}, {"help", trace_usage}, {"dump", trace_dump}, + {"convert", trace_convert}, {"-h", trace_usage}, };
tracecmd/trace-convert.c new file +106 -0
106 lines not on this page · raw message
tracecmd/trace-usage.c +13 -0
@@ -407,6 +407,19 @@ static struct usage_help usage_help[] = {" -h, --help show usage information\n" " --verbose 'level' Set the desired log level\n" }, + { +"convert" , +"convert trace file to different version" , +" %s convert [options]\n" +" -i input file, default is trace.dat\n" +" -o output file, mandatory parameter.\n" +" The output file can be specified also as last argument of the command\n" +" --file-version set the desired trace file version\n" +" --compression compress the trace output file, one of these strings can be passed:\n" +" any - auto select the best available compression algorithm\n" +" none - do not compress the trace file\n" +" name - the name of the desired compression algorithms\n" + " available algorithms can be listed with trace-cmd list -c\n" }, { NULL, NULL, NULL }
Signature · 1 line
2.31.1
PATCH 83/87 trace-cmd report: Add new parameters for version 7 trace files
In reply to Tzvetomir Stoyanov (VMware)By default, "trace-cmd report" writes in trace file version 7 and no trace file compression. A new parameters are added, which can be used to set desired verrsion and compression of the output trace file.
"trace-cmd report --file-version <version> --compression <compression>"
--- tracecmd/trace-record.c | 28 ++++++++++++++++++++++++++++ tracecmd/trace-usage.c | 7 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-)
tracecmd/trace-record.c +28 -0
@@ -5810,6 +5810,8 @@ void init_top_instance(void) }enum { + OPT_file_ver =237 , + OPT_comporession =238 , OPT_verbose =239 , OPT_tsc2nsec =240 , OPT_fork =241 ,
@@ -6249,6 +6251,8 @@ static void parse_record_options(int argc, {"tsc2nsec", no_argument, NULL, OPT_tsc2nsec}, {"poll", no_argument, NULL, OPT_poll}, {"verbose", optional_argument, NULL, OPT_verbose}, + {"compression", required_argument, NULL, OPT_comporession}, + {"file-version", required_argument, NULL, OPT_file_ver}, {NULL, 0, NULL, 0} };
@@ -6674,6 +6678,30 @@ static void parse_record_options(int argc,cmd_check_die (ctx, CMD_set, *(argv+1 ),"--poll" ); recorder_flags |=TRACECMD_RECORD_POLL ;break ; +case OPT_comporession: +cmd_check_die (ctx, CMD_start, *(argv+1 ),"--compression" ); +cmd_check_die (ctx, CMD_set, *(argv+1 ),"--compression" ); +cmd_check_die (ctx, CMD_extract, *(argv+1 ),"--compression" ); +cmd_check_die (ctx, CMD_stream, *(argv+1 ),"--compression" ); +cmd_check_die (ctx, CMD_profile, *(argv+1 ),"--compression" ); +if (strcmp (optarg,"any" ) &&strcmp (optarg,"none" ) && + !tracecmd_compress_is_supported (optarg,NULL )) +die ("Compression algorithm %s is not supported" , optarg); + ctx->compression =strdup (optarg); +break ; +case OPT_file_ver: +cmd_check_die (ctx, CMD_start, *(argv+1 ),"--file_version" ); +cmd_check_die (ctx, CMD_set, *(argv+1 ),"--file_version" ); +cmd_check_die (ctx, CMD_extract, *(argv+1 ),"--file_version" ); +cmd_check_die (ctx, CMD_stream, *(argv+1 ),"--file_version" ); +cmd_check_die (ctx, CMD_profile, *(argv+1 ),"--file_version" ); + ctx->file_version =atoi (optarg); +if (ctx->file_version <FILE_VERSION_MIN || + ctx->file_version >FILE_VERSION_MAX ) +die ("Unsupported file version %d, " +"supported versions are from %d to %d" , + ctx->file_version,FILE_VERSION_MIN ,FILE_VERSION_MAX ); +break ;case OPT_quiet:case 'q' : quiet = true;
tracecmd/trace-usage.c +6 -1
@@ -69,7 +69,12 @@ 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" " --poll don't block while reading from the trace buffer\n" -" --verbose 'level' Set the desired log level\n" +" --file-version set the desired trace file version\n" +" --compression compress the trace output file, one of these strings can be passed:\n" +" any - auto select the best available compression algorithm\n" +" none - do not compress the trace file\n" +" name - the name of the desired compression algorithms\n" +" available algorithms can be listed with trace-cmd list -c\n" }, { "set",
Signature · 1 line
2.31.1
PATCH 84/87 trace-cmd: Update bash completion
In reply to Tzvetomir Stoyanov (VMware)Added convert subcommand and its arguments to bash completion logic.
--- tracecmd/trace-cmd.bash | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
tracecmd/trace-cmd.bash +37 -0
@@ -64,6 +64,13 @@ plugin_options() COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) } +compression_param() +{ + local opts=$(trace-cmd list -c | grep -v 'Supported' | cut -d "," -f1) + opts+=" any none " + COMPREPLY=( $(compgen -W "${opts}") ) +} + __trace_cmd_list_complete() { local prev=$1
@@ -181,6 +188,9 @@ __trace_cmd_record_complete() cmd_options record "$cur" fi ;; + --compression) + compression_param + ;; *) # stream start and profile do not show all options cmd_options record "$cur"
@@ -222,6 +232,29 @@ __trace_cmd_dump_complete() esac } +__trace_cmd_convert_complete() +{ + local prev=$1 + local cur=$2 + shift 2 + local words=("$@") + + case "$prev" in + -i) + __show_files + ;; + -o) + __show_files + ;; + --compression) + compression_param + ;; + *) + cmd_options convert "$cur" + ;; + esac +} + __show_command_options() { local command="$1"
@@ -298,6 +331,10 @@ _trace_cmd_complete() __trace_cmd_dump_complete "${prev}" "${cur}" ${words[@]} return 0 ;; + convert) + __trace_cmd_convert_complete "${prev}" "${cur}" ${words[@]} + return 0 + ;; *) __show_command_options "$w" "${prev}" "${cur}" ;;
Signature · 1 line
2.31.1
PATCH 85/87 tarce-cmd: Man page for "trace-cmd convert"
In reply to Tzvetomir Stoyanov (VMware)Documented new "trace-cmnd convert" subcommand.
--- .../trace-cmd/trace-cmd-convert.1.txt | 65 +++++++++++++++++++ Documentation/trace-cmd/trace-cmd.1.txt | 4 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Documentation/trace-cmd/trace-cmd-convert.1.txt
Documentation/trace-cmd/trace-cmd-convert.1.txt new file +65 -0
@@ -0,0 +1,65 @@ +TRACE-CMD-CONVERT(1) +=================== + +NAME +---- +trace-cmd-convert - convert trace files + +SYNOPSIS +-------- +*trace-cmd convert* ['OPTIONS'] ['output-file'] + +DESCRIPTION +----------- +The trace-cmd(1) convert command converts trace file. It reads the input file and copies the data +into an output file. The output file may be in different format, depending on the command line +arguments. + +OPTIONS +------- +*-i* 'input-file':: + By default, trace-cmd convert will read the file 'trace.dat'. But the *-i* + option open up the given 'input-file' instead. + +*-o* 'out-file':: + The name of the output file, this parameter is mandatory. Note, the output file may also be + specified as the last item on the command line. + +*--file-version*:: + Desired version of the output file. Supported versions are 6 or 7. + +*--compression*:: + Compression of the trace output file, one of these strings can be passed: + + 'any' - auto select the best available compression algorithm + + 'none' - do not compress the trace file + + 'name' - the name of the desired compression algorithms. Available algorithms can be listed with + trace-cmd list -c + +*--help*:: + Print usage information. + +EXAMPLES +-------- + +# trace-cmd convert --compression any trace_compress.dat + +SEE ALSO +-------- +trace-cmd(1), trace-cmd.dat(1) + +AUTHOR +------ +*Steven Rostedt* <[email protected]>, author of *trace-cmd*. +*Tzvetomir Stoyanov* <[email protected]>, author of this man page. + +RESOURCES +--------- +https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/ + +COPYING +------- +Copyright \(C) 2021 VMware. Free use of this software is granted under +the terms of the GNU Public License (GPL).
Documentation/trace-cmd/trace-cmd.1.txt +3 -1
@@ -58,6 +58,8 @@ COMMANDS check-events - parse format strings for all trace events and return whether all formats are parseable + convert - convert trace files + OPTIONS -------
@@ -70,7 +72,7 @@ SEE ALSO -------- trace-cmd-record(1), trace-cmd-report(1), trace-cmd-hist(1), trace-cmd-start(1), trace-cmd-stop(1), trace-cmd-extract(1), trace-cmd-reset(1), -trace-cmd-restore(1), trace-cmd-stack(1), +trace-cmd-restore(1), trace-cmd-stack(1), trace-cmd-convert(1), trace-cmd-split(1), trace-cmd-list(1), trace-cmd-listen(1), trace-cmd.dat(5), trace-cmd-check-events(1) trace-cmd-stat(1)
Signature · 1 line
2.31.1
PATCH 86/87 tarce-cmd: Update record man page
In reply to Tzvetomir Stoyanov (VMware)Documented new arguments of the "trace-cmd record" subcommand:
--compression
--file-version
--- Documentation/trace-cmd/trace-cmd-record.1.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Documentation/trace-cmd/trace-cmd-record.1.txt +13 -0
@@ -377,6 +377,19 @@ OPTIONS trace-cmd record --verbose=warning +*--file-version*:: + Desired version of the output file. Supported versions are 6 or 7. + +*--compression*:: + Compression of the trace output file, one of these strings can be passed: + + 'any' - auto select the best available compression algorithm + + 'none' - do not compress the trace file + + 'name' - the name of the desired compression algorithms. Available algorithms can be listed with + trace-cmd list -c + EXAMPLES --------
Signature · 1 line
2.31.1
PATCH 87/87 trace-cmd: Document trace file version 7
In reply to Tzvetomir Stoyanov (VMware)Trace file versions 6 and 7 have a lot of differences. Added new man page describing the version 7 and renamed the existing trace-cmd.dat page for version 6 only.
---
...e-cmd.dat.5.txt => trace-cmd.dat.v6.5.txt} | 15 +-
.../trace-cmd/trace-cmd.dat.v7.5.txt | 442 ++++++++++++++++++
2 files changed, 451 insertions(+), 6 deletions(-)
rename Documentation/trace-cmd/{trace-cmd.dat.5.txt => trace-cmd.dat.v6.5.txt} (96%)
create mode 100644 Documentation/trace-cmd/trace-cmd.dat.v7.5.txtDocumentation/trace-cmd/trace-cmd.dat.v6.5.txt renamed from Documentation/trace-cmd/trace-cmd.dat.5.txt +9 -6
@@ -1,9 +1,9 @@ -TRACE-CMD.DAT(5) -================ +TRACE-CMD.DAT.v6(5) +=================== NAME ---- -trace-cmd.dat - trace-cmd file format +trace-cmd.dat.v6 - trace-cmd version 6 file format SYNOPSIS --------
@@ -30,7 +30,7 @@ INITIAL FORMAT "tracing" The next set of characters contain a null '\0' terminated string - that contains the version of the file (for example): + that contains the version of the file: "6\0"
@@ -193,10 +193,10 @@ REST OF TRACE-CMD HEADER "flyrecord\0" - If it is "options \0" then: + If it is "options \0" then follows a section with trace options. The next 2 bytes are a 16-bit word defining the current option. - If the the value is zero then there are no more options. + If the value is zero then there are no more options. Otherwise, the next 4 bytes contain a 32-bit word containing the option size. If the reader does not know how to handle the option
@@ -206,6 +206,9 @@ REST OF TRACE-CMD HEADER The next option will be directly after the previous option, and the options ends with a zero in the option type field. +TRACE DATA +---------- + The next 10 bytes after the options are one of the following: "latency \0"
Documentation/trace-cmd/trace-cmd.dat.v7.5.txt new file +442 -0
442 lines not on this page · raw message
Signature · 1 line
2.31.1