Mi enable-channel 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;
65f25c66 58const char * const mi_lttng_element_command_destroy;
7e66b1b0 59const char * const mi_lttng_element_command_calibrate;
89b72577 60const char * const mi_lttng_element_command_add_context;
acc09215 61const char * const mi_lttng_element_command_enable_channels;
c7e35b03 62const char * const mi_lttng_element_command_output;
1734c658 63const char * const mi_lttng_element_command_success;
c7e35b03 64
1734c658 65/* Strings related to version command */
c7e35b03
JR
66const char * const mi_lttng_element_version;
67const char * const mi_lttng_element_version_str;
68const char * const mi_lttng_element_version_web;
69const char * const mi_lttng_element_version_major;
70const char * const mi_lttng_element_version_minor;
71const char * const mi_lttng_element_version_license;
314d5222 72const char * const mi_lttng_element_version_commit;
c7e35b03
JR
73const char * const mi_lttng_element_version_patch_level;
74const char * const mi_lttng_element_version_description;
75
5e18ec73
JR
76/* String related to a lttng_event_field */
77const char * const mi_lttng_element_event_field;
78const char * const mi_lttng_element_event_fields;
79
89b72577
JRJ
80/* String related to lttng_event_context */
81const char * const mi_lttng_context_type_perf_counter;
82const char * const mi_lttng_context_type_perf_cpu_counter;
83const char * const mi_lttng_context_type_perf_thread_counter;
84
85/* String related to lttng_event_perf_counter_ctx */
86const char * const mi_lttng_element_perf_counter_context;
87
5e18ec73
JR
88/* Strings related to pid */
89const char * const mi_lttng_element_pids;
90const char * const mi_lttng_element_pid;
91const char * const mi_lttng_element_pid_id;
92
1734c658
JRJ
93/* Strings related to save command */
94const char * const mi_lttng_element_save;
95
96/* Strings related to load command */
97const char * const mi_lttng_element_load;
98
5e18ec73
JR
99/* General element of mi_lttng */
100const char * const mi_lttng_element_type_other;
101const char * const mi_lttng_element_type_integer;
102const char * const mi_lttng_element_type_enum;
103const char * const mi_lttng_element_type_float;
104const char * const mi_lttng_element_type_string;
105const char * const mi_lttng_element_nowrite;
89b72577 106const char * const mi_lttng_element_success;
5e18ec73
JR
107
108/* String related to loglevel */
109const char * const mi_lttng_loglevel_str_alert;
110const char * const mi_lttng_loglevel_str_crit;
111const char * const mi_lttng_loglevel_str_debug;
112const char * const mi_lttng_loglevel_str_debug_function;
113const char * const mi_lttng_loglevel_str_debug_line;
114const char * const mi_lttng_loglevel_str_debug_module;
115const char * const mi_lttng_loglevel_str_debug_process;
116const char * const mi_lttng_loglevel_str_debug_program;
117const char * const mi_lttng_loglevel_str_debug_system;
118const char * const mi_lttng_loglevel_str_debug_unit;
119const char * const mi_lttng_loglevel_str_emerg;
120const char * const mi_lttng_loglevel_str_err;
121const char * const mi_lttng_loglevel_str_info;
122const char * const mi_lttng_loglevel_str_notice;
123const char * const mi_lttng_loglevel_str_unknown;
124const char * const mi_lttng_loglevel_str_warning;
125
1734c658 126/* String related to loglevel type */
5e18ec73
JR
127const char * const mi_lttng_loglevel_type_all;
128const char * const mi_lttng_loglevel_type_range;
129const char * const mi_lttng_loglevel_type_single;
130const char * const mi_lttng_loglevel_type_unknown;
131
7e66b1b0
JRJ
132/* Sting related to lttng_calibrate */
133const char * const mi_lttng_element_calibrate;
134const char * const mi_lttng_element_calibrate_function;
135
5e18ec73
JR
136/* Utility string function */
137const char *mi_lttng_loglevel_string(int value);
138const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value);
139const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value);
140const char *mi_lttng_domaintype_string(enum lttng_domain_type value);
141const char *mi_lttng_buffertype_string(enum lttng_buffer_type value);
7e66b1b0 142const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val);
5e18ec73 143
c7e35b03
JR
144/*
145 * Create an instance of a machine interface writer.
146 *
147 * fd_output File to which the XML content must be written. The file will be
148 * closed once the mi_writer has been destroyed.
149 *
150 * Returns an instance of a machine interface writer on success, NULL on
151 * error.
152 */
153struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type);
154
155/*
156 * Destroy an instance of a machine interface writer.
157 *
158 * writer An instance of a machine interface writer.
159 *
160 * Returns zero if the XML document could be closed cleanly. Negative values
161 * indicate an error.
162 */
163int mi_lttng_writer_destroy(struct mi_writer *writer);
164
165/*
166 * Open a command tag and add it's name node.
167 *
168 * writer An instance of a machine interface writer.
c7e35b03
JR
169 * command The command name.
170 *
171 * Returns zero if the XML document could be closed cleanly.
172 * Negative values indicate an error.
173 */
174int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command);
175
176/*
177 * Close a command tag.
178 *
179 * writer An instance of a machine interface writer.
180 *
181 * Returns zero if the XML document could be closed cleanly.
182 * Negative values indicate an error.
183 */
184int mi_lttng_writer_command_close(struct mi_writer *writer);
185
186/*
187 * Open an element tag.
188 *
189 * writer An instance of a machine interface writer.
c7e35b03
JR
190 * element_name Element tag name.
191 *
192 * Returns zero if the XML document could be closed cleanly.
193 * Negative values indicate an error.
194 */
195int mi_lttng_writer_open_element(struct mi_writer *writer,
196 const char *element_name);
197
198/*
199 * Close the current element tag.
200 *
201 * writer An instance of a machine interface writer.
202 *
203 * Returns zero if the XML document could be closed cleanly.
204 * Negative values indicate an error.
205 */
206int mi_lttng_writer_close_element(struct mi_writer *writer);
207
208/*
5e18ec73 209 * Close multiple element.
c7e35b03
JR
210 *
211 * writer An instance of a machine interface writer.
5e18ec73 212 * nb_element Number of elements.
c7e35b03 213 *
5e18ec73
JR
214 * Returns zero if the XML document could be closed cleanly.
215 * Negative values indicate an error.
216 */
217int mi_lttng_close_multi_element(struct mi_writer *writer,
218 unsigned int nb_element);
219
220/*
221 * Write an element of type unsigned int.
c7e35b03 222 *
5e18ec73
JR
223 * writer An instance of a machine interface writer.
224 * element_name Element name.
c7e35b03
JR
225 * value Unsigned int value of the element
226 *
227 * Returns zero if the element's value could be written.
228 * Negative values indicate an error.
229 */
230int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer,
231 const char *element_name, uint64_t value);
232
233/*
234 * Write an element of type signed int.
235 *
236 * writer An instance of a machine interface writer.
c7e35b03 237 * element_name Element name.
5e18ec73 238 * value Signed int value of the element.
c7e35b03
JR
239 *
240 * Returns zero if the element's value could be written.
241 * Negative values indicate an error.
242 */
243int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer,
244 const char *element_name, int64_t value);
245
246/*
247 * Write an element of type boolean.
248 *
249 * writer An instance of a machine interface writer.
c7e35b03 250 * element_name Element name.
5e18ec73 251 * value Boolean value of the element.
c7e35b03
JR
252 *
253 * Returns zero if the element's value could be written.
254 * Negative values indicate an error.
255 */
256int mi_lttng_writer_write_element_bool(struct mi_writer *writer,
257 const char *element_name, int value);
258
259/*
260 * Write an element of type string.
261 *
262 * writer An instance of a machine interface writer.
c7e35b03 263 * element_name Element name.
5e18ec73 264 * value String value of the element.
c7e35b03
JR
265 *
266 * Returns zero if the element's value could be written.
267 * Negative values indicate an error.
268 */
269int mi_lttng_writer_write_element_string(struct mi_writer *writer,
270 const char *element_name, const char *value);
271
272/*
273 * Machine interface of struct version.
274 *
275 * writer An instance of a machine interface writer.
c7e35b03 276 * version Version struct.
c7e35b03 277 * lttng_description String value of the version description.
c7e35b03
JR
278 * lttng_license String value of the version license.
279 *
280 * Returns zero if the element's value could be written.
281 * Negative values indicate an error.
282 */
283int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version,
284 const char *lttng_description, const char *lttng_license);
285
286/*
5e18ec73 287 * Machine interface: open a sessions element.
c7e35b03 288 *
5e18ec73 289 * writer An instance of a machine interface writer.
c7e35b03 290 *
5e18ec73
JR
291 * Returns zero if the element's value could be written.
292 * Negative values indicate an error.
293 */
294int mi_lttng_sessions_open(struct mi_writer *writer);
295
296/*
297 * Machine interface of struct session.
c7e35b03 298 *
5e18ec73
JR
299 * writer An instance of a machine interface writer.
300 * session An instance of a session.
301 * is_open Defines whether or not the session element shall be closed.
302 * This should be used carefully and the client
303 * must close the session element.
304 * Use case: nested addtionnal information on a session
c7e35b03 305 * ex: domain,channel event.
c7e35b03
JR
306 *
307 * Returns zero if the element's value could be written.
308 * Negative values indicate an error.
309 */
310int mi_lttng_session(struct mi_writer *writer,
5e18ec73
JR
311 struct lttng_session *session, int is_open);
312
313/*
314 * Machine interface: open a domains element.
315 *
316 * writer An instance of a machine interface writer.
317 *
318 * Returns zero if the element's value could be written.
319 * Negative values indicate an error.
320 */
321int mi_lttng_domains_open(struct mi_writer *writer);
322
323/*
324 * Machine interface of struct domain.
325 *
326 * writer An instance of a machine interface writer.
327 * domain An instance of a domain.
328 *
329 * is_open Defines whether or not the session element shall be closed.
330 * This should be used carefully and the client
331 * must close the domain element.
332 * Use case: nested addition information on a domain
333 * ex: channel event.
334 *
335 * Returns zero if the element's value could be written.
336 * Negative values indicate an error.
337 */
338int mi_lttng_domain(struct mi_writer *writer,
339 struct lttng_domain *domain, int is_open);
340
341/*
342 * Machine interface: open a channels element.
343 *
344 * writer An instance of a machine interface writer.
345 *
346 * Returns zero if the element's value could be written.
347 * Negative values indicate an error.
348 */
349int mi_lttng_channels_open(struct mi_writer *writer);
350
351/*
352 * Machine interface of struct channel.
353 *
354 * writer An instance of a machine interface writer.
355 * channel An instance of a channel.
356 *
357 * is_open Defines whether or not the session element shall be closed.
358 * This should be used carefully and the client
359 * must close the channel element.
360 * Use case: nested addition information on a channel.
361 * ex: channel event.
362 *
363 * Returns zero if the element's value could be written.
364 * Negative values indicate an error.
365 */
366int mi_lttng_channel(struct mi_writer *writer,
367 struct lttng_channel *channel, int is_open);
368
369/*
370 * Machine interface of struct channel_attr.
371 *
372 * writer An instance of a machine interface writer.
373 * attr An instance of a channel_attr struct.
374 *
375 * Returns zero if the element's value could be written.
376 * Negative values indicate an error.
377 */
378int mi_lttng_channel_attr(struct mi_writer *writer,
379 struct lttng_channel_attr *attr);
380
381/*
382* Machine interface for event common attributes.
383*
384* writer An instance of a mi writer.
385* event single trace event.
386*
387* The common attribute are:
388* - mi event element
389* - event name
390* - event type
391* - enabled tag
392* - event filter
393*
394* Returns zero if the element's value could be written.
395* Negative values indicate an error.
396*/
397int mi_lttng_event_common_attributes(struct mi_writer *writer,
398 struct lttng_event *event);
399
400/*
401 * Machine interface for kernel tracepoint event with a loglevel.
402 *
403 * writer An instance of a mi writer.
404 * event single trace event.
405 *
406 * Returns zero if the element's value could be written.
407 * Negative values indicate an error.
408 */
409int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer,
410 struct lttng_event *event);
411
412/*
413 * Machine interface for kernel tracepoint event with no loglevel.
414 *
415 * writer An instance of a mi writer.
416 * event single trace event.
417 *
418 * Returns zero if the element's value could be written.
419 * Negative values indicate an error.
420 */
421int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer,
422 struct lttng_event *event);
423
424/*
425 * Machine interface for kernel function and probe event.
426 *
427 * writer An instance of a mi writer.
428 * event single trace event.
429 *
430 * Returns zero if the element's value could be written.
431 * Negative values indicate an error.
432 */
433int mi_lttng_event_function_probe(struct mi_writer *writer,
434 struct lttng_event *event);
435
436/*
437 * Machine interface for kernel function entry event.
438 *
439 * writer An instance of a mi writer.
440 * event single trace event.
441 *
442 * Returns zero if the element's value could be written.
443 * Negative values indicate an error.
444 */
445int mi_lttng_event_function_entry(struct mi_writer *writer,
446 struct lttng_event *event);
447
448/*
449 * Machine interface: open an events element.
450 *
451 * writer An instance of a machine interface writer.
452 *
453 * Returns zero if the element's value could be written.
454 * Negative values indicate an error.
455 */
456int mi_lttng_events_open(struct mi_writer *writer);
457
458/*
459 * Machine interface for printing an event.
460 * The trace event type currently supported are:
461 * TRACEPOINT,
462 * PROBE,
463 * FUNCTION,
464 * FUNCTION_ENTRY,
465 * SYSCALL
466 *
467 * writer An instance of a mi writer.
468 * event single trace event.
469 * is_open Defines whether or not the session element shall be closed.
470 * This should be used carefully and the client
471 * must close the event element.
472 * Use case: nested additional information
473 *
474 * Returns zero if the element's value could be written.
475 * Negative values indicate an error.
476 */
477int mi_lttng_event(struct mi_writer *writer, struct lttng_event *event,
478 int is_open);
479
480/*
481 * Machine interface for struct lttng_event_field.
482 *
483 * writer An instance of a mi writer.
484 * field An event_field instance.
485 *
486 * Returns zero if the element's value could be written.
487 * Negative values indicate an error.
488 */
489int mi_lttng_event_field(struct mi_writer *writer,
490 struct lttng_event_field *field);
491
492/*
493 * Machine interface: open a event_fields element.
494 *
495 * writer An instance of a machine interface writer.
496 *
89b72577 497 * Returns zero if the element could be written.
5e18ec73
JR
498 * Negative values indicate an error.
499 */
500int mi_lttng_event_fields_open(struct mi_writer *writer);
501
502/*
503 * Machine interface: open a PIDs element.
504 *
505 * writer An instance of a machine interface writer.
506 *
507 * Returns zero if the element's value could be written.
508 * Negative values indicate an error.
509 */
510int mi_lttng_pids_open(struct mi_writer *writer);
511
512/*
513 * Machine interface of a PID.
514 *
515 * writer An instance of a machine interface writer.
516 * pid A PID.
517 *
518 * is_open Defines whether or not the session element shall be closed.
519 * This should be used carefully and the client
520 * must close the pid element.
521 * Use case: nested addition information on a domain
522 * ex: channel event.
523 *
524 * Returns zero if the element's value could be written.
525 * Negative values indicate an error.
526 */
527int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
528 int is_open);
c7e35b03 529
7e66b1b0
JRJ
530/*
531 * Machine interface for struct lttng_calibrate.
532 *
533 * writer An instance of a machine interface writer.
534 *
535 * calibrate A lttng_calibrate instance.
536 *
537 * Returns zero if the element's value could be written.
538 * Negative values indicate an error.
539 */
540int mi_lttng_calibrate(struct mi_writer *writer,
541 struct lttng_calibrate *calibrate);
542
89b72577
JRJ
543/*
544 * Machine interface of a context.
545 *
546 * writer An instance of a machine interface writer
547 *
548 * context An instance of a lttng_event_context
549 *
550 * is_open Define if we close the context element
551 * This should be used carefully and the client
552 * need to close the context element.
553 * 0-> False
554 * 1-> True
555 * Returns zero if the element's value could be written.
556 * Negative values indicate an error.
557 */
558int mi_lttng_context(struct mi_writer *writer,
559 struct lttng_event_context *context, int is_open);
560
561/*
562 * Machine interface of a perf_counter_context.
563 *
564 * writer An instance of a machine interface writer
565 *
566 * contest An instance of a lttng_event_perf_counter_ctx
567 *
568 * Returns zero if the element's value could be written.
569 * Negative values indicate an error.
570 */
571int mi_lttng_perf_counter_context(struct mi_writer *writer,
572 struct lttng_event_perf_counter_ctx *perf_context);
573
c7e35b03 574#endif /* _MI_LTTNG_H */
This page took 0.044439 seconds and 4 git commands to generate.