Mi create command: support and validation
[lttng-tools.git] / src / common / mi-lttng.h
CommitLineData
c7e35b03
JR
1/*
2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#ifndef _MI_LTTNG_H
20#define _MI_LTTNG_H
21
22#include <stdint.h>
23
24#include <common/error.h>
25#include <common/macros.h>
26#include <common/config/config.h>
27#include <lttng/lttng.h>
28
29/* Instance of a machine interface writer. */
30struct mi_writer {
31 struct config_writer *writer;
32 enum lttng_mi_output_type type;
33};
34
35/*
36 * Version information for the machine interface.
37 */
38struct mi_lttng_version {
39 char version[NAME_MAX]; /* Version number of package */
40 uint32_t version_major; /* LTTng-Tools major version number */
41 uint32_t version_minor; /* LTTng-Tools minor version number */
42 uint32_t version_patchlevel; /* LTTng-Tools patchlevel version number */
314d5222 43 char version_commit[NAME_MAX]; /* Commit hash of the current version */
c7e35b03
JR
44 char version_name[NAME_MAX];
45 char package_url[NAME_MAX]; /* Define to the home page for this package. */
46};
47
48/* Strings related to command */
49const char * const mi_lttng_element_command;
37d03ff7 50const char * const mi_lttng_element_command_name;
c7e35b03
JR
51const char * const mi_lttng_element_command_version;
52const char * const mi_lttng_element_command_list;
1734c658
JRJ
53const char * const mi_lttng_element_command_save;
54const char * const mi_lttng_element_command_load;
e5b83100 55const char * const mi_lttng_element_command_stop;
1cfc0bc8 56const char * const mi_lttng_element_command_start;
37d03ff7 57const char * const mi_lttng_element_command_create;
c7e35b03 58const char * const mi_lttng_element_command_output;
1734c658 59const char * const mi_lttng_element_command_success;
c7e35b03 60
1734c658 61/* Strings related to version command */
c7e35b03
JR
62const char * const mi_lttng_element_version;
63const char * const mi_lttng_element_version_str;
64const char * const mi_lttng_element_version_web;
65const char * const mi_lttng_element_version_major;
66const char * const mi_lttng_element_version_minor;
67const char * const mi_lttng_element_version_license;
314d5222 68const char * const mi_lttng_element_version_commit;
c7e35b03
JR
69const char * const mi_lttng_element_version_patch_level;
70const char * const mi_lttng_element_version_description;
71
5e18ec73
JR
72/* String related to a lttng_event_field */
73const char * const mi_lttng_element_event_field;
74const char * const mi_lttng_element_event_fields;
75
76/* Strings related to pid */
77const char * const mi_lttng_element_pids;
78const char * const mi_lttng_element_pid;
79const char * const mi_lttng_element_pid_id;
80
1734c658
JRJ
81/* Strings related to save command */
82const char * const mi_lttng_element_save;
83
84/* Strings related to load command */
85const char * const mi_lttng_element_load;
86
5e18ec73
JR
87/* General element of mi_lttng */
88const char * const mi_lttng_element_type_other;
89const char * const mi_lttng_element_type_integer;
90const char * const mi_lttng_element_type_enum;
91const char * const mi_lttng_element_type_float;
92const char * const mi_lttng_element_type_string;
93const char * const mi_lttng_element_nowrite;
94
95/* String related to loglevel */
96const char * const mi_lttng_loglevel_str_alert;
97const char * const mi_lttng_loglevel_str_crit;
98const char * const mi_lttng_loglevel_str_debug;
99const char * const mi_lttng_loglevel_str_debug_function;
100const char * const mi_lttng_loglevel_str_debug_line;
101const char * const mi_lttng_loglevel_str_debug_module;
102const char * const mi_lttng_loglevel_str_debug_process;
103const char * const mi_lttng_loglevel_str_debug_program;
104const char * const mi_lttng_loglevel_str_debug_system;
105const char * const mi_lttng_loglevel_str_debug_unit;
106const char * const mi_lttng_loglevel_str_emerg;
107const char * const mi_lttng_loglevel_str_err;
108const char * const mi_lttng_loglevel_str_info;
109const char * const mi_lttng_loglevel_str_notice;
110const char * const mi_lttng_loglevel_str_unknown;
111const char * const mi_lttng_loglevel_str_warning;
112
1734c658 113/* String related to loglevel type */
5e18ec73
JR
114const char * const mi_lttng_loglevel_type_all;
115const char * const mi_lttng_loglevel_type_range;
116const char * const mi_lttng_loglevel_type_single;
117const char * const mi_lttng_loglevel_type_unknown;
118
119/* Utility string function */
120const char *mi_lttng_loglevel_string(int value);
121const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value);
122const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value);
123const char *mi_lttng_domaintype_string(enum lttng_domain_type value);
124const char *mi_lttng_buffertype_string(enum lttng_buffer_type value);
125
c7e35b03
JR
126/*
127 * Create an instance of a machine interface writer.
128 *
129 * fd_output File to which the XML content must be written. The file will be
130 * closed once the mi_writer has been destroyed.
131 *
132 * Returns an instance of a machine interface writer on success, NULL on
133 * error.
134 */
135struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type);
136
137/*
138 * Destroy an instance of a machine interface writer.
139 *
140 * writer An instance of a machine interface writer.
141 *
142 * Returns zero if the XML document could be closed cleanly. Negative values
143 * indicate an error.
144 */
145int mi_lttng_writer_destroy(struct mi_writer *writer);
146
147/*
148 * Open a command tag and add it's name node.
149 *
150 * writer An instance of a machine interface writer.
c7e35b03
JR
151 * command The command name.
152 *
153 * Returns zero if the XML document could be closed cleanly.
154 * Negative values indicate an error.
155 */
156int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command);
157
158/*
159 * Close a command tag.
160 *
161 * writer An instance of a machine interface writer.
162 *
163 * Returns zero if the XML document could be closed cleanly.
164 * Negative values indicate an error.
165 */
166int mi_lttng_writer_command_close(struct mi_writer *writer);
167
168/*
169 * Open an element tag.
170 *
171 * writer An instance of a machine interface writer.
c7e35b03
JR
172 * element_name Element tag name.
173 *
174 * Returns zero if the XML document could be closed cleanly.
175 * Negative values indicate an error.
176 */
177int mi_lttng_writer_open_element(struct mi_writer *writer,
178 const char *element_name);
179
180/*
181 * Close the current element tag.
182 *
183 * writer An instance of a machine interface writer.
184 *
185 * Returns zero if the XML document could be closed cleanly.
186 * Negative values indicate an error.
187 */
188int mi_lttng_writer_close_element(struct mi_writer *writer);
189
190/*
5e18ec73 191 * Close multiple element.
c7e35b03
JR
192 *
193 * writer An instance of a machine interface writer.
5e18ec73 194 * nb_element Number of elements.
c7e35b03 195 *
5e18ec73
JR
196 * Returns zero if the XML document could be closed cleanly.
197 * Negative values indicate an error.
198 */
199int mi_lttng_close_multi_element(struct mi_writer *writer,
200 unsigned int nb_element);
201
202/*
203 * Write an element of type unsigned int.
c7e35b03 204 *
5e18ec73
JR
205 * writer An instance of a machine interface writer.
206 * element_name Element name.
c7e35b03
JR
207 * value Unsigned int value of the element
208 *
209 * Returns zero if the element's value could be written.
210 * Negative values indicate an error.
211 */
212int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer,
213 const char *element_name, uint64_t value);
214
215/*
216 * Write an element of type signed int.
217 *
218 * writer An instance of a machine interface writer.
c7e35b03 219 * element_name Element name.
5e18ec73 220 * value Signed int value of the element.
c7e35b03
JR
221 *
222 * Returns zero if the element's value could be written.
223 * Negative values indicate an error.
224 */
225int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer,
226 const char *element_name, int64_t value);
227
228/*
229 * Write an element of type boolean.
230 *
231 * writer An instance of a machine interface writer.
c7e35b03 232 * element_name Element name.
5e18ec73 233 * value Boolean value of the element.
c7e35b03
JR
234 *
235 * Returns zero if the element's value could be written.
236 * Negative values indicate an error.
237 */
238int mi_lttng_writer_write_element_bool(struct mi_writer *writer,
239 const char *element_name, int value);
240
241/*
242 * Write an element of type string.
243 *
244 * writer An instance of a machine interface writer.
c7e35b03 245 * element_name Element name.
5e18ec73 246 * value String value of the element.
c7e35b03
JR
247 *
248 * Returns zero if the element's value could be written.
249 * Negative values indicate an error.
250 */
251int mi_lttng_writer_write_element_string(struct mi_writer *writer,
252 const char *element_name, const char *value);
253
254/*
255 * Machine interface of struct version.
256 *
257 * writer An instance of a machine interface writer.
c7e35b03 258 * version Version struct.
c7e35b03 259 * lttng_description String value of the version description.
c7e35b03
JR
260 * lttng_license String value of the version license.
261 *
262 * Returns zero if the element's value could be written.
263 * Negative values indicate an error.
264 */
265int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version,
266 const char *lttng_description, const char *lttng_license);
267
268/*
5e18ec73 269 * Machine interface: open a sessions element.
c7e35b03 270 *
5e18ec73 271 * writer An instance of a machine interface writer.
c7e35b03 272 *
5e18ec73
JR
273 * Returns zero if the element's value could be written.
274 * Negative values indicate an error.
275 */
276int mi_lttng_sessions_open(struct mi_writer *writer);
277
278/*
279 * Machine interface of struct session.
c7e35b03 280 *
5e18ec73
JR
281 * writer An instance of a machine interface writer.
282 * session An instance of a session.
283 * is_open Defines whether or not the session element shall be closed.
284 * This should be used carefully and the client
285 * must close the session element.
286 * Use case: nested addtionnal information on a session
c7e35b03 287 * ex: domain,channel event.
c7e35b03
JR
288 *
289 * Returns zero if the element's value could be written.
290 * Negative values indicate an error.
291 */
292int mi_lttng_session(struct mi_writer *writer,
5e18ec73
JR
293 struct lttng_session *session, int is_open);
294
295/*
296 * Machine interface: open a domains element.
297 *
298 * writer An instance of a machine interface writer.
299 *
300 * Returns zero if the element's value could be written.
301 * Negative values indicate an error.
302 */
303int mi_lttng_domains_open(struct mi_writer *writer);
304
305/*
306 * Machine interface of struct domain.
307 *
308 * writer An instance of a machine interface writer.
309 * domain An instance of a domain.
310 *
311 * is_open Defines whether or not the session element shall be closed.
312 * This should be used carefully and the client
313 * must close the domain element.
314 * Use case: nested addition information on a domain
315 * ex: channel event.
316 *
317 * Returns zero if the element's value could be written.
318 * Negative values indicate an error.
319 */
320int mi_lttng_domain(struct mi_writer *writer,
321 struct lttng_domain *domain, int is_open);
322
323/*
324 * Machine interface: open a channels element.
325 *
326 * writer An instance of a machine interface writer.
327 *
328 * Returns zero if the element's value could be written.
329 * Negative values indicate an error.
330 */
331int mi_lttng_channels_open(struct mi_writer *writer);
332
333/*
334 * Machine interface of struct channel.
335 *
336 * writer An instance of a machine interface writer.
337 * channel An instance of a channel.
338 *
339 * is_open Defines whether or not the session element shall be closed.
340 * This should be used carefully and the client
341 * must close the channel element.
342 * Use case: nested addition information on a channel.
343 * ex: channel event.
344 *
345 * Returns zero if the element's value could be written.
346 * Negative values indicate an error.
347 */
348int mi_lttng_channel(struct mi_writer *writer,
349 struct lttng_channel *channel, int is_open);
350
351/*
352 * Machine interface of struct channel_attr.
353 *
354 * writer An instance of a machine interface writer.
355 * attr An instance of a channel_attr struct.
356 *
357 * Returns zero if the element's value could be written.
358 * Negative values indicate an error.
359 */
360int mi_lttng_channel_attr(struct mi_writer *writer,
361 struct lttng_channel_attr *attr);
362
363/*
364* Machine interface for event common attributes.
365*
366* writer An instance of a mi writer.
367* event single trace event.
368*
369* The common attribute are:
370* - mi event element
371* - event name
372* - event type
373* - enabled tag
374* - event filter
375*
376* Returns zero if the element's value could be written.
377* Negative values indicate an error.
378*/
379int mi_lttng_event_common_attributes(struct mi_writer *writer,
380 struct lttng_event *event);
381
382/*
383 * Machine interface for kernel tracepoint event with a loglevel.
384 *
385 * writer An instance of a mi writer.
386 * event single trace event.
387 *
388 * Returns zero if the element's value could be written.
389 * Negative values indicate an error.
390 */
391int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer,
392 struct lttng_event *event);
393
394/*
395 * Machine interface for kernel tracepoint event with no loglevel.
396 *
397 * writer An instance of a mi writer.
398 * event single trace event.
399 *
400 * Returns zero if the element's value could be written.
401 * Negative values indicate an error.
402 */
403int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer,
404 struct lttng_event *event);
405
406/*
407 * Machine interface for kernel function and probe event.
408 *
409 * writer An instance of a mi writer.
410 * event single trace event.
411 *
412 * Returns zero if the element's value could be written.
413 * Negative values indicate an error.
414 */
415int mi_lttng_event_function_probe(struct mi_writer *writer,
416 struct lttng_event *event);
417
418/*
419 * Machine interface for kernel function entry event.
420 *
421 * writer An instance of a mi writer.
422 * event single trace event.
423 *
424 * Returns zero if the element's value could be written.
425 * Negative values indicate an error.
426 */
427int mi_lttng_event_function_entry(struct mi_writer *writer,
428 struct lttng_event *event);
429
430/*
431 * Machine interface: open an events element.
432 *
433 * writer An instance of a machine interface writer.
434 *
435 * Returns zero if the element's value could be written.
436 * Negative values indicate an error.
437 */
438int mi_lttng_events_open(struct mi_writer *writer);
439
440/*
441 * Machine interface for printing an event.
442 * The trace event type currently supported are:
443 * TRACEPOINT,
444 * PROBE,
445 * FUNCTION,
446 * FUNCTION_ENTRY,
447 * SYSCALL
448 *
449 * writer An instance of a mi writer.
450 * event single trace event.
451 * is_open Defines whether or not the session element shall be closed.
452 * This should be used carefully and the client
453 * must close the event element.
454 * Use case: nested additional information
455 *
456 * Returns zero if the element's value could be written.
457 * Negative values indicate an error.
458 */
459int mi_lttng_event(struct mi_writer *writer, struct lttng_event *event,
460 int is_open);
461
462/*
463 * Machine interface for struct lttng_event_field.
464 *
465 * writer An instance of a mi writer.
466 * field An event_field instance.
467 *
468 * Returns zero if the element's value could be written.
469 * Negative values indicate an error.
470 */
471int mi_lttng_event_field(struct mi_writer *writer,
472 struct lttng_event_field *field);
473
474/*
475 * Machine interface: open a event_fields element.
476 *
477 * writer An instance of a machine interface writer.
478 *
479 * Returns zero if the element's value could be written.
480 * Negative values indicate an error.
481 */
482int mi_lttng_event_fields_open(struct mi_writer *writer);
483
484/*
485 * Machine interface: open a PIDs element.
486 *
487 * writer An instance of a machine interface writer.
488 *
489 * Returns zero if the element's value could be written.
490 * Negative values indicate an error.
491 */
492int mi_lttng_pids_open(struct mi_writer *writer);
493
494/*
495 * Machine interface of a PID.
496 *
497 * writer An instance of a machine interface writer.
498 * pid A PID.
499 *
500 * is_open Defines whether or not the session element shall be closed.
501 * This should be used carefully and the client
502 * must close the pid element.
503 * Use case: nested addition information on a domain
504 * ex: channel event.
505 *
506 * Returns zero if the element's value could be written.
507 * Negative values indicate an error.
508 */
509int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
510 int is_open);
c7e35b03
JR
511
512#endif /* _MI_LTTNG_H */
This page took 0.043849 seconds and 5 git commands to generate.