• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3  * Copyright (C) 2008, 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4  *
5  */
6 #ifndef _TRACE_CMD_PRIVATE_H
7 #define _TRACE_CMD_PRIVATE_H
8 
9 #include <fcntl.h> /* for iovec */
10 #include <sys/types.h>
11 #include "event-parse.h"
12 #include "trace-cmd/trace-cmd.h"
13 #include "trace-cmd-private-python.h"
14 
15 #define __packed __attribute__((packed))
16 #define __hidden __attribute__((visibility ("hidden")))
17 
18 #define TRACECMD_MAGIC { 23, 8, 68 }
19 
20 #define ARRAY_SIZE(_a) (sizeof(_a) / sizeof((_a)[0]))
21 #define __weak __attribute__((weak))
22 #define __noreturn __attribute__((noreturn))
23 
24 #define TRACECMD_ERR_MSK	((unsigned long)(-1) & ~((1UL << 14) - 1))
25 #define TRACECMD_ISERR(ptr)	((unsigned long)(ptr) > TRACECMD_ERR_MSK)
26 #define TRACECMD_ERROR(ret)	((void *)((unsigned long)(ret) | TRACECMD_ERR_MSK))
27 #define TRACECMD_PTR2ERR(ptr)	((unisgned long)(ptr) & ~TRACECMD_ERR_MSK)
28 
29 #define TSCNSEC_CLOCK	"tsc2nsec"
30 
31 struct tep_plugin_list *trace_load_plugins(struct tep_handle *tep, int flags);
32 
33 int *tracecmd_add_id(int *list, int id, int len);
34 
35 #define FILE_VERSION_MIN		6
36 #define FILE_VERSION_MAX		7
37 
38 #define FILE_VERSION_SECTIONS		7
39 #define FILE_VERSION_COMPRESSION	7
40 
41 enum {
42 	RINGBUF_TYPE_PADDING		= 29,
43 	RINGBUF_TYPE_TIME_EXTEND	= 30,
44 	RINGBUF_TYPE_TIME_STAMP		= 31,
45 };
46 
47 /* Can be overridden */
48 void tracecmd_debug(const char *fmt, ...);
49 
50 void tracecmd_record_ref(struct tep_record *record);
51 
52 void tracecmd_set_debug(bool set_debug);
53 bool tracecmd_get_debug(void);
54 
55 void tracecmd_set_notimeout(bool set_notimeout);
56 bool tracecmd_get_notimeout(void);
57 
58 bool tracecmd_is_version_supported(unsigned int version);
59 int tracecmd_default_file_version(void);
60 
61 struct tracecmd_output;
62 struct tracecmd_recorder;
63 struct hook_list;
64 
65 /* --- tracecmd plugins --- */
66 
67 enum tracecmd_context {
68 	TRACECMD_INPUT,
69 	TRACECMD_OUTPUT,
70 };
71 
72 enum tracecmd_plugin_flag {
73 	TRACECMD_DISABLE_SYS_PLUGINS	= 1,
74 	TRACECMD_DISABLE_PLUGINS	= 1 << 1,
75 };
76 
77 struct trace_plugin_context;
78 
79 struct trace_plugin_context *
80 tracecmd_plugin_context_create(enum tracecmd_context context, void *data);
81 
82 void tracecmd_plugin_set_flag(struct trace_plugin_context *context,
83 			      enum tracecmd_plugin_flag flag);
84 
85 #define TRACECMD_PLUGIN_LOADER tracecmd_plugin_loader
86 #define TRACECMD_PLUGIN_UNLOADER tracecmd_plugin_unloader
87 #define TRACECMD_PLUGIN_ALIAS tracecmd_plugin_alias
88 #define _MAKE_STR(x)	#x
89 #define MAKE_STR(x)	_MAKE_STR(x)
90 #define TRACECMD_PLUGIN_LOADER_NAME MAKE_STR(TRACECMD_PLUGIN_LOADER)
91 #define TRACECMD_PLUGIN_UNLOADER_NAME MAKE_STR(TRACECMD_PLUGIN_UNLOADER)
92 #define TRACECMD_PLUGIN_ALIAS_NAME MAKE_STR(TRACECMD_PLUGIN_ALIAS)
93 
94 typedef int (*tracecmd_plugin_load_func)(struct trace_plugin_context *trace);
95 typedef int (*tracecmd_plugin_unload_func)(struct trace_plugin_context *trace);
96 
97 struct tracecmd_input *
98 tracecmd_plugin_context_input(struct trace_plugin_context *trace_context);
99 struct tracecmd_output *
100 tracecmd_plugin_context_output(struct trace_plugin_context *trace_context);
101 
102 void tracecmd_set_quiet(struct tracecmd_output *handle, bool set_quiet);
103 bool tracecmd_get_quiet(struct tracecmd_output *handle);
104 void tracecmd_set_out_clock(struct tracecmd_output *handle, const char *clock);
105 const char *tracecmd_get_trace_clock(struct tracecmd_input *handle);
106 
107 const char *tracecmd_get_cpustats(struct tracecmd_input *handle);
108 const char *tracecmd_get_uname(struct tracecmd_input *handle);
109 const char *tracecmd_get_version(struct tracecmd_input *handle);
110 off_t tracecmd_get_cpu_file_size(struct tracecmd_input *handle, int cpu);
111 
tracecmd_host_bigendian(void)112 static inline int tracecmd_host_bigendian(void)
113 {
114 	unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
115 	unsigned int *ptr;
116 
117 	ptr = (unsigned int *)str;
118 	return *ptr == 0x01020304;
119 }
120 
121 /* --- Opening and Reading the trace.dat file --- */
122 
123 enum tracecmd_file_states {
124 	TRACECMD_FILE_ALLOCATED = 0,
125 	TRACECMD_FILE_INIT,
126 	TRACECMD_FILE_HEADERS,
127 	TRACECMD_FILE_FTRACE_EVENTS,
128 	TRACECMD_FILE_ALL_EVENTS,
129 	TRACECMD_FILE_KALLSYMS,
130 	TRACECMD_FILE_PRINTK,
131 	TRACECMD_FILE_CMD_LINES,
132 	TRACECMD_FILE_CPU_COUNT,
133 	TRACECMD_FILE_OPTIONS,
134 	TRACECMD_FILE_CPU_LATENCY,
135 	TRACECMD_FILE_CPU_FLYRECORD,
136 };
137 
138 enum {
139 	TRACECMD_OPTION_DONE,
140 	TRACECMD_OPTION_DATE,
141 	TRACECMD_OPTION_CPUSTAT,
142 	TRACECMD_OPTION_BUFFER,
143 	TRACECMD_OPTION_TRACECLOCK,
144 	TRACECMD_OPTION_UNAME,
145 	TRACECMD_OPTION_HOOK,
146 	TRACECMD_OPTION_OFFSET,
147 	TRACECMD_OPTION_CPUCOUNT,
148 	TRACECMD_OPTION_VERSION,
149 	TRACECMD_OPTION_PROCMAPS,
150 	TRACECMD_OPTION_TRACEID,
151 	TRACECMD_OPTION_TIME_SHIFT,
152 	TRACECMD_OPTION_GUEST,
153 	TRACECMD_OPTION_TSC2NSEC,
154 	TRACECMD_OPTION_STRINGS,
155 	TRACECMD_OPTION_HEADER_INFO,
156 	TRACECMD_OPTION_FTRACE_EVENTS,
157 	TRACECMD_OPTION_EVENT_FORMATS,
158 	TRACECMD_OPTION_KALLSYMS,
159 	TRACECMD_OPTION_PRINTK,
160 	TRACECMD_OPTION_CMDLINES,
161 	TRACECMD_OPTION_BUFFER_TEXT,
162 	TRACECMD_OPTION_MAX,
163 };
164 
165 enum {
166 	TRACECMD_FL_IGNORE_DATE		= (1 << 0),
167 	TRACECMD_FL_BUFFER_INSTANCE	= (1 << 1),
168 	TRACECMD_FL_IN_USECS		= (1 << 2),
169 	TRACECMD_FL_RAW_TS		= (1 << 3),
170 	TRACECMD_FL_SECTIONED		= (1 << 4),
171 	TRACECMD_FL_COMPRESSION		= (1 << 5),
172 };
173 
174 struct tracecmd_ftrace {
175 	struct tracecmd_input		*handle;
176 	struct tep_event *fgraph_ret_event;
177 	int fgraph_ret_id;
178 	int long_size;
179 };
180 
181 struct tracecmd_proc_addr_map {
182 	size_t			start;
183 	size_t			end;
184 	char			*lib_name;
185 };
186 
187 typedef void (*tracecmd_show_data_func)(struct tracecmd_input *handle,
188 					struct tep_record *record);
189 typedef void (*tracecmd_handle_init_func)(struct tracecmd_input *handle,
190 					  struct hook_list *hook, int global);
191 
192 struct tracecmd_input *tracecmd_alloc(const char *file, int flags);
193 struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags);
194 void tracecmd_ref(struct tracecmd_input *handle);
195 int tracecmd_read_headers(struct tracecmd_input *handle,
196 			  enum tracecmd_file_states state);
197 int tracecmd_get_parsing_failures(struct tracecmd_input *handle);
198 int tracecmd_page_size(struct tracecmd_input *handle);
199 int tracecmd_copy_headers(struct tracecmd_input *in_handle,
200 			  struct tracecmd_output *out_handle,
201 			  enum tracecmd_file_states start_state,
202 			  enum tracecmd_file_states end_state);
203 int tracecmd_copy_buffer_descr(struct tracecmd_input *in_handle,
204 			       struct tracecmd_output *out_handle);
205 int tracecmd_copy_options(struct tracecmd_input *in_handle,
206 			  struct tracecmd_output *out_handle);
207 int tracecmd_copy_trace_data(struct tracecmd_input *in_handle,
208 			     struct tracecmd_output *out_handle);
209 void tracecmd_set_flag(struct tracecmd_input *handle, int flag);
210 void tracecmd_clear_flag(struct tracecmd_input *handle, int flag);
211 unsigned long tracecmd_get_flags(struct tracecmd_input *handle);
212 enum tracecmd_file_states tracecmd_get_file_state(struct tracecmd_input *handle);
213 int tracecmd_enable_tsync(struct tracecmd_input *handle, bool enable);
214 
215 void tracecmd_parse_trace_clock(struct tracecmd_input *handle, char *file, int size);
216 
217 int tracecmd_make_pipe(struct tracecmd_input *handle, int cpu, int fd, int cpus);
218 
219 int tracecmd_is_buffer_instance(struct tracecmd_input *handle);
220 
221 void tracecmd_set_ts_offset(struct tracecmd_input *handle, long long offset);
222 void tracecmd_set_ts2secs(struct tracecmd_input *handle, unsigned long long hz);
223 
224 void tracecmd_print_events(struct tracecmd_input *handle, const char *regex);
225 
226 struct hook_list *tracecmd_hooks(struct tracecmd_input *handle);
227 
228 void tracecmd_print_stats(struct tracecmd_input *handle);
229 void tracecmd_print_uname(struct tracecmd_input *handle);
230 void tracecmd_print_version(struct tracecmd_input *handle);
231 
232 int tracecmd_latency_data_read(struct tracecmd_input *handle, char **buf, size_t *size);
233 
234 struct tep_record *
235 tracecmd_read_prev(struct tracecmd_input *handle, struct tep_record *record);
236 
237 struct tep_record *
238 tracecmd_peek_next_data(struct tracecmd_input *handle, int *rec_cpu);
239 
240 struct tep_record *
241 tracecmd_translate_data(struct tracecmd_input *handle,
242 			void *ptr, int size);
243 struct tep_record *
244 tracecmd_read_cpu_last(struct tracecmd_input *handle, int cpu);
245 int tracecmd_refresh_record(struct tracecmd_input *handle,
246 			    struct tep_record *record);
247 
248 int tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle,
249 				  int cpu, unsigned long long ts);
250 void
251 tracecmd_set_all_cpus_to_timestamp(struct tracecmd_input *handle,
252 				   unsigned long long time);
253 
254 int tracecmd_set_cursor(struct tracecmd_input *handle,
255 			int cpu, size_t offset);
256 unsigned long long
257 tracecmd_get_cursor(struct tracecmd_input *handle, int cpu);
258 
259 unsigned long tracecmd_get_in_file_version(struct tracecmd_input *handle);
260 size_t tracecmd_get_options_offset(struct tracecmd_input *handle);
261 int tracecmd_get_file_compress_proto(struct tracecmd_input *handle,
262 				     const char **name, const char **version);
263 
264 int tracecmd_ftrace_overrides(struct tracecmd_input *handle, struct tracecmd_ftrace *finfo);
265 bool tracecmd_get_use_trace_clock(struct tracecmd_input *handle);
266 tracecmd_show_data_func
267 tracecmd_get_show_data_func(struct tracecmd_input *handle);
268 void tracecmd_set_show_data_func(struct tracecmd_input *handle,
269 				 tracecmd_show_data_func func);
270 
271 int tracecmd_record_at_buffer_start(struct tracecmd_input *handle, struct tep_record *record);
272 unsigned long long tracecmd_page_ts(struct tracecmd_input *handle,
273 				    struct tep_record *record);
274 unsigned int tracecmd_record_ts_delta(struct tracecmd_input *handle,
275 				      struct tep_record *record);
276 
277 struct tracecmd_proc_addr_map *
278 tracecmd_search_task_map(struct tracecmd_input *handle,
279 			 int pid, unsigned long long addr);
280 #ifndef SWIG
281 /* hack for function graph work around */
282 extern __thread struct tracecmd_input *tracecmd_curr_thread_handle;
283 #endif
284 
285 
286 /* --- Creating and Writing the trace.dat file --- */
287 
288 struct tracecmd_event_list {
289 	struct tracecmd_event_list	*next;
290 	const char			*glob;
291 };
292 
293 struct tracecmd_option;
294 struct tracecmd_msg_handle;
295 
296 int tracecmd_output_set_msg(struct tracecmd_output *handle,
297 			    struct tracecmd_msg_handle *msg_handle);
298 int tracecmd_output_set_trace_dir(struct tracecmd_output *handle, const char *tracing_dir);
299 int tracecmd_output_set_kallsyms(struct tracecmd_output *handle, const char *kallsyms);
300 int tracecmd_output_set_from_input(struct tracecmd_output *handle, struct tracecmd_input *ihandle);
301 int tracecmd_output_set_version(struct tracecmd_output *handle, int file_version);
302 int tracecmd_output_set_compression(struct tracecmd_output *handle, const char *compression);
303 int tracecmd_output_write_headers(struct tracecmd_output *handle,
304 				  struct tracecmd_event_list *list);
305 
306 struct tracecmd_output *tracecmd_output_create(const char *output_file);
307 struct tracecmd_output *tracecmd_output_create_fd(int fd);
308 struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus,
309 						     int file_version, const char *compression);
310 
311 struct tracecmd_option *tracecmd_add_option(struct tracecmd_output *handle,
312 					    unsigned short id, int size,
313 					    const void *data);
314 struct tracecmd_option *
315 tracecmd_add_option_v(struct tracecmd_output *handle,
316 		      unsigned short id, const struct iovec *vector, int count);
317 
318 int tracecmd_add_buffer_info(struct tracecmd_output *handle, const char *name, int cpus);
319 int tracecmd_write_buffer_info(struct tracecmd_output *handle);
320 
321 int tracecmd_write_cpus(struct tracecmd_output *handle, int cpus);
322 int tracecmd_write_cmdlines(struct tracecmd_output *handle);
323 int tracecmd_prepare_options(struct tracecmd_output *handle, off_t offset, int whence);
324 int tracecmd_write_options(struct tracecmd_output *handle);
325 int tracecmd_write_meta_strings(struct tracecmd_output *handle);
326 int tracecmd_append_options(struct tracecmd_output *handle);
327 void tracecmd_output_close(struct tracecmd_output *handle);
328 void tracecmd_output_flush(struct tracecmd_output *handle);
329 void tracecmd_output_free(struct tracecmd_output *handle);
330 struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char *file,
331 				      enum tracecmd_file_states state, int file_version,
332 				      const char *compression);
333 
334 int tracecmd_write_cpu_data(struct tracecmd_output *handle,
335 			    int cpus, char * const *cpu_data_files, const char *buff_name);
336 int tracecmd_append_cpu_data(struct tracecmd_output *handle,
337 			     int cpus, char * const *cpu_data_files);
338 int tracecmd_append_buffer_cpu_data(struct tracecmd_output *handle,
339 				    const char *name, int cpus, char * const *cpu_data_files);
340 struct tracecmd_output *tracecmd_get_output_handle_fd(int fd);
341 unsigned long tracecmd_get_out_file_version(struct tracecmd_output *handle);
342 size_t tracecmd_get_out_file_offset(struct tracecmd_output *handle);
343 
344 /* --- Reading the Fly Recorder Trace --- */
345 
346 enum {
347 	TRACECMD_RECORD_NOSPLICE	= (1 << 0),	/* Use read instead of splice */
348 	TRACECMD_RECORD_SNAPSHOT	= (1 << 1),	/* Extract from snapshot */
349 	TRACECMD_RECORD_BLOCK_SPLICE	= (1 << 2),	/* Block on splice write */
350 	TRACECMD_RECORD_NOBRASS		= (1 << 3),	/* Splice directly without a brass pipe */
351 	TRACECMD_RECORD_POLL		= (1 << 4),	/* Use O_NONBLOCK, poll trace buffers */
352 };
353 
354 void tracecmd_free_recorder(struct tracecmd_recorder *recorder);
355 struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu, unsigned flags);
356 struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu, unsigned flags);
357 struct tracecmd_recorder *tracecmd_create_recorder_virt(const char *file, int cpu, unsigned flags, int trace_fd, int maxkb);
358 struct tracecmd_recorder *tracecmd_create_recorder_maxkb(const char *file, int cpu, unsigned flags, int maxkb);
359 struct tracecmd_recorder *tracecmd_create_buffer_recorder_fd(int fd, int cpu, unsigned flags, struct tracefs_instance *instance);
360 struct tracecmd_recorder *tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, struct tracefs_instance *instance);
361 struct tracecmd_recorder *tracecmd_create_buffer_recorder_maxkb(const char *file, int cpu, unsigned flags, struct tracefs_instance *instance, int maxkb);
362 
363 int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep);
364 int tracecmd_stop_recording(struct tracecmd_recorder *recorder);
365 long tracecmd_flush_recording(struct tracecmd_recorder *recorder, bool finish);
366 
367 enum tracecmd_msg_flags {
368 	TRACECMD_MSG_FL_USE_TCP		= 1 << 0,
369 	TRACECMD_MSG_FL_USE_VSOCK	= 1 << 1,
370 	TRACECMD_MSG_FL_PROXY		= 1 << 2,
371 };
372 
373 #ifdef __ANDROID__
374 #define MSG_CACHE_FILE "/data/local/tmp/trace_msg_cacheXXXXXX"
375 #else	/* !__ANDROID__ */
376 #define MSG_CACHE_FILE "/tmp/trace_msg_cacheXXXXXX"
377 #endif	/* __ANDROID__ */
378 
379 /* for both client and server */
380 struct tracecmd_msg_handle {
381 	int			fd;
382 	short			cpu_count;
383 	short			version;	/* Current protocol version */
384 	unsigned long		flags;
385 	off_t			cache_start_offset;
386 	bool			done;
387 	bool			cache;
388 	int			cfd;
389 #ifndef HAVE_MEMFD_CREATE
390 	char			cfile[sizeof(MSG_CACHE_FILE)];
391 #endif
392 };
393 
394 struct tracecmd_tsync_protos {
395 	char **names;
396 };
397 
398 struct tracecmd_msg_handle *
399 tracecmd_msg_handle_alloc(int fd, unsigned long flags);
400 int tracecmd_msg_handle_cache(struct tracecmd_msg_handle *msg_handle);
401 
402 /* Closes the socket and frees the handle */
403 void tracecmd_msg_handle_close(struct tracecmd_msg_handle *msg_handle);
404 
405 /* for clients */
406 int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle,
407 				unsigned int **client_ports);
408 int tracecmd_msg_data_send(struct tracecmd_msg_handle *msg_handle,
409 			       const char *buf, int size);
410 int tracecmd_msg_finish_sending_data(struct tracecmd_msg_handle *msg_handle);
411 int tracecmd_msg_flush_data(struct tracecmd_msg_handle *msg_handle);
412 int tracecmd_msg_send_close_msg(struct tracecmd_msg_handle *msg_handle);
413 int tracecmd_msg_send_close_resp_msg(struct tracecmd_msg_handle *msg_handle);
414 int tracecmd_msg_wait_close(struct tracecmd_msg_handle *msg_handle);
415 int tracecmd_msg_wait_close_resp(struct tracecmd_msg_handle *msg_handle);
416 int tracecmd_msg_cont(struct tracecmd_msg_handle *msg_handle);
417 int tracecmd_msg_wait(struct tracecmd_msg_handle *msg_handle);
418 
419 /* for server */
420 int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle);
421 int tracecmd_msg_send_port_array(struct tracecmd_msg_handle *msg_handle,
422 				 unsigned *ports);
423 int tracecmd_msg_read_data(struct tracecmd_msg_handle *msg_handle, int ofd);
424 int tracecmd_msg_collect_data(struct tracecmd_msg_handle *msg_handle, int ofd);
425 bool tracecmd_msg_done(struct tracecmd_msg_handle *msg_handle);
426 void tracecmd_msg_set_done(struct tracecmd_msg_handle *msg_handle);
427 int tracecmd_msg_read_options(struct tracecmd_msg_handle *msg_handle,
428 			      struct tracecmd_output *handle);
429 int tracecmd_msg_send_options(struct tracecmd_msg_handle *msg_handle,
430 			      struct tracecmd_output *handle);
431 
432 int tracecmd_msg_send_trace_req(struct tracecmd_msg_handle *msg_handle,
433 				int argc, char **argv, bool use_fifos,
434 				unsigned long long trace_id,
435 				struct tracecmd_tsync_protos *protos);
436 int tracecmd_msg_send_trace_proxy(struct tracecmd_msg_handle *msg_handle,
437 				  int argc, char **argv, bool use_fifos,
438 				  unsigned long long trace_id,
439 				  struct tracecmd_tsync_protos *protos,
440 				  unsigned int nr_cpus,
441 				  unsigned int siblings);
442 int tracecmd_msg_recv_trace_req(struct tracecmd_msg_handle *msg_handle,
443 				int *argc, char ***argv, bool *use_fifos,
444 				unsigned long long *trace_id,
445 				struct tracecmd_tsync_protos **protos);
446 int tracecmd_msg_recv_trace_proxy(struct tracecmd_msg_handle *msg_handle,
447 				  int *argc, char ***argv, bool *use_fifos,
448 				  unsigned long long *trace_id,
449 				  struct tracecmd_tsync_protos **protos,
450 				  unsigned int *cpus, unsigned int *siblings);
451 
452 int tracecmd_msg_send_trace_resp(struct tracecmd_msg_handle *msg_handle,
453 				 int nr_cpus, int page_size,
454 				 unsigned int *ports, bool use_fifos,
455 				 unsigned long long trace_id,
456 				 const char *tsync_proto, unsigned int tsync_port);
457 int tracecmd_msg_recv_trace_resp(struct tracecmd_msg_handle *msg_handle,
458 				 int *nr_cpus, int *page_size,
459 				 unsigned int **ports, bool *use_fifos,
460 				 unsigned long long *trace_id,
461 				 char **tsync_proto,
462 				 unsigned int *tsync_port);
463 
464 int tracecmd_msg_send_time_sync(struct tracecmd_msg_handle *msg_handle,
465 				char *sync_protocol, unsigned int sync_msg_id,
466 				unsigned int payload_size, char *payload);
467 int tracecmd_msg_recv_time_sync(struct tracecmd_msg_handle *msg_handle,
468 				char *sync_protocol,
469 				unsigned int *sync_msg_id,
470 				unsigned int *payload_size, char **payload);
471 
472 enum tracecmd_clocks {
473 	TRACECMD_CLOCK_UNKNOWN	= 0,
474 	TRACECMD_CLOCK_LOCAL	= 1,
475 	TRACECMD_CLOCK_GLOBAL	= 1 << 1,
476 	TRACECMD_CLOCK_COUNTER	= 1 << 2,
477 	TRACECMD_CLOCK_UPTIME	= 1 << 3,
478 	TRACECMD_CLOCK_PERF	= 1 << 4,
479 	TRACECMD_CLOCK_MONO	= 1 << 5,
480 	TRACECMD_CLOCK_MONO_RAW	= 1 << 6,
481 	TRACECMD_CLOCK_BOOT	= 1 << 7,
482 	TRACECMD_CLOCK_X86_TSC	= 1 << 8
483 };
484 
485 enum tracecmd_clocks tracecmd_clock_str2id(const char *clock);
486 const char *tracecmd_clock_id2str(enum tracecmd_clocks clock);
487 
488 /* --- Timestamp synchronization --- */
489 
490 struct tracecmd_time_sync;
491 #define TRACECMD_TSYNC_PNAME_LENGTH	16
492 #define TRACECMD_TSYNC_PROTO_NONE	"none"
493 
494 enum{
495 	TRACECMD_TIME_SYNC_CMD_PROBE	= 1,
496 	TRACECMD_TIME_SYNC_CMD_STOP	= 2,
497 };
498 
499 enum tracecmd_time_sync_role {
500 	TRACECMD_TIME_SYNC_ROLE_HOST	= (1 << 0),
501 	TRACECMD_TIME_SYNC_ROLE_GUEST	= (1 << 1),
502 	TRACECMD_TIME_SYNC_ROLE_CLIENT	= (1 << 2),
503 	TRACECMD_TIME_SYNC_ROLE_SERVER	= (1 << 3),
504 };
505 
506 /* Timestamp synchronization flags */
507 #define TRACECMD_TSYNC_FLAG_INTERPOLATE	0x1
508 
509 void tracecmd_tsync_init(void);
510 int tracecmd_tsync_proto_getall(struct tracecmd_tsync_protos **protos, const char *clock, int role);
511 bool tsync_proto_is_supported(const char *proto_name);
512 struct tracecmd_time_sync *
513 tracecmd_tsync_with_host(int fd, const char *proto, const char *clock,
514 			 int remote_id, int local_id);
515 int tracecmd_tsync_with_host_stop(struct tracecmd_time_sync *tsync);
516 struct tracecmd_time_sync *
517 tracecmd_tsync_with_guest(unsigned long long trace_id, int loop_interval,
518 			  unsigned int fd, int guest_pid,
519 			  int guest_cpus, const char *proto_name, const char *clock);
520 int tracecmd_tsync_with_guest_stop(struct tracecmd_time_sync *tsync);
521 int tracecmd_tsync_get_offsets(struct tracecmd_time_sync *tsync, int cpu,
522 			       int *count, long long **ts,
523 			       long long **offsets, long long **scalings, long long **frac);
524 const char *tracecmd_tsync_get_proto(const struct tracecmd_tsync_protos *protos,
525 			 const char *clock, enum tracecmd_time_sync_role role);
526 void tracecmd_tsync_free(struct tracecmd_time_sync *tsync);
527 int tracecmd_write_guest_time_shift(struct tracecmd_output *handle,
528 				    struct tracecmd_time_sync *tsync);
529 
530 /* --- Compression --- */
531 struct tracecmd_compress_chunk {
532 	unsigned int		size;
533 	unsigned int		zsize;
534 	off_t			zoffset;
535 	off_t			offset;
536 };
537 struct tracecmd_compression;
538 struct tracecmd_compression_proto {
539 	int weight;
540 	const char *name;
541 	const char *version;
542 	int (*compress)(void *ctx, const void *in, int in_bytes, void *out, int out_bytes);
543 	int (*uncompress)(void *ctx, const void *in, int in_bytes, void *out, int out_bytes);
544 	unsigned int (*compress_size)(void *ctx, unsigned int bytes);
545 	bool (*is_supported)(const char *name, const char *version);
546 	void *(*new_context)(void);
547 	void (*free_context)(void *ctx);
548 };
549 
550 struct tracecmd_compression *tracecmd_compress_alloc(const char *name, const char *version,
551 						     int fd, struct tep_handle *tep,
552 						     struct tracecmd_msg_handle *msg_handle);
553 void tracecmd_compress_destroy(struct tracecmd_compression *handle);
554 int tracecmd_compress_block(struct tracecmd_compression *handle);
555 int tracecmd_uncompress_block(struct tracecmd_compression *handle);
556 void tracecmd_compress_reset(struct tracecmd_compression *handle);
557 ssize_t tracecmd_compress_buffer_read(struct tracecmd_compression *handle, char *dst, size_t len);
558 ssize_t tracecmd_compress_pread(struct tracecmd_compression *handle, char *dst, size_t len, off_t offset);
559 int tracecmd_compress_buffer_write(struct tracecmd_compression *handle,
560 				   const void *data, size_t size);
561 off_t tracecmd_compress_lseek(struct tracecmd_compression *handle, off_t offset, int whence);
562 int tracecmd_compress_proto_get_name(struct tracecmd_compression *compress,
563 				     const char **name, const char **version);
564 bool tracecmd_compress_is_supported(const char *name, const char *version);
565 int tracecmd_compress_protos_get(char ***names, char ***versions);
566 int tracecmd_compress_proto_register(struct tracecmd_compression_proto *proto);
567 int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int chunk_size,
568 				size_t *read_size, size_t *write_size);
569 int tracecmd_uncompress_copy_to(struct tracecmd_compression *handle, int fd,
570 				size_t *read_size, size_t *write_size);
571 int tracecmd_uncompress_chunk(struct tracecmd_compression *handle,
572 			      struct tracecmd_compress_chunk *chunk, char *data);
573 int tracecmd_load_chunks_info(struct tracecmd_compression *handle,
574 			      struct tracecmd_compress_chunk **chunks_info);
575 /* --- Plugin handling --- */
576 extern struct tep_plugin_option trace_ftrace_options[];
577 
578 char **trace_util_find_plugin_files(const char *suffix);
579 void trace_util_free_plugin_files(char **files);
580 
581 /* Used for trace-cmd list */
582 void tracecmd_ftrace_load_options(void);
583 
584 /* event hooks */
585 
586 struct hook_list {
587 	struct hook_list	*next;
588 	struct buffer_instance	*instance;
589 	const char		*hook;
590 	char			*str;
591 	char			*start_system;
592 	char			*start_event;
593 	char			*start_match;
594 	char			*end_system;
595 	char			*end_event;
596 	char			*end_match;
597 	char			*pid;
598 	int			migrate;
599 	int			global;
600 	int			stack;
601 };
602 
603 struct hook_list *tracecmd_create_event_hook(const char *arg);
604 void tracecmd_free_hooks(struct hook_list *hooks);
605 
606 void tracecmd_plog(const char *fmt, ...);
607 void tracecmd_plog_error(const char *fmt, ...);
608 int tracecmd_set_logfile(char *logfile);
609 
610 /* --- System --- */
611 unsigned long long tracecmd_generate_traceid(void);
612 int tracecmd_count_cpus(void);
613 
614 /* --- Hack! --- */
615 int tracecmd_blk_hack(struct tracecmd_input *handle);
616 
617 /* --- Stack tracer functions --- */
618 int tracecmd_stack_tracer_status(int *status);
619 
620 /* --- Debugging --- */
621 struct kbuffer *tracecmd_record_kbuf(struct tracecmd_input *handle,
622 				     struct tep_record *record);
623 void *tracecmd_record_page(struct tracecmd_input *handle,
624 			   struct tep_record *record);
625 void *tracecmd_record_offset(struct tracecmd_input *handle,
626 			     struct tep_record *record);
627 #ifdef PERF
628 
629 #include <linux/perf_event.h>
630 
631 /* trace-cmd Perf */
632 struct trace_perf {
633 	int fd;
634 	int cpu;
635 	int pid;
636 	int pages;
637 	struct perf_event_attr pe;
638 	struct perf_event_mmap_page *mmap;
639 };
640 int trace_perf_init(struct trace_perf *perf, int pages, int cpu, int pid);
641 int trace_perf_open(struct trace_perf *perf);
642 void trace_perf_close(struct trace_perf *perf);
643 #endif
644 
645 #endif /* _TRACE_CMD_PRIVATE_H */
646