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 type */
163 const char * const mi_lttng_loglevel_type_all
;
164 const char * const mi_lttng_loglevel_type_range
;
165 const char * const mi_lttng_loglevel_type_single
;
166 const char * const mi_lttng_loglevel_type_unknown
;
168 /* Sting related to lttng_calibrate */
169 const char * const mi_lttng_element_calibrate
;
170 const char * const mi_lttng_element_calibrate_function
;
172 /* String related to a lttng_snapshot */
173 const char * const mi_lttng_element_snapshot_ctrl_url
;
174 const char * const mi_lttng_element_snapshot_data_url
;
175 const char * const mi_lttng_element_snapshot_max_size
;
176 const char * const mi_lttng_element_snapshot_n_ptr
;
177 const char * const mi_lttng_element_snapshot_session_name
;
178 const char * const mi_lttng_element_snapshots
;
180 /* Utility string function */
181 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
);
182 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
183 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
184 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
185 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
186 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
);
189 * Create an instance of a machine interface writer.
191 * fd_output File to which the XML content must be written. The file will be
192 * closed once the mi_writer has been destroyed.
194 * Returns an instance of a machine interface writer on success, NULL on
197 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
200 * Destroy an instance of a machine interface writer.
202 * writer An instance of a machine interface writer.
204 * Returns zero if the XML document could be closed cleanly. Negative values
207 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
210 * Open a command tag and add it's name node.
212 * writer An instance of a machine interface writer.
213 * command The command name.
215 * Returns zero if the XML document could be closed cleanly.
216 * Negative values indicate an error.
218 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
221 * Close a command tag.
223 * writer An instance of a machine interface writer.
225 * Returns zero if the XML document could be closed cleanly.
226 * Negative values indicate an error.
228 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
231 * Open an element tag.
233 * writer An instance of a machine interface writer.
234 * element_name Element tag name.
236 * Returns zero if the XML document could be closed cleanly.
237 * Negative values indicate an error.
239 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
240 const char *element_name
);
243 * Close the current element tag.
245 * writer An instance of a machine interface writer.
247 * Returns zero if the XML document could be closed cleanly.
248 * Negative values indicate an error.
250 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
253 * Close multiple element.
255 * writer An instance of a machine interface writer.
256 * nb_element Number of elements.
258 * Returns zero if the XML document could be closed cleanly.
259 * Negative values indicate an error.
261 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
262 unsigned int nb_element
);
265 * Write an element of type unsigned int.
267 * writer An instance of a machine interface writer.
268 * element_name Element name.
269 * value Unsigned int value of the element
271 * Returns zero if the element's value could be written.
272 * Negative values indicate an error.
274 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
275 const char *element_name
, uint64_t value
);
278 * Write an element of type signed int.
280 * writer An instance of a machine interface writer.
281 * element_name Element name.
282 * value Signed int value of the element.
284 * Returns zero if the element's value could be written.
285 * Negative values indicate an error.
287 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
288 const char *element_name
, int64_t value
);
291 * Write an element of type boolean.
293 * writer An instance of a machine interface writer.
294 * element_name Element name.
295 * value Boolean value of the element.
297 * Returns zero if the element's value could be written.
298 * Negative values indicate an error.
300 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
301 const char *element_name
, int value
);
304 * Write an element of type string.
306 * writer An instance of a machine interface writer.
307 * element_name Element name.
308 * value String value of the element.
310 * Returns zero if the element's value could be written.
311 * Negative values indicate an error.
313 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
314 const char *element_name
, const char *value
);
317 * Machine interface of struct version.
319 * writer An instance of a machine interface writer.
320 * version Version struct.
321 * lttng_description String value of the version description.
322 * lttng_license String value of the version license.
324 * Returns zero if the element's value could be written.
325 * Negative values indicate an error.
327 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
328 const char *lttng_description
, const char *lttng_license
);
331 * Machine interface: open a sessions element.
333 * writer An instance of a machine interface writer.
335 * Returns zero if the element's value could be written.
336 * Negative values indicate an error.
338 int mi_lttng_sessions_open(struct mi_writer
*writer
);
341 * Machine interface of struct session.
343 * writer An instance of a machine interface writer.
344 * session An instance of a session.
345 * is_open Defines whether or not the session element shall be closed.
346 * This should be used carefully and the client
347 * must close the session element.
348 * Use case: nested additional information on a session
349 * ex: domain,channel event.
351 * Returns zero if the element's value could be written.
352 * Negative values indicate an error.
354 int mi_lttng_session(struct mi_writer
*writer
,
355 struct lttng_session
*session
, int is_open
);
358 * Machine interface: open a domains element.
360 * writer An instance of a machine interface writer.
362 * Returns zero if the element's value could be written.
363 * Negative values indicate an error.
365 int mi_lttng_domains_open(struct mi_writer
*writer
);
368 * Machine interface of struct domain.
370 * writer An instance of a machine interface writer.
371 * domain An instance of a domain.
373 * is_open Defines whether or not the session element shall be closed.
374 * This should be used carefully and the client
375 * must close the domain element.
376 * Use case: nested addition information on a domain
379 * Returns zero if the element's value could be written.
380 * Negative values indicate an error.
382 int mi_lttng_domain(struct mi_writer
*writer
,
383 struct lttng_domain
*domain
, int is_open
);
386 * Machine interface: open a channels element.
388 * writer An instance of a machine interface writer.
390 * Returns zero if the element's value could be written.
391 * Negative values indicate an error.
393 int mi_lttng_channels_open(struct mi_writer
*writer
);
396 * Machine interface of struct channel.
398 * writer An instance of a machine interface writer.
399 * channel An instance of a channel.
401 * is_open Defines whether or not the session element shall be closed.
402 * This should be used carefully and the client
403 * must close the channel element.
404 * Use case: nested addition information on a channel.
407 * Returns zero if the element's value could be written.
408 * Negative values indicate an error.
410 int mi_lttng_channel(struct mi_writer
*writer
,
411 struct lttng_channel
*channel
, int is_open
);
414 * Machine interface of struct channel_attr.
416 * writer An instance of a machine interface writer.
417 * attr An instance of a channel_attr struct.
419 * Returns zero if the element's value could be written.
420 * Negative values indicate an error.
422 int mi_lttng_channel_attr(struct mi_writer
*writer
,
423 struct lttng_channel_attr
*attr
);
426 * Machine interface for event common attributes.
428 * writer An instance of a mi writer.
429 * event single trace event.
431 * The common attribute are:
438 * Returns zero if the element's value could be written.
439 * Negative values indicate an error.
441 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
442 struct lttng_event
*event
);
445 * Machine interface for kernel tracepoint event with a loglevel.
447 * writer An instance of a mi writer.
448 * event single trace event.
449 * domain Event's domain
451 * Returns zero if the element's value could be written.
452 * Negative values indicate an error.
454 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
455 struct lttng_event
*event
, enum lttng_domain_type domain
);
458 * Machine interface for kernel tracepoint event with no loglevel.
460 * writer An instance of a mi writer.
461 * event single trace event.
463 * Returns zero if the element's value could be written.
464 * Negative values indicate an error.
466 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
467 struct lttng_event
*event
);
470 * Machine interface for kernel function and probe event.
472 * writer An instance of a mi writer.
473 * event single trace event.
475 * Returns zero if the element's value could be written.
476 * Negative values indicate an error.
478 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
479 struct lttng_event
*event
);
482 * Machine interface for kernel function entry event.
484 * writer An instance of a mi writer.
485 * event single trace event.
487 * Returns zero if the element's value could be written.
488 * Negative values indicate an error.
490 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
491 struct lttng_event
*event
);
494 * Machine interface: open an events element.
496 * writer An instance of a machine interface writer.
498 * Returns zero if the element's value could be written.
499 * Negative values indicate an error.
501 int mi_lttng_events_open(struct mi_writer
*writer
);
504 * Machine interface for printing an event.
505 * The trace event type currently supported are:
512 * writer An instance of a mi writer.
513 * event single trace event.
514 * is_open Defines whether or not the session element shall be closed.
515 * This should be used carefully and the client
516 * must close the event element.
517 * Use case: nested additional information
518 * domain Event's domain
520 * Returns zero if the element's value could be written.
521 * Negative values indicate an error.
523 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
524 int is_open
, enum lttng_domain_type domain
);
527 * Machine interface for struct lttng_event_field.
529 * writer An instance of a mi writer.
530 * field An event_field instance.
532 * Returns zero if the element's value could be written.
533 * Negative values indicate an error.
535 int mi_lttng_event_field(struct mi_writer
*writer
,
536 struct lttng_event_field
*field
);
539 * Machine interface: open a event_fields element.
541 * writer An instance of a machine interface writer.
543 * Returns zero if the element have be written.
544 * Negative values indicate an error.
546 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
549 * Machine interface: open a PIDs element.
551 * writer An instance of a machine interface writer.
553 * Returns zero if the element's value could be written.
554 * Negative values indicate an error.
556 int mi_lttng_pids_open(struct mi_writer
*writer
);
559 * Machine interface of a PID.
561 * writer An instance of a machine interface writer.
564 * is_open Defines whether or not the session element shall be closed.
565 * This should be used carefully and the client
566 * must close the pid element.
567 * Use case: nested addition information on a domain
570 * Returns zero if the element's value could be written.
571 * Negative values indicate an error.
573 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
577 * Machine interface for struct lttng_calibrate.
579 * writer An instance of a machine interface writer.
581 * calibrate A lttng_calibrate instance.
583 * Returns zero if the element's value could be written.
584 * Negative values indicate an error.
586 int mi_lttng_calibrate(struct mi_writer
*writer
,
587 struct lttng_calibrate
*calibrate
);
590 * Machine interface of a context.
592 * writer An instance of a machine interface writer
594 * context An instance of a lttng_event_context
596 * is_open Define if we close the context element
597 * This should be used carefully and the client
598 * need to close the context element.
599 * Returns zero if the element's value could be written.
600 * Negative values indicate an error.
602 int mi_lttng_context(struct mi_writer
*writer
,
603 struct lttng_event_context
*context
, int is_open
);
606 * Machine interface of a perf_counter_context.
608 * writer An instance of a machine interface writer
610 * contest An instance of a lttng_event_perf_counter_ctx
612 * Returns zero if the element's value could be written.
613 * Negative values indicate an error.
615 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
616 struct lttng_event_perf_counter_ctx
*perf_context
);
619 * Machine interface of the snapshot list_output.
620 * It specifies the session for which we are listing snapshots,
621 * and it opens a snapshots element to list a sequence
624 * writer An instance of a machine interface writer.
626 * session_name: Snapshot output for session "session_name".
628 * Note: The client has to close the session and the snapshots elements after
629 * having listed every lttng_snapshot_output.
631 * Returns zero if the element's value could be written.
632 * Negative values indicate an error.
634 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
635 const char *session_name
);
638 * Machine interface of the snapshot output.
639 * The machine interface serializes the following attributes:
640 * - id: ID of the snapshot output.
641 * - name: Name of the output.
642 * - data_url : Destination of the output.
643 * - ctrl_url: Destination of the output.
644 * - max_size: total size of all stream combined.
646 * writer An instance of a machine interface writer.
648 * output: A list of snapshot_output.
650 * Returns zero if the element's value could be written.
651 * Negative values indicate an error.
653 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
654 struct lttng_snapshot_output
*output
);
657 * Machine interface of the output of the command snapshot del output
658 * when deleting a snapshot either by id or by name.
659 * If the snapshot was found and successfully deleted using its id,
660 * it return the id of the snapshot and the current session name on which it
663 * Otherwise, it do the same process with the name of the snapshot, if the
664 * snapshot output id is undefined.
666 * writer An instance of a machine interface writer.
668 * id: ID of the snapshot output.
670 * name: Name of the snapshot.
672 * current_session_name: Session to which the snapshot belongs.
674 * Returns zero if the element's value could be written.
675 * Negative values indicate an error.
677 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
678 const char *name
, const char *current_session_name
);
681 * Machine interface of the output of the command snapshot add output
682 * when adding a snapshot from a user URL.
684 * If the snapshot was successfully added, the machine interface lists
686 * - id: ID of the newly add snapshot output.
687 * - current_session_name: Name of the session to which the output was added.
688 * - ctrl_url: Destination of the output.
689 * - max_size: total size of all stream combined.
691 * writer An instance of a machine interface writer.
693 * current_session_name: Session to which the snapshot belongs.
697 * output: iterator over a lttng_snapshot_output_list which contain
698 * the snapshot output informations.
700 * Returns zero if the element's value could be written.
701 * Negative values indicate an error.
703 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
704 const char *current_session_name
, const char *n_ptr
,
705 struct lttng_snapshot_output
*output
);
708 * Machine interface of the output of the command snapshot
709 * record from a URL (if given).
711 * If the snapshot is successfully recorded from a url, the machine interface
712 * output the following information:
713 * - url: Destination of the output stored in the snapshot.
715 * Otherwise, the machine interface output the data and ctrl url received
716 * from the command-line.
718 * writer An instance of a machine interface writer.
720 * current_session_name: Snapshot record for session "current_session_name".
722 * ctrl_url, data_url: Destination of the output receive from the command-line.
724 * Returns zero if the element's value could be written.
725 * Negative values indicate an error.
727 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
728 const char *current_session_name
, const char *url
,
729 const char *cmdline_ctrl_url
, const char *cmdline_data_url
);
731 #endif /* _MI_LTTNG_H */