2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
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.
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
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.
24 #include <common/error.h>
25 #include <common/macros.h>
26 #include <common/config/config.h>
27 #include <lttng/lttng.h>
29 /* Don't want to reference snapshot-internal.h here */
30 struct lttng_snapshot_output
;
32 /* Instance of a machine interface writer. */
34 struct config_writer
*writer
;
35 enum lttng_mi_output_type type
;
39 * Version information for the machine interface.
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. */
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_track
;
77 const char * const mi_lttng_element_command_untrack
;
78 const char * const mi_lttng_element_command_version
;
80 /* Strings related to version command */
81 const char * const mi_lttng_element_version
;
82 const char * const mi_lttng_element_version_commit
;
83 const char * const mi_lttng_element_version_description
;
84 const char * const mi_lttng_element_version_license
;
85 const char * const mi_lttng_element_version_major
;
86 const char * const mi_lttng_element_version_minor
;
87 const char * const mi_lttng_element_version_patch_level
;
88 const char * const mi_lttng_element_version_str
;
89 const char * const mi_lttng_element_version_web
;
91 /* String related to a lttng_event_field */
92 const char * const mi_lttng_element_event_field
;
93 const char * const mi_lttng_element_event_fields
;
95 /* String related to lttng_event_context */
96 const char * const mi_lttng_context_type_perf_counter
;
97 const char * const mi_lttng_context_type_perf_cpu_counter
;
98 const char * const mi_lttng_context_type_perf_thread_counter
;
100 /* String related to lttng_event_perf_counter_ctx */
101 const char * const mi_lttng_element_perf_counter_context
;
103 /* Strings related to pid */
104 const char * const mi_lttng_element_pids
;
105 const char * const mi_lttng_element_pid
;
106 const char * const mi_lttng_element_pid_id
;
108 /* Strings related to save command */
109 const char * const mi_lttng_element_save
;
111 /* Strings related to load command */
112 const char * const mi_lttng_element_load
;
114 /* General element of mi_lttng */
115 const char * const mi_lttng_element_empty
;
116 const char * const mi_lttng_element_id
;
117 const char * const mi_lttng_element_nowrite
;
118 const char * const mi_lttng_element_success
;
119 const char * const mi_lttng_element_type_enum
;
120 const char * const mi_lttng_element_type_float
;
121 const char * const mi_lttng_element_type_integer
;
122 const char * const mi_lttng_element_type_other
;
123 const char * const mi_lttng_element_type_string
;
125 /* String related to loglevel */
126 const char * const mi_lttng_loglevel_str_alert
;
127 const char * const mi_lttng_loglevel_str_crit
;
128 const char * const mi_lttng_loglevel_str_debug
;
129 const char * const mi_lttng_loglevel_str_debug_function
;
130 const char * const mi_lttng_loglevel_str_debug_line
;
131 const char * const mi_lttng_loglevel_str_debug_module
;
132 const char * const mi_lttng_loglevel_str_debug_process
;
133 const char * const mi_lttng_loglevel_str_debug_program
;
134 const char * const mi_lttng_loglevel_str_debug_system
;
135 const char * const mi_lttng_loglevel_str_debug_unit
;
136 const char * const mi_lttng_loglevel_str_emerg
;
137 const char * const mi_lttng_loglevel_str_err
;
138 const char * const mi_lttng_loglevel_str_info
;
139 const char * const mi_lttng_loglevel_str_notice
;
140 const char * const mi_lttng_loglevel_str_unknown
;
141 const char * const mi_lttng_loglevel_str_warning
;
143 /* String related to loglevel JUL */
144 const char * const mi_lttng_loglevel_str_jul_all
;
145 const char * const mi_lttng_loglevel_str_jul_config
;
146 const char * const mi_lttng_loglevel_str_jul_fine
;
147 const char * const mi_lttng_loglevel_str_jul_finer
;
148 const char * const mi_lttng_loglevel_str_jul_finest
;
149 const char * const mi_lttng_loglevel_str_jul_info
;
150 const char * const mi_lttng_loglevel_str_jul_off
;
151 const char * const mi_lttng_loglevel_str_jul_severe
;
152 const char * const mi_lttng_loglevel_str_jul_warning
;
154 /* String related to loglevel Log4j */
155 const char * const mi_lttng_loglevel_str_log4j_off
;
156 const char * const mi_lttng_loglevel_str_log4j_fatal
;
157 const char * const mi_lttng_loglevel_str_log4j_error
;
158 const char * const mi_lttng_loglevel_str_log4j_warn
;
159 const char * const mi_lttng_loglevel_str_log4j_info
;
160 const char * const mi_lttng_loglevel_str_log4j_debug
;
161 const char * const mi_lttng_loglevel_str_log4j_trace
;
162 const char * const mi_lttng_loglevel_str_log4j_all
;
164 /* String related to loglevel Python */
165 const char * const mi_lttng_loglevel_str_python_critical
;
166 const char * const mi_lttng_loglevel_str_python_error
;
167 const char * const mi_lttng_loglevel_str_python_warning
;
168 const char * const mi_lttng_loglevel_str_python_info
;
169 const char * const mi_lttng_loglevel_str_python_debug
;
170 const char * const mi_lttng_loglevel_str_python_notset
;
172 /* String related to loglevel type */
173 const char * const mi_lttng_loglevel_type_all
;
174 const char * const mi_lttng_loglevel_type_range
;
175 const char * const mi_lttng_loglevel_type_single
;
176 const char * const mi_lttng_loglevel_type_unknown
;
178 /* Sting related to lttng_calibrate */
179 const char * const mi_lttng_element_calibrate
;
180 const char * const mi_lttng_element_calibrate_function
;
182 /* String related to a lttng_snapshot */
183 const char * const mi_lttng_element_snapshot_ctrl_url
;
184 const char * const mi_lttng_element_snapshot_data_url
;
185 const char * const mi_lttng_element_snapshot_max_size
;
186 const char * const mi_lttng_element_snapshot_n_ptr
;
187 const char * const mi_lttng_element_snapshot_session_name
;
188 const char * const mi_lttng_element_snapshots
;
190 /* Utility string function */
191 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
);
192 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
193 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
194 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
195 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
196 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
);
199 * Create an instance of a machine interface writer.
201 * fd_output File to which the XML content must be written. The file will be
202 * closed once the mi_writer has been destroyed.
204 * Returns an instance of a machine interface writer on success, NULL on
207 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
210 * Destroy an instance of a machine interface writer.
212 * writer An instance of a machine interface writer.
214 * Returns zero if the XML document could be closed cleanly. Negative values
217 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
220 * Open a command tag and add it's name node.
222 * writer An instance of a machine interface writer.
223 * command The command name.
225 * Returns zero if the XML document could be closed cleanly.
226 * Negative values indicate an error.
228 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
231 * Close a command tag.
233 * writer An instance of a machine interface writer.
235 * Returns zero if the XML document could be closed cleanly.
236 * Negative values indicate an error.
238 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
241 * Open an element tag.
243 * writer An instance of a machine interface writer.
244 * element_name Element tag name.
246 * Returns zero if the XML document could be closed cleanly.
247 * Negative values indicate an error.
249 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
250 const char *element_name
);
253 * Close the current element tag.
255 * writer An instance of a machine interface writer.
257 * Returns zero if the XML document could be closed cleanly.
258 * Negative values indicate an error.
260 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
263 * Close multiple element.
265 * writer An instance of a machine interface writer.
266 * nb_element Number of elements.
268 * Returns zero if the XML document could be closed cleanly.
269 * Negative values indicate an error.
271 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
272 unsigned int nb_element
);
275 * Write an element of type unsigned int.
277 * writer An instance of a machine interface writer.
278 * element_name Element name.
279 * value Unsigned int value of the element
281 * Returns zero if the element's value could be written.
282 * Negative values indicate an error.
284 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
285 const char *element_name
, uint64_t value
);
288 * Write an element of type signed int.
290 * writer An instance of a machine interface writer.
291 * element_name Element name.
292 * value Signed int value of the element.
294 * Returns zero if the element's value could be written.
295 * Negative values indicate an error.
297 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
298 const char *element_name
, int64_t value
);
301 * Write an element of type boolean.
303 * writer An instance of a machine interface writer.
304 * element_name Element name.
305 * value Boolean value of the element.
307 * Returns zero if the element's value could be written.
308 * Negative values indicate an error.
310 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
311 const char *element_name
, int value
);
314 * Write an element of type string.
316 * writer An instance of a machine interface writer.
317 * element_name Element name.
318 * value String value of the element.
320 * Returns zero if the element's value could be written.
321 * Negative values indicate an error.
323 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
324 const char *element_name
, const char *value
);
327 * Machine interface of struct version.
329 * writer An instance of a machine interface writer.
330 * version Version struct.
331 * lttng_description String value of the version description.
332 * lttng_license String value of the version license.
334 * Returns zero if the element's value could be written.
335 * Negative values indicate an error.
337 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
338 const char *lttng_description
, const char *lttng_license
);
341 * Machine interface: open a sessions element.
343 * writer An instance of a machine interface writer.
345 * Returns zero if the element's value could be written.
346 * Negative values indicate an error.
348 int mi_lttng_sessions_open(struct mi_writer
*writer
);
351 * Machine interface of struct session.
353 * writer An instance of a machine interface writer.
354 * session An instance of a session.
355 * is_open Defines whether or not the session element shall be closed.
356 * This should be used carefully and the client
357 * must close the session element.
358 * Use case: nested additional information on a session
359 * ex: domain,channel event.
361 * Returns zero if the element's value could be written.
362 * Negative values indicate an error.
364 int mi_lttng_session(struct mi_writer
*writer
,
365 struct lttng_session
*session
, int is_open
);
368 * Machine interface: open a domains element.
370 * writer An instance of a machine interface writer.
372 * Returns zero if the element's value could be written.
373 * Negative values indicate an error.
375 int mi_lttng_domains_open(struct mi_writer
*writer
);
378 * Machine interface of struct domain.
380 * writer An instance of a machine interface writer.
381 * domain An instance of a domain.
383 * is_open Defines whether or not the session element shall be closed.
384 * This should be used carefully and the client
385 * must close the domain element.
386 * Use case: nested addition information on a domain
389 * Returns zero if the element's value could be written.
390 * Negative values indicate an error.
392 int mi_lttng_domain(struct mi_writer
*writer
,
393 struct lttng_domain
*domain
, int is_open
);
396 * Machine interface: open a channels element.
398 * writer An instance of a machine interface writer.
400 * Returns zero if the element's value could be written.
401 * Negative values indicate an error.
403 int mi_lttng_channels_open(struct mi_writer
*writer
);
406 * Machine interface of struct channel.
408 * writer An instance of a machine interface writer.
409 * channel An instance of a channel.
411 * is_open Defines whether or not the session element shall be closed.
412 * This should be used carefully and the client
413 * must close the channel element.
414 * Use case: nested addition information on a channel.
417 * Returns zero if the element's value could be written.
418 * Negative values indicate an error.
420 int mi_lttng_channel(struct mi_writer
*writer
,
421 struct lttng_channel
*channel
, int is_open
);
424 * Machine interface of struct channel_attr.
426 * writer An instance of a machine interface writer.
427 * attr An instance of a channel_attr struct.
429 * Returns zero if the element's value could be written.
430 * Negative values indicate an error.
432 int mi_lttng_channel_attr(struct mi_writer
*writer
,
433 struct lttng_channel_attr
*attr
);
436 * Machine interface for event common attributes.
438 * writer An instance of a mi writer.
439 * event single trace event.
441 * The common attribute are:
448 * Returns zero if the element's value could be written.
449 * Negative values indicate an error.
451 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
452 struct lttng_event
*event
);
455 * Machine interface for kernel tracepoint event with a loglevel.
457 * writer An instance of a mi writer.
458 * event single trace event.
459 * domain Event's domain
461 * Returns zero if the element's value could be written.
462 * Negative values indicate an error.
464 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
465 struct lttng_event
*event
, enum lttng_domain_type domain
);
468 * Machine interface for kernel tracepoint event with no loglevel.
470 * writer An instance of a mi writer.
471 * event single trace event.
473 * Returns zero if the element's value could be written.
474 * Negative values indicate an error.
476 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
477 struct lttng_event
*event
);
480 * Machine interface for kernel function and probe event.
482 * writer An instance of a mi writer.
483 * event single trace event.
485 * Returns zero if the element's value could be written.
486 * Negative values indicate an error.
488 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
489 struct lttng_event
*event
);
492 * Machine interface for kernel function entry event.
494 * writer An instance of a mi writer.
495 * event single trace event.
497 * Returns zero if the element's value could be written.
498 * Negative values indicate an error.
500 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
501 struct lttng_event
*event
);
504 * Machine interface: open an events element.
506 * writer An instance of a machine interface writer.
508 * Returns zero if the element's value could be written.
509 * Negative values indicate an error.
511 int mi_lttng_events_open(struct mi_writer
*writer
);
514 * Machine interface for printing an event.
515 * The trace event type currently supported are:
522 * writer An instance of a mi writer.
523 * event single trace event.
524 * is_open Defines whether or not the session element shall be closed.
525 * This should be used carefully and the client
526 * must close the event element.
527 * Use case: nested additional information
528 * domain Event's domain
530 * Returns zero if the element's value could be written.
531 * Negative values indicate an error.
533 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
534 int is_open
, enum lttng_domain_type domain
);
537 * Machine interface for struct lttng_event_field.
539 * writer An instance of a mi writer.
540 * field An event_field instance.
542 * Returns zero if the element's value could be written.
543 * Negative values indicate an error.
545 int mi_lttng_event_field(struct mi_writer
*writer
,
546 struct lttng_event_field
*field
);
549 * Machine interface: open a event_fields element.
551 * writer An instance of a machine interface writer.
553 * Returns zero if the element have be written.
554 * Negative values indicate an error.
556 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
559 * Machine interface: open a PIDs element.
561 * writer An instance of a machine interface writer.
563 * Returns zero if the element's value could be written.
564 * Negative values indicate an error.
566 int mi_lttng_pids_open(struct mi_writer
*writer
);
569 * Machine interface of a PID.
571 * writer An instance of a machine interface writer.
574 * is_open Defines whether or not the session element shall be closed.
575 * This should be used carefully and the client
576 * must close the pid element.
577 * Use case: nested addition information on a domain
580 * Returns zero if the element's value could be written.
581 * Negative values indicate an error.
583 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
587 * Machine interface for struct lttng_calibrate.
589 * writer An instance of a machine interface writer.
591 * calibrate A lttng_calibrate instance.
593 * Returns zero if the element's value could be written.
594 * Negative values indicate an error.
596 int mi_lttng_calibrate(struct mi_writer
*writer
,
597 struct lttng_calibrate
*calibrate
);
600 * Machine interface of a context.
602 * writer An instance of a machine interface writer
604 * context An instance of a lttng_event_context
606 * is_open Define if we close the context element
607 * This should be used carefully and the client
608 * need to close the context element.
609 * Returns zero if the element's value could be written.
610 * Negative values indicate an error.
612 int mi_lttng_context(struct mi_writer
*writer
,
613 struct lttng_event_context
*context
, int is_open
);
616 * Machine interface of a perf_counter_context.
618 * writer An instance of a machine interface writer
620 * contest An instance of a lttng_event_perf_counter_ctx
622 * Returns zero if the element's value could be written.
623 * Negative values indicate an error.
625 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
626 struct lttng_event_perf_counter_ctx
*perf_context
);
629 * Machine interface of the snapshot list_output.
630 * It specifies the session for which we are listing snapshots,
631 * and it opens a snapshots element to list a sequence
634 * writer An instance of a machine interface writer.
636 * session_name: Snapshot output for session "session_name".
638 * Note: The client has to close the session and the snapshots elements after
639 * having listed every lttng_snapshot_output.
641 * Returns zero if the element's value could be written.
642 * Negative values indicate an error.
644 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
645 const char *session_name
);
648 * Machine interface of the snapshot output.
649 * The machine interface serializes the following attributes:
650 * - id: ID of the snapshot output.
651 * - name: Name of the output.
652 * - data_url : Destination of the output.
653 * - ctrl_url: Destination of the output.
654 * - max_size: total size of all stream combined.
656 * writer An instance of a machine interface writer.
658 * output: A list of snapshot_output.
660 * Returns zero if the element's value could be written.
661 * Negative values indicate an error.
663 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
664 struct lttng_snapshot_output
*output
);
667 * Machine interface of the output of the command snapshot del output
668 * when deleting a snapshot either by id or by name.
669 * If the snapshot was found and successfully deleted using its id,
670 * it return the id of the snapshot and the current session name on which it
673 * Otherwise, it do the same process with the name of the snapshot, if the
674 * snapshot output id is undefined.
676 * writer An instance of a machine interface writer.
678 * id: ID of the snapshot output.
680 * name: Name of the snapshot.
682 * current_session_name: Session to which the snapshot belongs.
684 * Returns zero if the element's value could be written.
685 * Negative values indicate an error.
687 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
688 const char *name
, const char *current_session_name
);
691 * Machine interface of the output of the command snapshot add output
692 * when adding a snapshot from a user URL.
694 * If the snapshot was successfully added, the machine interface lists
696 * - id: ID of the newly add snapshot output.
697 * - current_session_name: Name of the session to which the output was added.
698 * - ctrl_url: Destination of the output.
699 * - max_size: total size of all stream combined.
701 * writer An instance of a machine interface writer.
703 * current_session_name: Session to which the snapshot belongs.
707 * output: iterator over a lttng_snapshot_output_list which contain
708 * the snapshot output informations.
710 * Returns zero if the element's value could be written.
711 * Negative values indicate an error.
713 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
714 const char *current_session_name
, const char *n_ptr
,
715 struct lttng_snapshot_output
*output
);
718 * Machine interface of the output of the command snapshot
719 * record from a URL (if given).
721 * If the snapshot is successfully recorded from a url, the machine interface
722 * output the following information:
723 * - url: Destination of the output stored in the snapshot.
725 * Otherwise, the machine interface output the data and ctrl url received
726 * from the command-line.
728 * writer An instance of a machine interface writer.
730 * current_session_name: Snapshot record for session "current_session_name".
732 * ctrl_url, data_url: Destination of the output receive from the command-line.
734 * Returns zero if the element's value could be written.
735 * Negative values indicate an error.
737 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
738 const char *current_session_name
, const char *url
,
739 const char *cmdline_ctrl_url
, const char *cmdline_data_url
);
741 #endif /* _MI_LTTNG_H */