1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4 *
5 */
6 #ifndef _TRACE_CMD_LOCAL_H
7 #define _TRACE_CMD_LOCAL_H
8
9 #include <byteswap.h>
10 #include "trace-cmd-private.h"
11
12 #define FILE_VERSION_DEFAULT 7
13
14 /* Can be overridden */
15 void tracecmd_warning(const char *fmt, ...);
16 void tracecmd_critical(const char *fmt, ...);
17 void tracecmd_info(const char *fmt, ...);
18
19 #ifndef htonll
20 # if __BYTE_ORDER == __LITTLE_ENDIAN
21 #define htonll(x) __bswap_64(x)
22 #define ntohll(x) __bswap_64(x)
23 #else
24 #define htonll(x) (x)
25 #define ntohll(x) (x)
26 #endif
27 #endif
28
29 #ifdef HAVE_ZLIB
30 int tracecmd_zlib_init(void);
31 #endif
32
33 #ifdef HAVE_ZSTD
34 int tracecmd_zstd_init(void);
35 #else
tracecmd_zstd_init(void)36 static inline int tracecmd_zstd_init(void)
37 {
38 return 0;
39 }
40 #endif
41
42 struct data_file_write {
43 unsigned long long file_size;
44 unsigned long long write_size;
45 /* offset in the trace file, where write_size is stored */
46 unsigned long long file_write_size;
47 unsigned long long data_offset;
48 /* offset in the trace file, where data_offset is stored */
49 unsigned long long file_data_offset;
50 };
51
52 void tracecmd_compress_init(void);
53 void tracecmd_compress_free(void);
54
55 bool check_file_state(unsigned long file_version, int current_state, int new_state);
56 bool check_out_state(struct tracecmd_output *handle, int new_state);
57
58 int out_uncompress_block(struct tracecmd_output *handle);
59 int out_compression_start(struct tracecmd_output *handle, bool compress);
60 int out_compression_end(struct tracecmd_output *handle, bool compress);
61 void out_compression_reset(struct tracecmd_output *handle, bool compress);
62 bool out_check_compression(struct tracecmd_output *handle);
63
64 void out_set_file_state(struct tracecmd_output *handle, int new_state);
65 int out_save_options_offset(struct tracecmd_output *handle,
66 unsigned long long start);
67 unsigned long long out_copy_fd_compress(struct tracecmd_output *handle,
68 int fd, unsigned long long max,
69 unsigned long long *write_size, int page);
70 void in_uncompress_reset(struct tracecmd_input *handle);
71 int in_uncompress_block(struct tracecmd_input *handle);
72
73 unsigned long long
74 out_write_section_header(struct tracecmd_output *handle, unsigned short header_id,
75 char *description, int flags, bool option);
76 int out_update_section_header(struct tracecmd_output *handle, unsigned long long offset);
77
78 long long do_write_check(struct tracecmd_output *handle, const void *data, long long size);
79
80 struct tracecmd_option *
81 out_add_buffer_option(struct tracecmd_output *handle, const char *name,
82 unsigned short id, unsigned long long data_offset,
83 int cpus, struct data_file_write *cpu_data, int page_size);
84
85 struct cpu_data_source {
86 int fd;
87 int size;
88 off64_t offset;
89 };
90
91 int out_write_cpu_data(struct tracecmd_output *handle, int cpus,
92 struct cpu_data_source *data, const char *buff_name);
93 int out_write_emty_cpu_data(struct tracecmd_output *handle, int cpus);
94 off64_t msg_lseek(struct tracecmd_msg_handle *msg_handle, off64_t offset, int whence);
95 unsigned long long get_last_option_offset(struct tracecmd_input *handle);
96 unsigned int get_meta_strings_size(struct tracecmd_input *handle);
97
98 #endif /* _TRACE_CMD_LOCAL_H */
99