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