0ec04fc6e5edfd83458e021ecf835c0b5f429eaa
[ust.git] / libustcomm / ustcomm.h
1 /* Copyright (C) 2009 Pierre-Marc Fournier
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #ifndef USTCOMM_H
19 #define USTCOMM_H
20
21 #include <sys/types.h>
22 #include <sys/un.h>
23 #include <urcu/list.h>
24
25 #include <ust/kcompat/kcompat.h>
26
27 #define SOCK_DIR "/tmp/ust-app-socks"
28
29 struct ustcomm_sock {
30 struct cds_list_head list;
31 int fd;
32 int epoll_fd;
33 };
34
35 struct ustcomm_header {
36 int command;
37 long size;
38 int result;
39 int fd_included;
40 };
41
42 #define USTCOMM_BUFFER_SIZE ((1 << 12) - sizeof(struct ustcomm_header))
43
44 /* Specify a sata size that leaves margin at the end of a buffer
45 * in order to make sure that we never have more data than
46 * will fit in the buffer AND that the last chars (due to a
47 * pre-receive memset) will always be 0, terminating any string
48 */
49 #define USTCOMM_DATA_SIZE (USTCOMM_BUFFER_SIZE - 20 * sizeof(void *))
50
51 enum tracectl_commands {
52 ALLOC_TRACE,
53 CONSUME_BUFFER,
54 CREATE_TRACE,
55 DESTROY_TRACE,
56 DISABLE_MARKER,
57 ENABLE_MARKER,
58 EXIT,
59 FORCE_SUBBUF_SWITCH,
60 GET_BUF_SHMID_PIPE_FD,
61 GET_PIDUNIQUE,
62 GET_SOCK_PATH,
63 GET_SUBBUFFER,
64 GET_SUBBUF_NUM_SIZE,
65 LIST_MARKERS,
66 LIST_TRACE_EVENTS,
67 LOAD_PROBE_LIB,
68 NOTIFY_BUF_MAPPED,
69 PRINT_MARKERS,
70 PRINT_TRACE_EVENTS,
71 PUT_SUBBUFFER,
72 SETUP_TRACE,
73 SET_SOCK_PATH,
74 SET_SUBBUF_NUM,
75 SET_SUBBUF_SIZE,
76 START,
77 START_TRACE,
78 STOP_TRACE,
79 };
80
81 struct ustcomm_single_field {
82 char *field;
83 char data[USTCOMM_DATA_SIZE];
84 };
85
86 struct ustcomm_channel_info {
87 char *trace;
88 char *channel;
89 unsigned int subbuf_size;
90 unsigned int subbuf_num;
91 char data[USTCOMM_DATA_SIZE];
92 };
93
94 struct ustcomm_buffer_info {
95 char *trace;
96 char *channel;
97 int ch_cpu;
98 pid_t pid;
99 int buf_shmid;
100 int buf_struct_shmid;
101 long consumed_old;
102 char data[USTCOMM_DATA_SIZE];
103 };
104
105 struct ustcomm_marker_info {
106 char *trace;
107 char *channel;
108 char *marker;
109 char data[USTCOMM_DATA_SIZE];
110 };
111
112 struct ustcomm_pidunique {
113 s64 pidunique;
114 };
115
116 struct ustcomm_notify_buf_mapped {
117 char data[USTCOMM_DATA_SIZE];
118 };
119
120 /* Ensure directory existence, usefull for unix sockets */
121 extern int ensure_dir_exists(const char *dir);
122
123 /* Create and delete sockets */
124 extern struct ustcomm_sock * ustcomm_init_sock(int fd, int epoll_fd,
125 struct cds_list_head *list);
126 extern void ustcomm_del_sock(struct ustcomm_sock *sock, int keep_in_epoll);
127
128 /* Create and delete named sockets */
129 extern struct ustcomm_sock * ustcomm_init_named_socket(const char *name,
130 int epoll_fd);
131 extern void ustcomm_del_named_sock(struct ustcomm_sock *sock,
132 int keep_socket_file);
133
134 /* Send and receive functions for file descriptors */
135 extern int ustcomm_send_fd(int sock, const struct ustcomm_header *header,
136 const char *data, int *fd);
137 extern int ustcomm_recv_fd(int sock, struct ustcomm_header *header,
138 char *data, int *fd);
139
140 /* Normal send and receive functions */
141 extern int ustcomm_send(int sock, const struct ustcomm_header *header,
142 const char *data);
143 extern int ustcomm_recv(int sock, struct ustcomm_header *header,
144 char *data);
145
146 /* Receive and allocate data, not to be used inside libust */
147 extern int ustcomm_recv_alloc(int sock,
148 struct ustcomm_header *header,
149 char **data);
150
151 /* Request function, send and receive */
152 extern int ustcomm_req(int sock,
153 const struct ustcomm_header *req_header,
154 const char *req_data,
155 struct ustcomm_header *res_header,
156 char *res_data);
157
158 extern int ustcomm_request_consumer(pid_t pid, const char *channel);
159 extern int ustcomm_connect_app(pid_t pid, int *app_fd);
160 extern int ustcomm_connect_path(const char *path, int *connection_fd);
161
162 extern int nth_token_is(const char *str, const char *token, int tok_no);
163
164 extern char *nth_token(const char *str, int tok_no);
165
166 /* String serialising functions, printf straight into a buffer */
167 #define USTCOMM_POISON_PTR (void *)0x19831018
168
169 extern char * ustcomm_print_data(char *data_field, int field_size,
170 int *offset, const char *format, ...);
171 extern char * ustcomm_restore_ptr(char *ptr, char *data_field,
172 int data_field_size);
173
174 #define COMPUTE_MSG_SIZE(struct_ptr, offset) \
175 (size_t) (long)(struct_ptr)->data - (long)(struct_ptr) + (offset)
176
177 /* Packing and unpacking functions, making life easier */
178 extern int ustcomm_pack_single_field(struct ustcomm_header *header,
179 struct ustcomm_single_field *sf,
180 const char *trace);
181
182 extern int ustcomm_unpack_single_field(struct ustcomm_single_field *sf);
183
184 extern int ustcomm_pack_channel_info(struct ustcomm_header *header,
185 struct ustcomm_channel_info *ch_inf,
186 const char *trace,
187 const char *channel);
188
189 extern int ustcomm_unpack_channel_info(struct ustcomm_channel_info *ch_inf);
190
191 extern int ustcomm_pack_buffer_info(struct ustcomm_header *header,
192 struct ustcomm_buffer_info *buf_inf,
193 const char *trace,
194 const char *channel,
195 int channel_cpu);
196
197 extern int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info *buf_inf);
198
199 extern int ustcomm_pack_marker_info(struct ustcomm_header *header,
200 struct ustcomm_marker_info *marker_inf,
201 const char *trace,
202 const char *channel,
203 const char *marker);
204
205 extern int ustcomm_unpack_marker_info(struct ustcomm_marker_info *marker_inf);
206
207 #endif /* USTCOMM_H */
This page took 0.031989 seconds and 3 git commands to generate.