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_version
;
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
;
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
;
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
;
98 /* String related to lttng_event_perf_counter_ctx */
99 const char * const mi_lttng_element_perf_counter_context
;
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
;
106 /* Strings related to save command */
107 const char * const mi_lttng_element_save
;
109 /* Strings related to load command */
110 const char * const mi_lttng_element_load
;
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
;
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
;
141 /* String related to loglevel JUL */
142 const char * const mi_lttng_loglevel_str_jul_all
;
143 const char * const mi_lttng_loglevel_str_jul_config
;
144 const char * const mi_lttng_loglevel_str_jul_fine
;
145 const char * const mi_lttng_loglevel_str_jul_finer
;
146 const char * const mi_lttng_loglevel_str_jul_finest
;
147 const char * const mi_lttng_loglevel_str_jul_info
;
148 const char * const mi_lttng_loglevel_str_jul_off
;
149 const char * const mi_lttng_loglevel_str_jul_severe
;
150 const char * const mi_lttng_loglevel_str_jul_warning
;
152 /* String related to loglevel Log4j */
153 const char * const mi_lttng_loglevel_str_log4j_off
;
154 const char * const mi_lttng_loglevel_str_log4j_fatal
;
155 const char * const mi_lttng_loglevel_str_log4j_error
;
156 const char * const mi_lttng_loglevel_str_log4j_warn
;
157 const char * const mi_lttng_loglevel_str_log4j_info
;
158 const char * const mi_lttng_loglevel_str_log4j_debug
;
159 const char * const mi_lttng_loglevel_str_log4j_trace
;
160 const char * const mi_lttng_loglevel_str_log4j_all
;
162 /* String related to loglevel Python */
163 const char * const mi_lttng_loglevel_str_python_critical
;
164 const char * const mi_lttng_loglevel_str_python_error
;
165 const char * const mi_lttng_loglevel_str_python_warning
;
166 const char * const mi_lttng_loglevel_str_python_info
;
167 const char * const mi_lttng_loglevel_str_python_debug
;
168 const char * const mi_lttng_loglevel_str_python_notset
;
170 /* String related to loglevel type */
171 const char * const mi_lttng_loglevel_type_all
;
172 const char * const mi_lttng_loglevel_type_range
;
173 const char * const mi_lttng_loglevel_type_single
;
174 const char * const mi_lttng_loglevel_type_unknown
;
176 /* Sting related to lttng_calibrate */
177 const char * const mi_lttng_element_calibrate
;
178 const char * const mi_lttng_element_calibrate_function
;
180 /* String related to a lttng_snapshot */
181 const char * const mi_lttng_element_snapshot_ctrl_url
;
182 const char * const mi_lttng_element_snapshot_data_url
;
183 const char * const mi_lttng_element_snapshot_max_size
;
184 const char * const mi_lttng_element_snapshot_n_ptr
;
185 const char * const mi_lttng_element_snapshot_session_name
;
186 const char * const mi_lttng_element_snapshots
;
188 /* Utility string function */
189 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
);
190 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
191 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
192 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
193 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
194 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
);
197 * Create an instance of a machine interface writer.
199 * fd_output File to which the XML content must be written. The file will be
200 * closed once the mi_writer has been destroyed.
202 * Returns an instance of a machine interface writer on success, NULL on
205 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
208 * Destroy an instance of a machine interface writer.
210 * writer An instance of a machine interface writer.
212 * Returns zero if the XML document could be closed cleanly. Negative values
215 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
218 * Open a command tag and add it's name node.
220 * writer An instance of a machine interface writer.
221 * command The command name.
223 * Returns zero if the XML document could be closed cleanly.
224 * Negative values indicate an error.
226 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
229 * Close a command tag.
231 * writer An instance of a machine interface writer.
233 * Returns zero if the XML document could be closed cleanly.
234 * Negative values indicate an error.
236 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
239 * Open an element tag.
241 * writer An instance of a machine interface writer.
242 * element_name Element tag name.
244 * Returns zero if the XML document could be closed cleanly.
245 * Negative values indicate an error.
247 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
248 const char *element_name
);
251 * Close the current element tag.
253 * writer An instance of a machine interface writer.
255 * Returns zero if the XML document could be closed cleanly.
256 * Negative values indicate an error.
258 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
261 * Close multiple element.
263 * writer An instance of a machine interface writer.
264 * nb_element Number of elements.
266 * Returns zero if the XML document could be closed cleanly.
267 * Negative values indicate an error.
269 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
270 unsigned int nb_element
);
273 * Write an element of type unsigned int.
275 * writer An instance of a machine interface writer.
276 * element_name Element name.
277 * value Unsigned int value of the element
279 * Returns zero if the element's value could be written.
280 * Negative values indicate an error.
282 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
283 const char *element_name
, uint64_t value
);
286 * Write an element of type signed int.
288 * writer An instance of a machine interface writer.
289 * element_name Element name.
290 * value Signed int value of the element.
292 * Returns zero if the element's value could be written.
293 * Negative values indicate an error.
295 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
296 const char *element_name
, int64_t value
);
299 * Write an element of type boolean.
301 * writer An instance of a machine interface writer.
302 * element_name Element name.
303 * value Boolean value of the element.
305 * Returns zero if the element's value could be written.
306 * Negative values indicate an error.
308 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
309 const char *element_name
, int value
);
312 * Write an element of type string.
314 * writer An instance of a machine interface writer.
315 * element_name Element name.
316 * value String value of the element.
318 * Returns zero if the element's value could be written.
319 * Negative values indicate an error.
321 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
322 const char *element_name
, const char *value
);
325 * Machine interface of struct version.
327 * writer An instance of a machine interface writer.
328 * version Version struct.
329 * lttng_description String value of the version description.
330 * lttng_license String value of the version license.
332 * Returns zero if the element's value could be written.
333 * Negative values indicate an error.
335 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
336 const char *lttng_description
, const char *lttng_license
);
339 * Machine interface: open a sessions element.
341 * writer An instance of a machine interface writer.
343 * Returns zero if the element's value could be written.
344 * Negative values indicate an error.
346 int mi_lttng_sessions_open(struct mi_writer
*writer
);
349 * Machine interface of struct session.
351 * writer An instance of a machine interface writer.
352 * session An instance of a session.
353 * is_open Defines whether or not the session element shall be closed.
354 * This should be used carefully and the client
355 * must close the session element.
356 * Use case: nested additional information on a session
357 * ex: domain,channel event.
359 * Returns zero if the element's value could be written.
360 * Negative values indicate an error.
362 int mi_lttng_session(struct mi_writer
*writer
,
363 struct lttng_session
*session
, int is_open
);
366 * Machine interface: open a domains element.
368 * writer An instance of a machine interface writer.
370 * Returns zero if the element's value could be written.
371 * Negative values indicate an error.
373 int mi_lttng_domains_open(struct mi_writer
*writer
);
376 * Machine interface of struct domain.
378 * writer An instance of a machine interface writer.
379 * domain An instance of a domain.
381 * is_open Defines whether or not the session element shall be closed.
382 * This should be used carefully and the client
383 * must close the domain element.
384 * Use case: nested addition information on a domain
387 * Returns zero if the element's value could be written.
388 * Negative values indicate an error.
390 int mi_lttng_domain(struct mi_writer
*writer
,
391 struct lttng_domain
*domain
, int is_open
);
394 * Machine interface: open a channels element.
396 * writer An instance of a machine interface writer.
398 * Returns zero if the element's value could be written.
399 * Negative values indicate an error.
401 int mi_lttng_channels_open(struct mi_writer
*writer
);
404 * Machine interface of struct channel.
406 * writer An instance of a machine interface writer.
407 * channel An instance of a channel.
409 * is_open Defines whether or not the session element shall be closed.
410 * This should be used carefully and the client
411 * must close the channel element.
412 * Use case: nested addition information on a channel.
415 * Returns zero if the element's value could be written.
416 * Negative values indicate an error.
418 int mi_lttng_channel(struct mi_writer
*writer
,
419 struct lttng_channel
*channel
, int is_open
);
422 * Machine interface of struct channel_attr.
424 * writer An instance of a machine interface writer.
425 * attr An instance of a channel_attr struct.
427 * Returns zero if the element's value could be written.
428 * Negative values indicate an error.
430 int mi_lttng_channel_attr(struct mi_writer
*writer
,
431 struct lttng_channel_attr
*attr
);
434 * Machine interface for event common attributes.
436 * writer An instance of a mi writer.
437 * event single trace event.
439 * The common attribute are:
446 * Returns zero if the element's value could be written.
447 * Negative values indicate an error.
449 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
450 struct lttng_event
*event
);
453 * Machine interface for kernel tracepoint event with a loglevel.
455 * writer An instance of a mi writer.
456 * event single trace event.
457 * domain Event's domain
459 * Returns zero if the element's value could be written.
460 * Negative values indicate an error.
462 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
463 struct lttng_event
*event
, enum lttng_domain_type domain
);
466 * Machine interface for kernel tracepoint event with no loglevel.
468 * writer An instance of a mi writer.
469 * event single trace event.
471 * Returns zero if the element's value could be written.
472 * Negative values indicate an error.
474 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
475 struct lttng_event
*event
);
478 * Machine interface for kernel function and probe event.
480 * writer An instance of a mi writer.
481 * event single trace event.
483 * Returns zero if the element's value could be written.
484 * Negative values indicate an error.
486 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
487 struct lttng_event
*event
);
490 * Machine interface for kernel function entry event.
492 * writer An instance of a mi writer.
493 * event single trace event.
495 * Returns zero if the element's value could be written.
496 * Negative values indicate an error.
498 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
499 struct lttng_event
*event
);
502 * Machine interface: open an events element.
504 * writer An instance of a machine interface writer.
506 * Returns zero if the element's value could be written.
507 * Negative values indicate an error.
509 int mi_lttng_events_open(struct mi_writer
*writer
);
512 * Machine interface for printing an event.
513 * The trace event type currently supported are:
520 * writer An instance of a mi writer.
521 * event single trace event.
522 * is_open Defines whether or not the session element shall be closed.
523 * This should be used carefully and the client
524 * must close the event element.
525 * Use case: nested additional information
526 * domain Event's domain
528 * Returns zero if the element's value could be written.
529 * Negative values indicate an error.
531 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
532 int is_open
, enum lttng_domain_type domain
);
535 * Machine interface for struct lttng_event_field.
537 * writer An instance of a mi writer.
538 * field An event_field instance.
540 * Returns zero if the element's value could be written.
541 * Negative values indicate an error.
543 int mi_lttng_event_field(struct mi_writer
*writer
,
544 struct lttng_event_field
*field
);
547 * Machine interface: open a event_fields element.
549 * writer An instance of a machine interface writer.
551 * Returns zero if the element have be written.
552 * Negative values indicate an error.
554 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
557 * Machine interface: open a PIDs element.
559 * writer An instance of a machine interface writer.
561 * Returns zero if the element's value could be written.
562 * Negative values indicate an error.
564 int mi_lttng_pids_open(struct mi_writer
*writer
);
567 * Machine interface of a PID.
569 * writer An instance of a machine interface writer.
572 * is_open Defines whether or not the session element shall be closed.
573 * This should be used carefully and the client
574 * must close the pid element.
575 * Use case: nested addition information on a domain
578 * Returns zero if the element's value could be written.
579 * Negative values indicate an error.
581 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
585 * Machine interface for struct lttng_calibrate.
587 * writer An instance of a machine interface writer.
589 * calibrate A lttng_calibrate instance.
591 * Returns zero if the element's value could be written.
592 * Negative values indicate an error.
594 int mi_lttng_calibrate(struct mi_writer
*writer
,
595 struct lttng_calibrate
*calibrate
);
598 * Machine interface of a context.
600 * writer An instance of a machine interface writer
602 * context An instance of a lttng_event_context
604 * is_open Define if we close the context element
605 * This should be used carefully and the client
606 * need to close the context element.
607 * Returns zero if the element's value could be written.
608 * Negative values indicate an error.
610 int mi_lttng_context(struct mi_writer
*writer
,
611 struct lttng_event_context
*context
, int is_open
);
614 * Machine interface of a perf_counter_context.
616 * writer An instance of a machine interface writer
618 * contest An instance of a lttng_event_perf_counter_ctx
620 * Returns zero if the element's value could be written.
621 * Negative values indicate an error.
623 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
624 struct lttng_event_perf_counter_ctx
*perf_context
);
627 * Machine interface of the snapshot list_output.
628 * It specifies the session for which we are listing snapshots,
629 * and it opens a snapshots element to list a sequence
632 * writer An instance of a machine interface writer.
634 * session_name: Snapshot output for session "session_name".
636 * Note: The client has to close the session and the snapshots elements after
637 * having listed every lttng_snapshot_output.
639 * Returns zero if the element's value could be written.
640 * Negative values indicate an error.
642 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
643 const char *session_name
);
646 * Machine interface of the snapshot output.
647 * The machine interface serializes the following attributes:
648 * - id: ID of the snapshot output.
649 * - name: Name of the output.
650 * - data_url : Destination of the output.
651 * - ctrl_url: Destination of the output.
652 * - max_size: total size of all stream combined.
654 * writer An instance of a machine interface writer.
656 * output: A list of snapshot_output.
658 * Returns zero if the element's value could be written.
659 * Negative values indicate an error.
661 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
662 struct lttng_snapshot_output
*output
);
665 * Machine interface of the output of the command snapshot del output
666 * when deleting a snapshot either by id or by name.
667 * If the snapshot was found and successfully deleted using its id,
668 * it return the id of the snapshot and the current session name on which it
671 * Otherwise, it do the same process with the name of the snapshot, if the
672 * snapshot output id is undefined.
674 * writer An instance of a machine interface writer.
676 * id: ID of the snapshot output.
678 * name: Name of the snapshot.
680 * current_session_name: Session to which the snapshot belongs.
682 * Returns zero if the element's value could be written.
683 * Negative values indicate an error.
685 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
686 const char *name
, const char *current_session_name
);
689 * Machine interface of the output of the command snapshot add output
690 * when adding a snapshot from a user URL.
692 * If the snapshot was successfully added, the machine interface lists
694 * - id: ID of the newly add snapshot output.
695 * - current_session_name: Name of the session to which the output was added.
696 * - ctrl_url: Destination of the output.
697 * - max_size: total size of all stream combined.
699 * writer An instance of a machine interface writer.
701 * current_session_name: Session to which the snapshot belongs.
705 * output: iterator over a lttng_snapshot_output_list which contain
706 * the snapshot output informations.
708 * Returns zero if the element's value could be written.
709 * Negative values indicate an error.
711 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
712 const char *current_session_name
, const char *n_ptr
,
713 struct lttng_snapshot_output
*output
);
716 * Machine interface of the output of the command snapshot
717 * record from a URL (if given).
719 * If the snapshot is successfully recorded from a url, the machine interface
720 * output the following information:
721 * - url: Destination of the output stored in the snapshot.
723 * Otherwise, the machine interface output the data and ctrl url received
724 * from the command-line.
726 * writer An instance of a machine interface writer.
728 * current_session_name: Snapshot record for session "current_session_name".
730 * ctrl_url, data_url: Destination of the output receive from the command-line.
732 * Returns zero if the element's value could be written.
733 * Negative values indicate an error.
735 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
736 const char *current_session_name
, const char *url
,
737 const char *cmdline_ctrl_url
, const char *cmdline_data_url
);
739 #endif /* _MI_LTTNG_H */