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 type */
153 const char * const mi_lttng_loglevel_type_all
;
154 const char * const mi_lttng_loglevel_type_range
;
155 const char * const mi_lttng_loglevel_type_single
;
156 const char * const mi_lttng_loglevel_type_unknown
;
158 /* Sting related to lttng_calibrate */
159 const char * const mi_lttng_element_calibrate
;
160 const char * const mi_lttng_element_calibrate_function
;
162 /* String related to a lttng_snapshot */
163 const char * const mi_lttng_element_snapshot_ctrl_url
;
164 const char * const mi_lttng_element_snapshot_data_url
;
165 const char * const mi_lttng_element_snapshot_max_size
;
166 const char * const mi_lttng_element_snapshot_n_ptr
;
167 const char * const mi_lttng_element_snapshot_session_name
;
168 const char * const mi_lttng_element_snapshots
;
170 /* Utility string function */
171 const char *mi_lttng_loglevel_string(int value
);
172 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
173 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
174 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
175 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
176 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
);
179 * Create an instance of a machine interface writer.
181 * fd_output File to which the XML content must be written. The file will be
182 * closed once the mi_writer has been destroyed.
184 * Returns an instance of a machine interface writer on success, NULL on
187 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
190 * Destroy an instance of a machine interface writer.
192 * writer An instance of a machine interface writer.
194 * Returns zero if the XML document could be closed cleanly. Negative values
197 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
200 * Open a command tag and add it's name node.
202 * writer An instance of a machine interface writer.
203 * command The command name.
205 * Returns zero if the XML document could be closed cleanly.
206 * Negative values indicate an error.
208 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
211 * Close a command tag.
213 * writer An instance of a machine interface writer.
215 * Returns zero if the XML document could be closed cleanly.
216 * Negative values indicate an error.
218 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
221 * Open an element tag.
223 * writer An instance of a machine interface writer.
224 * element_name Element tag name.
226 * Returns zero if the XML document could be closed cleanly.
227 * Negative values indicate an error.
229 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
230 const char *element_name
);
233 * Close the current element tag.
235 * writer An instance of a machine interface writer.
237 * Returns zero if the XML document could be closed cleanly.
238 * Negative values indicate an error.
240 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
243 * Close multiple element.
245 * writer An instance of a machine interface writer.
246 * nb_element Number of elements.
248 * Returns zero if the XML document could be closed cleanly.
249 * Negative values indicate an error.
251 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
252 unsigned int nb_element
);
255 * Write an element of type unsigned int.
257 * writer An instance of a machine interface writer.
258 * element_name Element name.
259 * value Unsigned int value of the element
261 * Returns zero if the element's value could be written.
262 * Negative values indicate an error.
264 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
265 const char *element_name
, uint64_t value
);
268 * Write an element of type signed int.
270 * writer An instance of a machine interface writer.
271 * element_name Element name.
272 * value Signed int value of the element.
274 * Returns zero if the element's value could be written.
275 * Negative values indicate an error.
277 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
278 const char *element_name
, int64_t value
);
281 * Write an element of type boolean.
283 * writer An instance of a machine interface writer.
284 * element_name Element name.
285 * value Boolean value of the element.
287 * Returns zero if the element's value could be written.
288 * Negative values indicate an error.
290 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
291 const char *element_name
, int value
);
294 * Write an element of type string.
296 * writer An instance of a machine interface writer.
297 * element_name Element name.
298 * value String value of the element.
300 * Returns zero if the element's value could be written.
301 * Negative values indicate an error.
303 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
304 const char *element_name
, const char *value
);
307 * Machine interface of struct version.
309 * writer An instance of a machine interface writer.
310 * version Version struct.
311 * lttng_description String value of the version description.
312 * lttng_license String value of the version license.
314 * Returns zero if the element's value could be written.
315 * Negative values indicate an error.
317 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
318 const char *lttng_description
, const char *lttng_license
);
321 * Machine interface: open a sessions element.
323 * writer An instance of a machine interface writer.
325 * Returns zero if the element's value could be written.
326 * Negative values indicate an error.
328 int mi_lttng_sessions_open(struct mi_writer
*writer
);
331 * Machine interface of struct session.
333 * writer An instance of a machine interface writer.
334 * session An instance of a session.
335 * is_open Defines whether or not the session element shall be closed.
336 * This should be used carefully and the client
337 * must close the session element.
338 * Use case: nested additional information on a session
339 * ex: domain,channel event.
341 * Returns zero if the element's value could be written.
342 * Negative values indicate an error.
344 int mi_lttng_session(struct mi_writer
*writer
,
345 struct lttng_session
*session
, int is_open
);
348 * Machine interface: open a domains element.
350 * writer An instance of a machine interface writer.
352 * Returns zero if the element's value could be written.
353 * Negative values indicate an error.
355 int mi_lttng_domains_open(struct mi_writer
*writer
);
358 * Machine interface of struct domain.
360 * writer An instance of a machine interface writer.
361 * domain An instance of a domain.
363 * is_open Defines whether or not the session element shall be closed.
364 * This should be used carefully and the client
365 * must close the domain element.
366 * Use case: nested addition information on a domain
369 * Returns zero if the element's value could be written.
370 * Negative values indicate an error.
372 int mi_lttng_domain(struct mi_writer
*writer
,
373 struct lttng_domain
*domain
, int is_open
);
376 * Machine interface: open a channels element.
378 * writer An instance of a machine interface writer.
380 * Returns zero if the element's value could be written.
381 * Negative values indicate an error.
383 int mi_lttng_channels_open(struct mi_writer
*writer
);
386 * Machine interface of struct channel.
388 * writer An instance of a machine interface writer.
389 * channel An instance of a channel.
391 * is_open Defines whether or not the session element shall be closed.
392 * This should be used carefully and the client
393 * must close the channel element.
394 * Use case: nested addition information on a channel.
397 * Returns zero if the element's value could be written.
398 * Negative values indicate an error.
400 int mi_lttng_channel(struct mi_writer
*writer
,
401 struct lttng_channel
*channel
, int is_open
);
404 * Machine interface of struct channel_attr.
406 * writer An instance of a machine interface writer.
407 * attr An instance of a channel_attr struct.
409 * Returns zero if the element's value could be written.
410 * Negative values indicate an error.
412 int mi_lttng_channel_attr(struct mi_writer
*writer
,
413 struct lttng_channel_attr
*attr
);
416 * Machine interface for event common attributes.
418 * writer An instance of a mi writer.
419 * event single trace event.
421 * The common attribute are:
428 * Returns zero if the element's value could be written.
429 * Negative values indicate an error.
431 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
432 struct lttng_event
*event
);
435 * Machine interface for kernel tracepoint event with a loglevel.
437 * writer An instance of a mi writer.
438 * event single trace event.
440 * Returns zero if the element's value could be written.
441 * Negative values indicate an error.
443 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
444 struct lttng_event
*event
);
447 * Machine interface for kernel tracepoint event with no loglevel.
449 * writer An instance of a mi writer.
450 * event single trace event.
452 * Returns zero if the element's value could be written.
453 * Negative values indicate an error.
455 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
456 struct lttng_event
*event
);
459 * Machine interface for kernel function and probe event.
461 * writer An instance of a mi writer.
462 * event single trace event.
464 * Returns zero if the element's value could be written.
465 * Negative values indicate an error.
467 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
468 struct lttng_event
*event
);
471 * Machine interface for kernel function entry event.
473 * writer An instance of a mi writer.
474 * event single trace event.
476 * Returns zero if the element's value could be written.
477 * Negative values indicate an error.
479 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
480 struct lttng_event
*event
);
483 * Machine interface: open an events element.
485 * writer An instance of a machine interface writer.
487 * Returns zero if the element's value could be written.
488 * Negative values indicate an error.
490 int mi_lttng_events_open(struct mi_writer
*writer
);
493 * Machine interface for printing an event.
494 * The trace event type currently supported are:
501 * writer An instance of a mi writer.
502 * event single trace event.
503 * is_open Defines whether or not the session element shall be closed.
504 * This should be used carefully and the client
505 * must close the event element.
506 * Use case: nested additional information
508 * Returns zero if the element's value could be written.
509 * Negative values indicate an error.
511 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
515 * Machine interface for struct lttng_event_field.
517 * writer An instance of a mi writer.
518 * field An event_field instance.
520 * Returns zero if the element's value could be written.
521 * Negative values indicate an error.
523 int mi_lttng_event_field(struct mi_writer
*writer
,
524 struct lttng_event_field
*field
);
527 * Machine interface: open a event_fields element.
529 * writer An instance of a machine interface writer.
531 * Returns zero if the element have be written.
532 * Negative values indicate an error.
534 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
537 * Machine interface: open a PIDs element.
539 * writer An instance of a machine interface writer.
541 * Returns zero if the element's value could be written.
542 * Negative values indicate an error.
544 int mi_lttng_pids_open(struct mi_writer
*writer
);
547 * Machine interface of a PID.
549 * writer An instance of a machine interface writer.
552 * is_open Defines whether or not the session element shall be closed.
553 * This should be used carefully and the client
554 * must close the pid element.
555 * Use case: nested addition information on a domain
558 * Returns zero if the element's value could be written.
559 * Negative values indicate an error.
561 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
565 * Machine interface for struct lttng_calibrate.
567 * writer An instance of a machine interface writer.
569 * calibrate A lttng_calibrate instance.
571 * Returns zero if the element's value could be written.
572 * Negative values indicate an error.
574 int mi_lttng_calibrate(struct mi_writer
*writer
,
575 struct lttng_calibrate
*calibrate
);
578 * Machine interface of a context.
580 * writer An instance of a machine interface writer
582 * context An instance of a lttng_event_context
584 * is_open Define if we close the context element
585 * This should be used carefully and the client
586 * need to close the context element.
587 * Returns zero if the element's value could be written.
588 * Negative values indicate an error.
590 int mi_lttng_context(struct mi_writer
*writer
,
591 struct lttng_event_context
*context
, int is_open
);
594 * Machine interface of a perf_counter_context.
596 * writer An instance of a machine interface writer
598 * contest An instance of a lttng_event_perf_counter_ctx
600 * Returns zero if the element's value could be written.
601 * Negative values indicate an error.
603 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
604 struct lttng_event_perf_counter_ctx
*perf_context
);
607 * Machine interface of the snapshot list_output.
608 * It specifies the session for which we are listing snapshots,
609 * and it opens a snapshots element to list a sequence
612 * writer An instance of a machine interface writer.
614 * session_name: Snapshot output for session "session_name".
616 * Note: The client has to close the session and the snapshots elements after
617 * having listed every lttng_snapshot_output.
619 * Returns zero if the element's value could be written.
620 * Negative values indicate an error.
622 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
623 const char *session_name
);
626 * Machine interface of the snapshot output.
627 * The machine interface serializes the following attributes:
628 * - id: ID of the snapshot output.
629 * - name: Name of the output.
630 * - data_url : Destination of the output.
631 * - ctrl_url: Destination of the output.
632 * - max_size: total size of all stream combined.
634 * writer An instance of a machine interface writer.
636 * output: A list of snapshot_output.
638 * Returns zero if the element's value could be written.
639 * Negative values indicate an error.
641 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
642 struct lttng_snapshot_output
*output
);
645 * Machine interface of the output of the command snapshot del output
646 * when deleting a snapshot either by id or by name.
647 * If the snapshot was found and successfully deleted using its id,
648 * it return the id of the snapshot and the current session name on which it
651 * Otherwise, it do the same process with the name of the snapshot, if the
652 * snapshot output id is undefined.
654 * writer An instance of a machine interface writer.
656 * id: ID of the snapshot output.
658 * name: Name of the snapshot.
660 * current_session_name: Session to which the snapshot belongs.
662 * Returns zero if the element's value could be written.
663 * Negative values indicate an error.
665 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
666 const char *name
, const char *current_session_name
);
669 * Machine interface of the output of the command snapshot add output
670 * when adding a snapshot from a user URL.
672 * If the snapshot was successfully added, the machine interface lists
674 * - id: ID of the newly add snapshot output.
675 * - current_session_name: Name of the session to which the output was added.
676 * - ctrl_url: Destination of the output.
677 * - max_size: total size of all stream combined.
679 * writer An instance of a machine interface writer.
681 * current_session_name: Session to which the snapshot belongs.
685 * output: iterator over a lttng_snapshot_output_list which contain
686 * the snapshot output informations.
688 * Returns zero if the element's value could be written.
689 * Negative values indicate an error.
691 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
692 const char *current_session_name
, const char *n_ptr
,
693 struct lttng_snapshot_output
*output
);
696 * Machine interface of the output of the command snapshot
697 * record from a URL (if given).
699 * If the snapshot is successfully recorded from a url, the machine interface
700 * output the following information:
701 * - url: Destination of the output stored in the snapshot.
703 * Otherwise, the machine interface output the data and ctrl url received
704 * from the command-line.
706 * writer An instance of a machine interface writer.
708 * current_session_name: Snapshot record for session "current_session_name".
710 * ctrl_url, data_url: Destination of the output receive from the command-line.
712 * Returns zero if the element's value could be written.
713 * Negative values indicate an error.
715 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
716 const char *current_session_name
, const char *url
,
717 const char *cmdline_ctrl_url
, const char *cmdline_data_url
);
719 #endif /* _MI_LTTNG_H */