@@ -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);
@@ -135,6 +135,7 @@ enum {
TRACECMD_OPTION_TIME_SHIFT,
TRACECMD_OPTION_GUEST,
TRACECMD_OPTION_TSC2NSEC,
+ TRACECMD_OPTION_MAX,
};
enum {
@@ -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);
@@ -366,6 +366,76 @@ int tracecmd_ftrace_enable(int set)
return ret;
}
+__hidden unsigned long long
+out_write_section_header(struct tracecmd_output *handle, unsigned short header_id,
+ char *description, enum tracecmd_section_flags flags, bool option)
+{
+ tsize_t endian8;
+ tsize_t offset;
+ short endian2;
+ int size;
+
+ if (header_id >= TRACECMD_OPTION_MAX)
+ return -1;
+ if (handle->file_version < 7)
+ return 0;
+ if (!handle->compress)
+ flags &= ~TRACECMD_SEC_FL_COMPRESS;
+ offset = do_lseek(handle, 0, SEEK_CUR);
+ if (option) {
+ endian8 = convert_endian_8(handle, offset);
+ if (!tracecmd_add_option(handle, header_id, 8, &endian8))
+ return -1;
+ }
+ /* Section ID */
+ endian2 = convert_endian_2(handle, header_id);
+ if (do_write_check(handle, &endian2, 2))
+ return (off_t)-1;
+
+ /* Section description */
+ if (do_write_check(handle, description, strlen(description) + 1))
+ return (off_t)-1;
+ /* Section flags */
+ endian2 = convert_endian_2(handle, flags);
+ if (do_write_check(handle, &endian2, 2))
+ return (off_t)-1;
+
+ offset = do_lseek(handle, 0, SEEK_CUR);
+ size = 0;
+ /* Reserve for section size */
+ if (do_write_check(handle, &size, 4))
+ return (off_t)-1;
+ return offset;
+}
+
+__hidden int out_update_section_header(struct tracecmd_output *handle, unsigned long long offset)
+{
+ unsigned long long current;
+ unsigned int endian4;
+ int size;
+
+ if (handle->file_version < 7 || offset == 0)
+ return 0;
+
+ current = do_lseek(handle, 0, SEEK_CUR);
+ /* The real size is the difference between the saved offset and
+ * the current offset - 4 bytes, the reserved space for the section size.
+ */
+ size = current - offset;
+ if (size < 4)
+ return -1;
+ size -= 4;
+ if (do_lseek(handle, offset, SEEK_SET) == (off_t)-1)
+ return -1;
+
+ endian4 = convert_endian_4(handle, size);
+ if (do_write_check(handle, &endian4, 4))
+ return -1;
+ if (do_lseek(handle, current, SEEK_SET) == (off_t)-1)
+ return -1;
+ return 0;
+}
+
static int read_header_files(struct tracecmd_output *handle, bool compress)
{
tsize_t size, check_size, endian8;
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 Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- 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(+)