• 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_LOCAL_H
7 #define _TRACE_FS_LOCAL_H
8 
9 #include <pthread.h>
10 
11 #define __hidden __attribute__((visibility ("hidden")))
12 #define __weak __attribute__((weak))
13 
14 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
15 
16 /* Will cause a division by zero warning if cond is true */
17 #define BUILD_BUG_ON(cond)			\
18 	do { if (!(1/!(cond))) { } } while (0)
19 
20 #define HASH_BITS 10
21 
22 struct tracefs_options_mask {
23 	unsigned long long	mask;
24 };
25 
26 struct follow_event {
27 	struct tep_event	*event;
28 	void			*callback_data;
29 	int (*callback)(struct tep_event *,
30 			struct tep_record *,
31 			int, void *);
32 };
33 
34 struct tracefs_instance {
35 	struct tracefs_options_mask	supported_opts;
36 	struct tracefs_options_mask	enabled_opts;
37 	struct follow_event		*followers;
38 	struct follow_event		*missed_followers;
39 	char				*trace_dir;
40 	char				*name;
41 	pthread_mutex_t			lock;
42 	int				ref;
43 	int				flags;
44 	int				ftrace_filter_fd;
45 	int				ftrace_notrace_fd;
46 	int				ftrace_marker_fd;
47 	int				ftrace_marker_raw_fd;
48 	int				nr_followers;
49 	int				nr_missed_followers;
50 	bool				pipe_keep_going;
51 	bool				iterate_keep_going;
52 };
53 
54 extern pthread_mutex_t toplevel_lock;
55 
trace_get_lock(struct tracefs_instance * instance)56 static inline pthread_mutex_t *trace_get_lock(struct tracefs_instance *instance)
57 {
58 	return instance ? &instance->lock : &toplevel_lock;
59 }
60 
61 void trace_put_instance(struct tracefs_instance *instance);
62 int trace_get_instance(struct tracefs_instance *instance);
63 
64 /* Can be overridden */
65 void tracefs_warning(const char *fmt, ...);
66 
67 int str_read_file(const char *file, char **buffer, bool warn);
68 char *trace_append_file(const char *dir, const char *name);
69 char *trace_find_tracing_dir(bool debugfs);
70 
71 #ifndef ACCESSPERMS
72 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
73 #endif
74 
75 #ifndef ALLPERMS
76 #define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) /* 07777 */
77 #endif
78 
79 #ifndef DEFFILEMODE
80 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) /* 0666*/
81 #endif
82 
83 struct tracefs_options_mask *
84 supported_opts_mask(struct tracefs_instance *instance);
85 
86 struct tracefs_options_mask *
87 enabled_opts_mask(struct tracefs_instance *instance);
88 
89 char **trace_list_create_empty(void);
90 int trace_list_pop(char **list);
91 
92 char *append_string(char *str, const char *delim, const char *add);
93 int trace_test_state(int state);
94 bool trace_verify_event_field(struct tep_event *event,
95 			      const char *field_name,
96 			      const struct tep_format_field **ptr_field);
97 int trace_append_filter(char **filter, unsigned int *state,
98 			unsigned int *open_parens,
99 			struct tep_event *event,
100 			enum tracefs_filter type,
101 			const char *field_name,
102 			enum tracefs_compare compare,
103 			 const char *val);
104 
105 struct tracefs_synth *synth_init_from(struct tep_handle *tep,
106 				      const char *start_system,
107 				      const char *start_event);
108 
109 #define HIST_COUNTER_TYPE	(TRACEFS_HIST_KEY_MAX + 100)
110 int synth_add_start_field(struct tracefs_synth *synth,
111 			  const char *start_field,
112 			  const char *name,
113 			  enum tracefs_hist_key_type type, int cnt);
114 
115 /* Internal interface for ftrace dynamic events */
116 
117 struct tracefs_dynevent {
118 	char *trace_file;
119 	char *prefix;
120 	char *system;
121 	char *event;
122 	char *address;
123 	char *format;
124 	enum tracefs_dynevent_type type;
125 };
126 
127 struct tracefs_dynevent *
128 dynevent_alloc(enum tracefs_dynevent_type type, const char *system,
129 	       const char *event, const char *address, const char *format);
130 int dynevent_get_count(unsigned int types, const char *system);
131 
132 int trace_load_events(struct tep_handle *tep,
133 		      const char *tracing_dir, const char *system);
134 int trace_rescan_events(struct tep_handle *tep,
135 			const char *tracing_dir, const char *system);
136 struct tep_event *get_tep_event(struct tep_handle *tep,
137 				const char *system, const char *name);
138 
139 unsigned int quick_hash(const char *str);
140 
141 #endif /* _TRACE_FS_LOCAL_H */
142