6215df56734414b21d360bd7233e15c91a947d66
[lttng-tools.git] / src / common / mi-lttng.h
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 /* Don't want to reference snapshot-internal.h here */
30 struct lttng_snapshot_output;
31
32 /* Instance of a machine interface writer. */
33 struct mi_writer {
34 struct config_writer *writer;
35 enum lttng_mi_output_type type;
36 };
37
38 /*
39 * Version information for the machine interface.
40 */
41 struct mi_lttng_version {
42 char version[NAME_MAX]; /* Version number of package */
43 uint32_t version_major; /* LTTng-Tools major version number */
44 uint32_t version_minor; /* LTTng-Tools minor version number */
45 uint32_t version_patchlevel; /* LTTng-Tools patchlevel version number */
46 char version_commit[NAME_MAX]; /* Commit hash of the current version */
47 char version_name[NAME_MAX];
48 char package_url[NAME_MAX]; /* Define to the home page for this package. */
49 };
50
51 /* Strings related to command */
52 const char * const mi_lttng_element_command;
53 const char * const mi_lttng_element_command_name;
54 const char * const mi_lttng_element_command_action;
55 const char * const mi_lttng_element_command_version;
56 const char * const mi_lttng_element_command_enable_event;
57 const char * const mi_lttng_element_command_list;
58 const char * const mi_lttng_element_command_save;
59 const char * const mi_lttng_element_command_load;
60 const char * const mi_lttng_element_command_stop;
61 const char * const mi_lttng_element_command_start;
62 const char * const mi_lttng_element_command_create;
63 const char * const mi_lttng_element_command_destroy;
64 const char * const mi_lttng_element_command_calibrate;
65 const char * const mi_lttng_element_command_add_context;
66 const char * const mi_lttng_element_command_enable_channels;
67 const char * const mi_lttng_element_command_set_session;
68 const char * const mi_lttng_element_command_disable_event;
69 const char * const mi_lttng_element_command_disable_channel;
70 const char * const mi_lttng_element_command_snapshot;
71 const char * const mi_lttng_element_command_list_snapshot;
72 const char * const mi_lttng_element_command_del_snapshot;
73 const char * const mi_lttng_element_command_add_snapshot;
74 const char * const mi_lttng_element_command_record_snapshot;
75 const char * const mi_lttng_element_command_output;
76 const char * const mi_lttng_element_command_success;
77
78 /* Strings related to version command */
79 const char * const mi_lttng_element_version;
80 const char * const mi_lttng_element_version_str;
81 const char * const mi_lttng_element_version_web;
82 const char * const mi_lttng_element_version_major;
83 const char * const mi_lttng_element_version_minor;
84 const char * const mi_lttng_element_version_license;
85 const char * const mi_lttng_element_version_commit;
86 const char * const mi_lttng_element_version_patch_level;
87 const char * const mi_lttng_element_version_description;
88
89 /* String related to a lttng_event_field */
90 const char * const mi_lttng_element_event_field;
91 const char * const mi_lttng_element_event_fields;
92
93 /* String related to lttng_event_context */
94 const char * const mi_lttng_context_type_perf_counter;
95 const char * const mi_lttng_context_type_perf_cpu_counter;
96 const char * const mi_lttng_context_type_perf_thread_counter;
97
98 /* String related to lttng_event_perf_counter_ctx */
99 const char * const mi_lttng_element_perf_counter_context;
100
101 /* Strings related to pid */
102 const char * const mi_lttng_element_pids;
103 const char * const mi_lttng_element_pid;
104 const char * const mi_lttng_element_pid_id;
105
106 /* Strings related to save command */
107 const char * const mi_lttng_element_save;
108
109 /* Strings related to load command */
110 const char * const mi_lttng_element_load;
111
112 /* General element of mi_lttng */
113 const char * const mi_lttng_element_type_other;
114 const char * const mi_lttng_element_type_integer;
115 const char * const mi_lttng_element_type_enum;
116 const char * const mi_lttng_element_type_float;
117 const char * const mi_lttng_element_type_string;
118 const char * const mi_lttng_element_nowrite;
119 const char * const mi_lttng_element_success;
120
121 /* String related to loglevel */
122 const char * const mi_lttng_loglevel_str_alert;
123 const char * const mi_lttng_loglevel_str_crit;
124 const char * const mi_lttng_loglevel_str_debug;
125 const char * const mi_lttng_loglevel_str_debug_function;
126 const char * const mi_lttng_loglevel_str_debug_line;
127 const char * const mi_lttng_loglevel_str_debug_module;
128 const char * const mi_lttng_loglevel_str_debug_process;
129 const char * const mi_lttng_loglevel_str_debug_program;
130 const char * const mi_lttng_loglevel_str_debug_system;
131 const char * const mi_lttng_loglevel_str_debug_unit;
132 const char * const mi_lttng_loglevel_str_emerg;
133 const char * const mi_lttng_loglevel_str_err;
134 const char * const mi_lttng_loglevel_str_info;
135 const char * const mi_lttng_loglevel_str_notice;
136 const char * const mi_lttng_loglevel_str_unknown;
137 const char * const mi_lttng_loglevel_str_warning;
138
139 /* String related to loglevel type */
140 const char * const mi_lttng_loglevel_type_all;
141 const char * const mi_lttng_loglevel_type_range;
142 const char * const mi_lttng_loglevel_type_single;
143 const char * const mi_lttng_loglevel_type_unknown;
144
145 /* Sting related to lttng_calibrate */
146 const char * const mi_lttng_element_calibrate;
147 const char * const mi_lttng_element_calibrate_function;
148
149 /* String related to a lttng_snashot */
150 const char * const mi_lttng_element_snapshots;
151 const char * const mi_lttng_element_snapshot_session_name;
152 const char * const mi_lttng_element_snapshot_n_ptr;
153 const char * const mi_lttng_element_snapshot_data_url;
154 const char * const mi_lttng_element_snapshot_ctrl_url;
155 const char * const mi_lttng_element_snapshot_max_size;
156
157 /* Utility string function */
158 const char *mi_lttng_loglevel_string(int value);
159 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value);
160 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value);
161 const char *mi_lttng_domaintype_string(enum lttng_domain_type value);
162 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value);
163 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val);
164
165 /*
166 * Create an instance of a machine interface writer.
167 *
168 * fd_output File to which the XML content must be written. The file will be
169 * closed once the mi_writer has been destroyed.
170 *
171 * Returns an instance of a machine interface writer on success, NULL on
172 * error.
173 */
174 struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type);
175
176 /*
177 * Destroy an instance of a machine interface writer.
178 *
179 * writer An instance of a machine interface writer.
180 *
181 * Returns zero if the XML document could be closed cleanly. Negative values
182 * indicate an error.
183 */
184 int mi_lttng_writer_destroy(struct mi_writer *writer);
185
186 /*
187 * Open a command tag and add it's name node.
188 *
189 * writer An instance of a machine interface writer.
190 * command The command name.
191 *
192 * Returns zero if the XML document could be closed cleanly.
193 * Negative values indicate an error.
194 */
195 int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command);
196
197 /*
198 * Close a command tag.
199 *
200 * writer An instance of a machine interface writer.
201 *
202 * Returns zero if the XML document could be closed cleanly.
203 * Negative values indicate an error.
204 */
205 int mi_lttng_writer_command_close(struct mi_writer *writer);
206
207 /*
208 * Open an element tag.
209 *
210 * writer An instance of a machine interface writer.
211 * element_name Element tag name.
212 *
213 * Returns zero if the XML document could be closed cleanly.
214 * Negative values indicate an error.
215 */
216 int mi_lttng_writer_open_element(struct mi_writer *writer,
217 const char *element_name);
218
219 /*
220 * Close the current element tag.
221 *
222 * writer An instance of a machine interface writer.
223 *
224 * Returns zero if the XML document could be closed cleanly.
225 * Negative values indicate an error.
226 */
227 int mi_lttng_writer_close_element(struct mi_writer *writer);
228
229 /*
230 * Close multiple element.
231 *
232 * writer An instance of a machine interface writer.
233 * nb_element Number of elements.
234 *
235 * Returns zero if the XML document could be closed cleanly.
236 * Negative values indicate an error.
237 */
238 int mi_lttng_close_multi_element(struct mi_writer *writer,
239 unsigned int nb_element);
240
241 /*
242 * Write an element of type unsigned int.
243 *
244 * writer An instance of a machine interface writer.
245 * element_name Element name.
246 * value Unsigned int value of the element
247 *
248 * Returns zero if the element's value could be written.
249 * Negative values indicate an error.
250 */
251 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer,
252 const char *element_name, uint64_t value);
253
254 /*
255 * Write an element of type signed int.
256 *
257 * writer An instance of a machine interface writer.
258 * element_name Element name.
259 * value Signed int value of the element.
260 *
261 * Returns zero if the element's value could be written.
262 * Negative values indicate an error.
263 */
264 int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer,
265 const char *element_name, int64_t value);
266
267 /*
268 * Write an element of type boolean.
269 *
270 * writer An instance of a machine interface writer.
271 * element_name Element name.
272 * value Boolean value of the element.
273 *
274 * Returns zero if the element's value could be written.
275 * Negative values indicate an error.
276 */
277 int mi_lttng_writer_write_element_bool(struct mi_writer *writer,
278 const char *element_name, int value);
279
280 /*
281 * Write an element of type string.
282 *
283 * writer An instance of a machine interface writer.
284 * element_name Element name.
285 * value String value of the element.
286 *
287 * Returns zero if the element's value could be written.
288 * Negative values indicate an error.
289 */
290 int mi_lttng_writer_write_element_string(struct mi_writer *writer,
291 const char *element_name, const char *value);
292
293 /*
294 * Machine interface of struct version.
295 *
296 * writer An instance of a machine interface writer.
297 * version Version struct.
298 * lttng_description String value of the version description.
299 * lttng_license String value of the version license.
300 *
301 * Returns zero if the element's value could be written.
302 * Negative values indicate an error.
303 */
304 int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version,
305 const char *lttng_description, const char *lttng_license);
306
307 /*
308 * Machine interface: open a sessions element.
309 *
310 * writer An instance of a machine interface writer.
311 *
312 * Returns zero if the element's value could be written.
313 * Negative values indicate an error.
314 */
315 int mi_lttng_sessions_open(struct mi_writer *writer);
316
317 /*
318 * Machine interface of struct session.
319 *
320 * writer An instance of a machine interface writer.
321 * session An instance of a session.
322 * is_open Defines whether or not the session element shall be closed.
323 * This should be used carefully and the client
324 * must close the session element.
325 * Use case: nested addtionnal information on a session
326 * ex: domain,channel event.
327 *
328 * Returns zero if the element's value could be written.
329 * Negative values indicate an error.
330 */
331 int mi_lttng_session(struct mi_writer *writer,
332 struct lttng_session *session, int is_open);
333
334 /*
335 * Machine interface: open a domains element.
336 *
337 * writer An instance of a machine interface writer.
338 *
339 * Returns zero if the element's value could be written.
340 * Negative values indicate an error.
341 */
342 int mi_lttng_domains_open(struct mi_writer *writer);
343
344 /*
345 * Machine interface of struct domain.
346 *
347 * writer An instance of a machine interface writer.
348 * domain An instance of a domain.
349 *
350 * is_open Defines whether or not the session element shall be closed.
351 * This should be used carefully and the client
352 * must close the domain element.
353 * Use case: nested addition information on a domain
354 * ex: channel event.
355 *
356 * Returns zero if the element's value could be written.
357 * Negative values indicate an error.
358 */
359 int mi_lttng_domain(struct mi_writer *writer,
360 struct lttng_domain *domain, int is_open);
361
362 /*
363 * Machine interface: open a channels element.
364 *
365 * writer An instance of a machine interface writer.
366 *
367 * Returns zero if the element's value could be written.
368 * Negative values indicate an error.
369 */
370 int mi_lttng_channels_open(struct mi_writer *writer);
371
372 /*
373 * Machine interface of struct channel.
374 *
375 * writer An instance of a machine interface writer.
376 * channel An instance of a channel.
377 *
378 * is_open Defines whether or not the session element shall be closed.
379 * This should be used carefully and the client
380 * must close the channel element.
381 * Use case: nested addition information on a channel.
382 * ex: channel event.
383 *
384 * Returns zero if the element's value could be written.
385 * Negative values indicate an error.
386 */
387 int mi_lttng_channel(struct mi_writer *writer,
388 struct lttng_channel *channel, int is_open);
389
390 /*
391 * Machine interface of struct channel_attr.
392 *
393 * writer An instance of a machine interface writer.
394 * attr An instance of a channel_attr struct.
395 *
396 * Returns zero if the element's value could be written.
397 * Negative values indicate an error.
398 */
399 int mi_lttng_channel_attr(struct mi_writer *writer,
400 struct lttng_channel_attr *attr);
401
402 /*
403 * Machine interface for event common attributes.
404 *
405 * writer An instance of a mi writer.
406 * event single trace event.
407 *
408 * The common attribute are:
409 * - mi event element
410 * - event name
411 * - event type
412 * - enabled tag
413 * - event filter
414 *
415 * Returns zero if the element's value could be written.
416 * Negative values indicate an error.
417 */
418 int mi_lttng_event_common_attributes(struct mi_writer *writer,
419 struct lttng_event *event);
420
421 /*
422 * Machine interface for kernel tracepoint event with a loglevel.
423 *
424 * writer An instance of a mi writer.
425 * event single trace event.
426 *
427 * Returns zero if the element's value could be written.
428 * Negative values indicate an error.
429 */
430 int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer,
431 struct lttng_event *event);
432
433 /*
434 * Machine interface for kernel tracepoint event with no loglevel.
435 *
436 * writer An instance of a mi writer.
437 * event single trace event.
438 *
439 * Returns zero if the element's value could be written.
440 * Negative values indicate an error.
441 */
442 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer,
443 struct lttng_event *event);
444
445 /*
446 * Machine interface for kernel function and probe event.
447 *
448 * writer An instance of a mi writer.
449 * event single trace event.
450 *
451 * Returns zero if the element's value could be written.
452 * Negative values indicate an error.
453 */
454 int mi_lttng_event_function_probe(struct mi_writer *writer,
455 struct lttng_event *event);
456
457 /*
458 * Machine interface for kernel function entry event.
459 *
460 * writer An instance of a mi writer.
461 * event single trace event.
462 *
463 * Returns zero if the element's value could be written.
464 * Negative values indicate an error.
465 */
466 int mi_lttng_event_function_entry(struct mi_writer *writer,
467 struct lttng_event *event);
468
469 /*
470 * Machine interface: open an events element.
471 *
472 * writer An instance of a machine interface writer.
473 *
474 * Returns zero if the element's value could be written.
475 * Negative values indicate an error.
476 */
477 int mi_lttng_events_open(struct mi_writer *writer);
478
479 /*
480 * Machine interface for printing an event.
481 * The trace event type currently supported are:
482 * TRACEPOINT,
483 * PROBE,
484 * FUNCTION,
485 * FUNCTION_ENTRY,
486 * SYSCALL
487 *
488 * writer An instance of a mi writer.
489 * event single trace event.
490 * is_open Defines whether or not the session element shall be closed.
491 * This should be used carefully and the client
492 * must close the event element.
493 * Use case: nested additional information
494 *
495 * Returns zero if the element's value could be written.
496 * Negative values indicate an error.
497 */
498 int mi_lttng_event(struct mi_writer *writer, struct lttng_event *event,
499 int is_open);
500
501 /*
502 * Machine interface for struct lttng_event_field.
503 *
504 * writer An instance of a mi writer.
505 * field An event_field instance.
506 *
507 * Returns zero if the element's value could be written.
508 * Negative values indicate an error.
509 */
510 int mi_lttng_event_field(struct mi_writer *writer,
511 struct lttng_event_field *field);
512
513 /*
514 * Machine interface: open a event_fields element.
515 *
516 * writer An instance of a machine interface writer.
517 *
518 * Returns zero if the element have be written.
519 * Negative values indicate an error.
520 */
521 int mi_lttng_event_fields_open(struct mi_writer *writer);
522
523 /*
524 * Machine interface: open a PIDs element.
525 *
526 * writer An instance of a machine interface writer.
527 *
528 * Returns zero if the element's value could be written.
529 * Negative values indicate an error.
530 */
531 int mi_lttng_pids_open(struct mi_writer *writer);
532
533 /*
534 * Machine interface of a PID.
535 *
536 * writer An instance of a machine interface writer.
537 * pid A PID.
538 *
539 * is_open Defines whether or not the session element shall be closed.
540 * This should be used carefully and the client
541 * must close the pid element.
542 * Use case: nested addition information on a domain
543 * ex: channel event.
544 *
545 * Returns zero if the element's value could be written.
546 * Negative values indicate an error.
547 */
548 int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
549 int is_open);
550
551 /*
552 * Machine interface for struct lttng_calibrate.
553 *
554 * writer An instance of a machine interface writer.
555 *
556 * calibrate A lttng_calibrate instance.
557 *
558 * Returns zero if the element's value could be written.
559 * Negative values indicate an error.
560 */
561 int mi_lttng_calibrate(struct mi_writer *writer,
562 struct lttng_calibrate *calibrate);
563
564 /*
565 * Machine interface of a context.
566 *
567 * writer An instance of a machine interface writer
568 *
569 * context An instance of a lttng_event_context
570 *
571 * is_open Define if we close the context element
572 * This should be used carefully and the client
573 * need to close the context element.
574 * Returns zero if the element's value could be written.
575 * Negative values indicate an error.
576 */
577 int mi_lttng_context(struct mi_writer *writer,
578 struct lttng_event_context *context, int is_open);
579
580 /*
581 * Machine interface of a perf_counter_context.
582 *
583 * writer An instance of a machine interface writer
584 *
585 * contest An instance of a lttng_event_perf_counter_ctx
586 *
587 * Returns zero if the element's value could be written.
588 * Negative values indicate an error.
589 */
590 int mi_lttng_perf_counter_context(struct mi_writer *writer,
591 struct lttng_event_perf_counter_ctx *perf_context);
592
593 /*
594 * Machine interface of the snapshot list_output.
595 * It specifies the session for which we are listing snapshots,
596 * and it opens a snapshots element to list a sequence
597 * of snapshots.
598 *
599 * writer An instance of a machine interface writer.
600 *
601 * session_name: Snapshot output for session "session_name".
602 *
603 * Note: The client has to close the session and the snapshots elements after
604 * having listed every lttng_snapshot_output.
605 *
606 * Returns zero if the element's value could be written.
607 * Negative values indicate an error.
608 */
609 int mi_lttng_snapshot_output_session_name(struct mi_writer *writer,
610 const char *session_name);
611
612 /*
613 * Machine interface of the snapshot output.
614 * The machine interface serializes the following attributes:
615 * - id: ID of the snapshot output.
616 * - name: Name of the output.
617 * - data_url : Destination of the output.
618 * - ctrl_url: Destination of the output.
619 * - max_size: total size of all stream combined.
620 *
621 * writer An instance of a machine interface writer.
622 *
623 * output: A list of snapshot_output.
624 *
625 * Returns zero if the element's value could be written.
626 * Negative values indicate an error.
627 */
628 int mi_lttng_snapshot_list_output(struct mi_writer *writer,
629 struct lttng_snapshot_output *output);
630
631 /*
632 * Machine interface of the output of the command snapshot del output
633 * when deleting a snapshot either by id or by name.
634 * If the snapshot was found and successfully deleted using its id,
635 * it return the id of the snapshot and the current session name on which it
636 * was attached.
637 *
638 * Otherwise, it do the same process with the name of the snapshot, if the
639 * snapshot output id is undefined.
640 *
641 * writer An instance of a machine interface writer.
642 *
643 * id: ID of the snapshot output.
644 *
645 * name: Name of the snapshot.
646 *
647 * current_session_name: Session to which the snapshot belongs.
648 *
649 * Returns zero if the element's value could be written.
650 * Negative values indicate an error.
651 */
652 int mi_lttng_snapshot_del_output(struct mi_writer *writer, int id,
653 const char *name, const char *current_session_name);
654
655 /*
656 * Machine interface of the output of the command snapshot add output
657 * when adding a snapshot from a user URL.
658 *
659 * If the snapshot was successfully added, the machine interface lists
660 * these information:
661 * - id: ID of the newly add snapshot output.
662 * - current_session_name: Name of the session to which the output was added.
663 * - ctrl_url: Destination of the output.
664 * - max_size: total size of all stream combined.
665 *
666 * writer An instance of a machine interface writer.
667 *
668 * current_session_name: Session to which the snapshot belongs.
669 *
670 * n_ptr:
671 *
672 * output: iterator over a lttng_snapshot_output_list which contain
673 * the snapshot output informations.
674 *
675 * Returns zero if the element's value could be written.
676 * Negative values indicate an error.
677 */
678 int mi_lttng_snapshot_add_output(struct mi_writer *writer,
679 const char *current_session_name, const char *n_ptr,
680 struct lttng_snapshot_output *output);
681
682 /*
683 * Machine interface of the output of the command snapshot
684 * record from a URL (if given).
685 *
686 * If the snapshot is successfully recorded from a url, the machine interface
687 * output the following information:
688 * - url: Destination of the output stored in the snapshot.
689 *
690 * Otherwise, the machine interface output the data and ctrl url received
691 * from the command-line.
692 *
693 * writer An instance of a machine interface writer.
694 *
695 * current_session_name: Snapshot record for session "current_session_name".
696 *
697 * ctrl_url, data_url: Destination of the output receive from the command-line.
698 *
699 * Returns zero if the element's value could be written.
700 * Negative values indicate an error.
701 */
702 int mi_lttng_snapshot_record(struct mi_writer *writer,
703 const char *current_session_name, const char *url,
704 const char *cmdline_ctrl_url, const char *cmdline_data_url);
705
706 #endif /* _MI_LTTNG_H */
This page took 0.043198 seconds and 4 git commands to generate.