• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3  * Copyright (C) 2019, VMware, Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
4  *
5  */
6 #ifndef _TRACE_FS_H
7 #define _TRACE_FS_H
8 
9 #include <fcntl.h>
10 #include <sched.h>
11 #include <event-parse.h>
12 
13 char *tracefs_get_tracing_file(const char *name);
14 void tracefs_put_tracing_file(char *name);
15 
16 /* the returned string must *not* be freed */
17 const char *tracefs_tracing_dir(void);
18 const char *tracefs_debug_dir(void);
19 int tracefs_set_tracing_dir(char *tracing_dir);
20 int tracefs_tracing_dir_is_mounted(bool mount, const char **path);
21 
22 /* ftrace instances */
23 struct tracefs_instance;
24 
25 void tracefs_instance_free(struct tracefs_instance *instance);
26 struct tracefs_instance *tracefs_instance_create(const char *name);
27 struct tracefs_instance *tracefs_instance_alloc(const char *tracing_dir,
28 						const char *name);
29 int tracefs_instance_destroy(struct tracefs_instance *instance);
30 bool tracefs_instance_is_new(struct tracefs_instance *instance);
31 const char *tracefs_instance_get_name(struct tracefs_instance *instance);
32 const char *tracefs_instance_get_trace_dir(struct tracefs_instance *instance);
33 char *
34 tracefs_instance_get_file(struct tracefs_instance *instance, const char *file);
35 char *tracefs_instance_get_dir(struct tracefs_instance *instance);
36 int tracefs_instance_file_write(struct tracefs_instance *instance,
37 				const char *file, const char *str);
38 int tracefs_instance_file_append(struct tracefs_instance *instance,
39 				 const char *file, const char *str);
40 int tracefs_instance_file_clear(struct tracefs_instance *instance,
41 				const char *file);
42 char *tracefs_instance_file_read(struct tracefs_instance *instance,
43 				 const char *file, int *psize);
44 int tracefs_instance_file_read_number(struct tracefs_instance *instance,
45 				      const char *file, long long *res);
46 int tracefs_instance_file_open(struct tracefs_instance *instance,
47 			       const char *file, int mode);
48 int tracefs_instances_walk(int (*callback)(const char *, void *), void *context);
49 int tracefs_instance_set_affinity_set(struct tracefs_instance *instance,
50 				  cpu_set_t *set, size_t set_size);
51 int tracefs_instance_set_affinity_raw(struct tracefs_instance *instance,
52 				      const char *mask);
53 int tracefs_instance_set_affinity(struct tracefs_instance *instance,
54 				  const char *cpu_str);
55 char *tracefs_instance_get_affinity(struct tracefs_instance *instance);
56 char *tracefs_instance_get_affinity_raw(struct tracefs_instance *instance);
57 int tracefs_instance_get_affinity_set(struct tracefs_instance *instance,
58 				      cpu_set_t *set, size_t set_size);
59 ssize_t tracefs_instance_get_buffer_size(struct tracefs_instance *instance, int cpu);
60 int tracefs_instance_set_buffer_size(struct tracefs_instance *instance, size_t size, int cpu);
61 char **tracefs_instances(const char *regex);
62 
63 bool tracefs_instance_exists(const char *name);
64 bool tracefs_file_exists(struct tracefs_instance *instance, const char *name);
65 bool tracefs_dir_exists(struct tracefs_instance *instance, const char *name);
66 
67 int tracefs_trace_is_on(struct tracefs_instance *instance);
68 int tracefs_trace_on(struct tracefs_instance *instance);
69 int tracefs_trace_off(struct tracefs_instance *instance);
70 int tracefs_trace_on_fd(int fd);
71 int tracefs_trace_off_fd(int fd);
72 
73 enum tracefs_enable_state {
74 	TRACEFS_ERROR		= -1,
75 	TRACEFS_ALL_DISABLED	= 0,
76 	TRACEFS_ALL_ENABLED	= 1,
77 	TRACEFS_SOME_ENABLED	= 2,
78 };
79 
80 int tracefs_event_enable(struct tracefs_instance *instance, const char *system, const char *event);
81 int tracefs_event_disable(struct tracefs_instance *instance, const char *system, const char *event);
82 enum tracefs_enable_state tracefs_event_is_enabled(struct tracefs_instance *instance,
83 			 const char *system, const char *event);
84 
85 char *tracefs_error_last(struct tracefs_instance *instance);
86 char *tracefs_error_all(struct tracefs_instance *instance);
87 int tracefs_error_clear(struct tracefs_instance *instance);
88 
89 void tracefs_list_free(char **list);
90 char **tracefs_list_add(char **list, const char *string);
91 int tracefs_list_size(char **list);
92 
93 bool tracefs_tracer_available(const char *tracing_dir, const char *tracer);
94 
95 /**
96  * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance
97  * @instance: ftrace instance, can be NULL for the top instance
98  *
99  * Returns -1 in case of an error, or a valid file descriptor to "tracing_on"
100  * file for reading and writing.The returned FD must be closed with close().
101  */
tracefs_trace_on_get_fd(struct tracefs_instance * instance)102 static inline int tracefs_trace_on_get_fd(struct tracefs_instance *instance)
103 {
104 	return tracefs_instance_file_open(instance, "tracing_on", O_RDWR);
105 }
106 
107 /* trace print string*/
108 int tracefs_print_init(struct tracefs_instance *instance);
109 int tracefs_printf(struct tracefs_instance *instance, const char *fmt, ...);
110 int tracefs_vprintf(struct tracefs_instance *instance, const char *fmt, va_list ap);
111 void tracefs_print_close(struct tracefs_instance *instance);
112 
113 /* trace write binary data*/
114 int tracefs_binary_init(struct tracefs_instance *instance);
115 int tracefs_binary_write(struct tracefs_instance *instance, void *data, int len);
116 void tracefs_binary_close(struct tracefs_instance *instance);
117 
118 /* events */
119 char **tracefs_event_systems(const char *tracing_dir);
120 char **tracefs_system_events(const char *tracing_dir, const char *system);
121 int tracefs_iterate_raw_events(struct tep_handle *tep,
122 				struct tracefs_instance *instance,
123 				cpu_set_t *cpus, int cpu_size,
124 				int (*callback)(struct tep_event *,
125 						struct tep_record *,
126 						int, void *),
127 				void *callback_context);
128 void tracefs_iterate_stop(struct tracefs_instance *instance);
129 int tracefs_follow_event(struct tep_handle *tep, struct tracefs_instance *instance,
130 			  const char *system, const char *event_name,
131 			  int (*callback)(struct tep_event *,
132 					  struct tep_record *,
133 					  int, void *),
134 			  void *callback_data);
135 int tracefs_follow_missed_events(struct tracefs_instance *instance,
136 				 int (*callback)(struct tep_event *,
137 						 struct tep_record *,
138 						 int, void *),
139 				 void *callback_data);
140 
141 char *tracefs_event_get_file(struct tracefs_instance *instance,
142 			     const char *system, const char *event,
143 			     const char *file);
144 char *tracefs_event_file_read(struct tracefs_instance *instance,
145 			      const char *system, const char *event,
146 			      const char *file, int *psize);
147 int tracefs_event_file_write(struct tracefs_instance *instance,
148 			     const char *system, const char *event,
149 			     const char *file, const char *str);
150 int tracefs_event_file_append(struct tracefs_instance *instance,
151 			      const char *system, const char *event,
152 			      const char *file, const char *str);
153 int tracefs_event_file_clear(struct tracefs_instance *instance,
154 			     const char *system, const char *event,
155 			     const char *file);
156 bool tracefs_event_file_exists(struct tracefs_instance *instance,
157 			       const char *system, const char *event,
158 			       const char *file);
159 
160 char **tracefs_tracers(const char *tracing_dir);
161 
162 struct tep_handle *tracefs_local_events(const char *tracing_dir);
163 struct tep_handle *tracefs_local_events_system(const char *tracing_dir,
164 					       const char * const *sys_names);
165 int tracefs_fill_local_events(const char *tracing_dir,
166 			       struct tep_handle *tep, int *parsing_failures);
167 
168 int tracefs_load_cmdlines(const char *tracing_dir, struct tep_handle *tep);
169 
170 char *tracefs_get_clock(struct tracefs_instance *instance);
171 
172 enum tracefs_option_id {
173 	TRACEFS_OPTION_INVALID = 0,
174 	TRACEFS_OPTION_ANNOTATE,
175 	TRACEFS_OPTION_BIN,
176 	TRACEFS_OPTION_BLK_CGNAME,
177 	TRACEFS_OPTION_BLK_CGROUP,
178 	TRACEFS_OPTION_BLK_CLASSIC,
179 	TRACEFS_OPTION_BLOCK,
180 	TRACEFS_OPTION_CONTEXT_INFO,
181 	TRACEFS_OPTION_DISABLE_ON_FREE,
182 	TRACEFS_OPTION_DISPLAY_GRAPH,
183 	TRACEFS_OPTION_EVENT_FORK,
184 	TRACEFS_OPTION_FGRAPH_ABSTIME,
185 	TRACEFS_OPTION_FGRAPH_CPU,
186 	TRACEFS_OPTION_FGRAPH_DURATION,
187 	TRACEFS_OPTION_FGRAPH_IRQS,
188 	TRACEFS_OPTION_FGRAPH_OVERHEAD,
189 	TRACEFS_OPTION_FGRAPH_OVERRUN,
190 	TRACEFS_OPTION_FGRAPH_PROC,
191 	TRACEFS_OPTION_FGRAPH_TAIL,
192 	TRACEFS_OPTION_FUNC_STACKTRACE,
193 	TRACEFS_OPTION_FUNCTION_FORK,
194 	TRACEFS_OPTION_FUNCTION_TRACE,
195 	TRACEFS_OPTION_GRAPH_TIME,
196 	TRACEFS_OPTION_HEX,
197 	TRACEFS_OPTION_IRQ_INFO,
198 	TRACEFS_OPTION_LATENCY_FORMAT,
199 	TRACEFS_OPTION_MARKERS,
200 	TRACEFS_OPTION_OVERWRITE,
201 	TRACEFS_OPTION_PAUSE_ON_TRACE,
202 	TRACEFS_OPTION_PRINTK_MSG_ONLY,
203 	TRACEFS_OPTION_PRINT_PARENT,
204 	TRACEFS_OPTION_RAW,
205 	TRACEFS_OPTION_RECORD_CMD,
206 	TRACEFS_OPTION_RECORD_TGID,
207 	TRACEFS_OPTION_SLEEP_TIME,
208 	TRACEFS_OPTION_STACKTRACE,
209 	TRACEFS_OPTION_SYM_ADDR,
210 	TRACEFS_OPTION_SYM_OFFSET,
211 	TRACEFS_OPTION_SYM_USEROBJ,
212 	TRACEFS_OPTION_TRACE_PRINTK,
213 	TRACEFS_OPTION_USERSTACKTRACE,
214 	TRACEFS_OPTION_VERBOSE,
215 };
216 #define TRACEFS_OPTION_MAX (TRACEFS_OPTION_VERBOSE + 1)
217 
218 struct tracefs_options_mask;
219 bool tracefs_option_mask_is_set(const struct tracefs_options_mask *options,
220 				enum tracefs_option_id id);
221 const struct tracefs_options_mask *tracefs_options_get_supported(struct tracefs_instance *instance);
222 bool tracefs_option_is_supported(struct tracefs_instance *instance, enum tracefs_option_id id);
223 const struct tracefs_options_mask *tracefs_options_get_enabled(struct tracefs_instance *instance);
224 bool tracefs_option_is_enabled(struct tracefs_instance *instance, enum tracefs_option_id id);
225 int tracefs_option_enable(struct tracefs_instance *instance, enum tracefs_option_id id);
226 int tracefs_option_disable(struct tracefs_instance *instance, enum tracefs_option_id id);
227 const char *tracefs_option_name(enum tracefs_option_id id);
228 enum tracefs_option_id tracefs_option_id(const char *name);
229 
230 /*
231  * RESET	- Reset on opening filter file (O_TRUNC)
232  * CONTINUE	- Do not close filter file on return.
233  * FUTURE	- For kernels that support this feature, enable filters for
234  *		  a module that has yet to be loaded.
235  */
236 enum {
237 	TRACEFS_FL_RESET	= (1 << 0),
238 	TRACEFS_FL_CONTINUE	= (1 << 1),
239 	TRACEFS_FL_FUTURE	= (1 << 2),
240 };
241 
242 int tracefs_function_filter(struct tracefs_instance *instance, const char *filter,
243 			    const char *module, unsigned int flags);
244 int tracefs_function_notrace(struct tracefs_instance *instance, const char *filter,
245 			     const char *module, unsigned int flags);
246 int tracefs_filter_functions(const char *filter, const char *module, char ***list);
247 
248 
249 /* Control library logs */
250 void tracefs_set_loglevel(enum tep_loglevel level);
251 
252 enum tracefs_tracers {
253 	TRACEFS_TRACER_NOP = 0,
254 	TRACEFS_TRACER_CUSTOM,
255 	TRACEFS_TRACER_FUNCTION,
256 	TRACEFS_TRACER_FUNCTION_GRAPH,
257 	TRACEFS_TRACER_IRQSOFF,
258 	TRACEFS_TRACER_PREEMPTOFF,
259 	TRACEFS_TRACER_PREEMPTIRQSOFF,
260 	TRACEFS_TRACER_WAKEUP,
261 	TRACEFS_TRACER_WAKEUP_RT,
262 	TRACEFS_TRACER_WAKEUP_DL,
263 	TRACEFS_TRACER_MMIOTRACE,
264 	TRACEFS_TRACER_HWLAT,
265 	TRACEFS_TRACER_BRANCH,
266 	TRACEFS_TRACER_BLOCK,
267 };
268 
269 int tracefs_tracer_set(struct tracefs_instance *instance, enum tracefs_tracers tracer, ...);
270 
271 int tracefs_tracer_clear(struct tracefs_instance *instance);
272 
273 ssize_t tracefs_trace_pipe_stream(int fd, struct tracefs_instance *instance, int flags);
274 ssize_t tracefs_trace_pipe_print(struct tracefs_instance *instance, int flags);
275 void tracefs_trace_pipe_stop(struct tracefs_instance *instance);
276 
277 /* Dynamic events */
278 struct tracefs_dynevent;
279 enum tracefs_dynevent_type {
280 	TRACEFS_DYNEVENT_UNKNOWN	= 0,
281 	TRACEFS_DYNEVENT_KPROBE		= 1 << 0,
282 	TRACEFS_DYNEVENT_KRETPROBE	= 1 << 1,
283 	TRACEFS_DYNEVENT_UPROBE		= 1 << 2,
284 	TRACEFS_DYNEVENT_URETPROBE	= 1 << 3,
285 	TRACEFS_DYNEVENT_EPROBE		= 1 << 4,
286 	TRACEFS_DYNEVENT_SYNTH		= 1 << 5,
287 	TRACEFS_DYNEVENT_MAX		= 1 << 6,
288 };
289 
290 #define TRACEFS_DYNEVENT_ALL		0xFFFFFFFF
291 
292 int tracefs_dynevent_create(struct tracefs_dynevent *devent);
293 int tracefs_dynevent_destroy(struct tracefs_dynevent *devent, bool force);
294 int tracefs_dynevent_destroy_all(unsigned int types, bool force);
295 void tracefs_dynevent_free(struct tracefs_dynevent *devent);
296 void tracefs_dynevent_list_free(struct tracefs_dynevent **events);
297 struct tracefs_dynevent **
298 tracefs_dynevent_get_all(unsigned int types, const char *system);
299 struct tracefs_dynevent *
300 tracefs_dynevent_get(enum tracefs_dynevent_type type, const char *system, const char *event);
301 enum tracefs_dynevent_type
302 tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system,
303 		      char **event, char **prefix, char **addr, char **format);
304 struct tep_event *
305 tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent);
306 
307 struct tracefs_dynevent *
308 tracefs_eprobe_alloc(const char *system, const char *event,
309 		     const char *target_system, const char *target_event, const char *fetchargs);
310 struct tracefs_dynevent *
311 tracefs_uprobe_alloc(const char *system, const char *event,
312 		     const char *file, unsigned long long offset, const char *fetchargs);
313 struct tracefs_dynevent *
314 tracefs_uretprobe_alloc(const char *system, const char *event,
315 			const char *file, unsigned long long offset, const char *fetchargs);
316 
317 struct tracefs_dynevent *
318 tracefs_kprobe_alloc(const char *system, const char *event, const char *addr, const char *format);
319 struct tracefs_dynevent *
320 tracefs_kretprobe_alloc(const char *system, const char *event,
321 			const char *addr, const char *format, unsigned int max);
322 int tracefs_kprobe_raw(const char *system, const char *event,
323 		       const char *addr, const char *format);
324 int tracefs_kretprobe_raw(const char *system, const char *event,
325 			  const char *addr, const char *format);
326 
327 enum tracefs_hist_key_type {
328 	TRACEFS_HIST_KEY_NORMAL = 0,
329 	TRACEFS_HIST_KEY_HEX,
330 	TRACEFS_HIST_KEY_SYM,
331 	TRACEFS_HIST_KEY_SYM_OFFSET,
332 	TRACEFS_HIST_KEY_SYSCALL,
333 	TRACEFS_HIST_KEY_EXECNAME,
334 	TRACEFS_HIST_KEY_LOG,
335 	TRACEFS_HIST_KEY_USECS,
336 	TRACEFS_HIST_KEY_BUCKETS,
337 	TRACEFS_HIST_KEY_MAX
338 };
339 
340 enum tracefs_hist_sort_direction {
341 	TRACEFS_HIST_SORT_ASCENDING,
342 	TRACEFS_HIST_SORT_DESCENDING,
343 };
344 
345 #define TRACEFS_HIST_TIMESTAMP		"common_timestamp"
346 #define TRACEFS_HIST_TIMESTAMP_USECS	"common_timestamp.usecs"
347 #define TRACEFS_HIST_CPU		"cpu"
348 
349 #define TRACEFS_HIST_COUNTER		"__COUNTER__"
350 
351 #define TRACEFS_HIST_HITCOUNT		"hitcount"
352 
353 struct tracefs_hist;
354 
355 enum tracefs_hist_command {
356 	TRACEFS_HIST_CMD_START = 0,
357 	TRACEFS_HIST_CMD_PAUSE,
358 	TRACEFS_HIST_CMD_CONT,
359 	TRACEFS_HIST_CMD_CLEAR,
360 	TRACEFS_HIST_CMD_DESTROY,
361 };
362 
363 enum tracefs_filter {
364 	TRACEFS_FILTER_COMPARE,
365 	TRACEFS_FILTER_AND,
366 	TRACEFS_FILTER_OR,
367 	TRACEFS_FILTER_NOT,
368 	TRACEFS_FILTER_OPEN_PAREN,
369 	TRACEFS_FILTER_CLOSE_PAREN,
370 };
371 
372 enum tracefs_compare {
373 	TRACEFS_COMPARE_EQ,
374 	TRACEFS_COMPARE_NE,
375 	TRACEFS_COMPARE_GT,
376 	TRACEFS_COMPARE_GE,
377 	TRACEFS_COMPARE_LT,
378 	TRACEFS_COMPARE_LE,
379 	TRACEFS_COMPARE_RE,
380 	TRACEFS_COMPARE_AND,
381 };
382 
383 void tracefs_hist_free(struct tracefs_hist *hist);
384 struct tracefs_hist *
385 tracefs_hist_alloc(struct tep_handle *tep,
386 		   const char *system, const char *event_name,
387 		   const char *key, enum tracefs_hist_key_type type);
388 struct tracefs_hist *
389 tracefs_hist_alloc_2d(struct tep_handle *tep,
390 		      const char *system, const char *event_name,
391 		      const char *key1, enum tracefs_hist_key_type type1,
392 		      const char *key2, enum tracefs_hist_key_type type2);
393 
394 struct tracefs_hist_axis {
395 	const char *key;
396 	enum tracefs_hist_key_type type;
397 };
398 
399 struct tracefs_hist_axis_cnt {
400 	const char *key;
401 	enum tracefs_hist_key_type type;
402 	int cnt;
403 };
404 
405 struct tracefs_hist *
406 tracefs_hist_alloc_nd(struct tep_handle *tep,
407 		      const char *system, const char *event_name,
408 		      struct tracefs_hist_axis *axes);
409 struct tracefs_hist *
410 tracefs_hist_alloc_nd_cnt(struct tep_handle *tep,
411 			  const char *system, const char *event_name,
412 			  struct tracefs_hist_axis_cnt *axes);
413 const char *tracefs_hist_get_name(struct tracefs_hist *hist);
414 const char *tracefs_hist_get_event(struct tracefs_hist *hist);
415 const char *tracefs_hist_get_system(struct tracefs_hist *hist);
416 int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key,
417 			 enum tracefs_hist_key_type type);
418 int tracefs_hist_add_key_cnt(struct tracefs_hist *hist, const char *key,
419 			 enum tracefs_hist_key_type type, int cnt);
420 int tracefs_hist_add_value(struct tracefs_hist *hist, const char *value);
421 int tracefs_hist_add_sort_key(struct tracefs_hist *hist,
422 			      const char *sort_key);
423 int tracefs_hist_set_sort_key(struct tracefs_hist *hist,
424 			      const char *sort_key, ...);
425 int tracefs_hist_sort_key_direction(struct tracefs_hist *hist,
426 				    const char *sort_key,
427 				    enum tracefs_hist_sort_direction dir);
428 int tracefs_hist_add_name(struct tracefs_hist *hist, const char *name);
429 int tracefs_hist_append_filter(struct tracefs_hist *hist,
430 			       enum tracefs_filter type,
431 			       const char *field,
432 			       enum tracefs_compare compare,
433 			       const char *val);
434 int tracefs_hist_echo_cmd(struct trace_seq *seq,  struct tracefs_instance *instance,
435 			  struct tracefs_hist *hist, enum tracefs_hist_command command);
436 int tracefs_hist_command(struct tracefs_instance *instance,
437 			 struct tracefs_hist *hist, enum tracefs_hist_command cmd);
438 
439 /**
440  * tracefs_hist_start - enable a histogram
441  * @instance: The instance the histogram will be in (NULL for toplevel)
442  * @hist: The histogram to start
443  *
444  * Starts executing a histogram.
445  *
446  * Returns 0 on success, -1 on error.
447  */
tracefs_hist_start(struct tracefs_instance * instance,struct tracefs_hist * hist)448 static inline int tracefs_hist_start(struct tracefs_instance *instance,
449 				     struct tracefs_hist *hist)
450 {
451 	return tracefs_hist_command(instance, hist, 0);
452 }
453 
454 /**
455  * tracefs_hist_pause - pause a histogram
456  * @instance: The instance the histogram is in (NULL for toplevel)
457  * @hist: The histogram to pause
458  *
459  * Pause a histogram.
460  *
461  * Returns 0 on success, -1 on error.
462  */
tracefs_hist_pause(struct tracefs_instance * instance,struct tracefs_hist * hist)463 static inline int tracefs_hist_pause(struct tracefs_instance *instance,
464 				     struct tracefs_hist *hist)
465 {
466 	return tracefs_hist_command(instance, hist, TRACEFS_HIST_CMD_PAUSE);
467 }
468 
469 /**
470  * tracefs_hist_continue - continue a paused histogram
471  * @instance: The instance the histogram is in (NULL for toplevel)
472  * @hist: The histogram to continue
473  *
474  * Continue a histogram.
475  *
476  * Returns 0 on success, -1 on error.
477  */
tracefs_hist_continue(struct tracefs_instance * instance,struct tracefs_hist * hist)478 static inline int tracefs_hist_continue(struct tracefs_instance *instance,
479 					struct tracefs_hist *hist)
480 {
481 	return tracefs_hist_command(instance, hist, TRACEFS_HIST_CMD_CONT);
482 }
483 
484 /**
485  * tracefs_hist_reset - clear a histogram
486  * @instance: The instance the histogram is in (NULL for toplevel)
487  * @hist: The histogram to reset
488  *
489  * Resets a histogram.
490  *
491  * Returns 0 on success, -1 on error.
492  */
tracefs_hist_reset(struct tracefs_instance * instance,struct tracefs_hist * hist)493 static inline int tracefs_hist_reset(struct tracefs_instance *instance,
494 				     struct tracefs_hist *hist)
495 {
496 	return tracefs_hist_command(instance, hist, TRACEFS_HIST_CMD_CLEAR);
497 }
498 
499 /**
500  * tracefs_hist_destroy - deletes a histogram (needs to be enabled again)
501  * @instance: The instance the histogram is in (NULL for toplevel)
502  * @hist: The histogram to delete
503  *
504  * Deletes (removes) a running histogram. This is different than
505  * clear, as clear only clears the data but the histogram still exists.
506  * This deletes the histogram and should be called before
507  * tracefs_hist_free() to clean up properly.
508  *
509  * Returns 0 on success, -1 on error.
510  */
tracefs_hist_destroy(struct tracefs_instance * instance,struct tracefs_hist * hist)511 static inline int tracefs_hist_destroy(struct tracefs_instance *instance,
512 				       struct tracefs_hist *hist)
513 {
514 	return tracefs_hist_command(instance, hist, TRACEFS_HIST_CMD_DESTROY);
515 }
516 
517 struct tracefs_synth;
518 
519 /*
520  * DELTA_END	- end_field - start_field
521  * DELTA_START	- start_field - end_field
522  * ADD		- start_field + end_field
523  */
524 enum tracefs_synth_calc {
525 	TRACEFS_SYNTH_DELTA_END,
526 	TRACEFS_SYNTH_DELTA_START,
527 	TRACEFS_SYNTH_ADD,
528 };
529 
530 int tracefs_filter_string_append(struct tep_event *event, char **filter,
531 				 enum tracefs_filter type,
532 				 const char *field, enum tracefs_compare compare,
533 				 const char *val);
534 int tracefs_filter_string_verify(struct tep_event *event, const char *filter,
535 				 char **err);
536 
537 int tracefs_event_filter_apply(struct tracefs_instance *instance,
538 			       struct tep_event *event, const char *filter);
539 
540 int tracefs_event_filter_clear(struct tracefs_instance *instance,
541 			       struct tep_event *event);
542 
543 /** Deprecated do not use: Instead use tracefs_filter_string_append() **/
544 int tracefs_event_append_filter(struct tep_event *event, char **filter,
545 				enum tracefs_filter type,
546 				const char *field, enum tracefs_compare compare,
547 				const char *val);
548 
549 /** Deprecated do not use: Instead use tracefs_filter_string_verify()  **/
550 int tracefs_event_verify_filter(struct tep_event *event, const char *filter,
551 				char **err);
552 
553 #define TRACEFS_TIMESTAMP "common_timestamp"
554 #define TRACEFS_TIMESTAMP_USECS "common_timestamp.usecs"
555 
556 enum tracefs_synth_handler {
557 	TRACEFS_SYNTH_HANDLE_NONE	= 0,
558 	TRACEFS_SYNTH_HANDLE_MATCH,
559 	TRACEFS_SYNTH_HANDLE_MAX,
560 	TRACEFS_SYNTH_HANDLE_CHANGE,
561 };
562 
563 const char *tracefs_synth_get_name(struct tracefs_synth *synth);
564 struct tracefs_synth *tracefs_synth_alloc(struct tep_handle *tep,
565 					  const char *name,
566 					  const char *start_system,
567 					  const char *start_event,
568 					  const char *end_system,
569 					  const char *end_event,
570 					  const char *start_match_field,
571 					  const char *end_match_field,
572 					  const char *match_name);
573 int tracefs_synth_add_match_field(struct tracefs_synth *synth,
574 				  const char *start_match_field,
575 				  const char *end_match_field,
576 				  const char *name);
577 int tracefs_synth_add_compare_field(struct tracefs_synth *synth,
578 				    const char *start_compare_field,
579 				    const char *end_compare_field,
580 				    enum tracefs_synth_calc calc,
581 				    const char *name);
582 int tracefs_synth_add_start_field(struct tracefs_synth *synth,
583 				  const char *start_field,
584 				  const char *name);
585 int tracefs_synth_add_end_field(struct tracefs_synth *synth,
586 				const char *end_field,
587 				const char *name);
588 int tracefs_synth_append_start_filter(struct tracefs_synth *synth,
589 				      enum tracefs_filter type,
590 				      const char *field,
591 				      enum tracefs_compare compare,
592 				      const char *val);
593 int tracefs_synth_append_end_filter(struct tracefs_synth *synth,
594 				    enum tracefs_filter type,
595 				    const char *field,
596 				    enum tracefs_compare compare,
597 				    const char *val);
598 int tracefs_synth_trace(struct tracefs_synth *synth,
599 			enum tracefs_synth_handler type, const char *field);
600 int tracefs_synth_snapshot(struct tracefs_synth *synth,
601 			   enum tracefs_synth_handler type, const char *field);
602 int tracefs_synth_save(struct tracefs_synth *synth,
603 		       enum tracefs_synth_handler type, const char *field,
604 		       char **save_fields);
605 bool tracefs_synth_complete(struct tracefs_synth *synth);
606 struct tracefs_hist *tracefs_synth_get_start_hist(struct tracefs_synth *synth);
607 int tracefs_synth_create(struct tracefs_synth *synth);
608 int tracefs_synth_destroy(struct tracefs_synth *synth);
609 void tracefs_synth_free(struct tracefs_synth *synth);
610 int tracefs_synth_echo_cmd(struct trace_seq *seq, struct tracefs_synth *synth);
611 int tracefs_synth_raw_fmt(struct trace_seq *seq, struct tracefs_synth *synth);
612 const char *tracefs_synth_show_event(struct tracefs_synth *synth);
613 const char *tracefs_synth_show_start_hist(struct tracefs_synth *synth);
614 const char *tracefs_synth_show_end_hist(struct tracefs_synth *synth);
615 
616 struct tracefs_synth *tracefs_sql(struct tep_handle *tep, const char *name,
617 				  const char *sql_buffer, char **err);
618 struct tep_event *
619 tracefs_synth_get_event(struct tep_handle *tep, struct tracefs_synth *synth);
620 
621 struct tracefs_cpu;
622 
623 struct tracefs_cpu *tracefs_cpu_alloc_fd(int fd, int subbuf_size, bool nonblock);
624 struct tracefs_cpu *tracefs_cpu_open(struct tracefs_instance *instance,
625 				     int cpu, bool nonblock);
626 void tracefs_cpu_close(struct tracefs_cpu *tcpu);
627 void tracefs_cpu_free_fd(struct tracefs_cpu *tcpu);
628 int tracefs_cpu_read_size(struct tracefs_cpu *tcpu);
629 int tracefs_cpu_read(struct tracefs_cpu *tcpu, void *buffer, bool nonblock);
630 int tracefs_cpu_buffered_read(struct tracefs_cpu *tcpu, void *buffer, bool nonblock);
631 int tracefs_cpu_write(struct tracefs_cpu *tcpu, int wfd, bool nonblock);
632 int tracefs_cpu_stop(struct tracefs_cpu *tcpu);
633 int tracefs_cpu_flush(struct tracefs_cpu *tcpu, void *buffer);
634 int tracefs_cpu_flush_write(struct tracefs_cpu *tcpu, int wfd);
635 int tracefs_cpu_pipe(struct tracefs_cpu *tcpu, int wfd, bool nonblock);
636 
637 #endif /* _TRACE_FS_H */
638