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