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_name
;
54 const char * const mi_lttng_element_command_action
;
55 const char * const mi_lttng_element_command_version
;
56 const char * const mi_lttng_element_command_enable_event
;
57 const char * const mi_lttng_element_command_list
;
58 const char * const mi_lttng_element_command_save
;
59 const char * const mi_lttng_element_command_load
;
60 const char * const mi_lttng_element_command_stop
;
61 const char * const mi_lttng_element_command_start
;
62 const char * const mi_lttng_element_command_create
;
63 const char * const mi_lttng_element_command_destroy
;
64 const char * const mi_lttng_element_command_calibrate
;
65 const char * const mi_lttng_element_command_add_context
;
66 const char * const mi_lttng_element_command_enable_channels
;
67 const char * const mi_lttng_element_command_set_session
;
68 const char * const mi_lttng_element_command_disable_event
;
69 const char * const mi_lttng_element_command_disable_channel
;
70 const char * const mi_lttng_element_command_snapshot
;
71 const char * const mi_lttng_element_command_list_snapshot
;
72 const char * const mi_lttng_element_command_del_snapshot
;
73 const char * const mi_lttng_element_command_add_snapshot
;
74 const char * const mi_lttng_element_command_record_snapshot
;
75 const char * const mi_lttng_element_command_output
;
76 const char * const mi_lttng_element_command_success
;
78 /* Strings related to version command */
79 const char * const mi_lttng_element_version
;
80 const char * const mi_lttng_element_version_str
;
81 const char * const mi_lttng_element_version_web
;
82 const char * const mi_lttng_element_version_major
;
83 const char * const mi_lttng_element_version_minor
;
84 const char * const mi_lttng_element_version_license
;
85 const char * const mi_lttng_element_version_commit
;
86 const char * const mi_lttng_element_version_patch_level
;
87 const char * const mi_lttng_element_version_description
;
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_type_other
;
114 const char * const mi_lttng_element_type_integer
;
115 const char * const mi_lttng_element_type_enum
;
116 const char * const mi_lttng_element_type_float
;
117 const char * const mi_lttng_element_type_string
;
118 const char * const mi_lttng_element_nowrite
;
119 const char * const mi_lttng_element_success
;
121 /* String related to loglevel */
122 const char * const mi_lttng_loglevel_str_alert
;
123 const char * const mi_lttng_loglevel_str_crit
;
124 const char * const mi_lttng_loglevel_str_debug
;
125 const char * const mi_lttng_loglevel_str_debug_function
;
126 const char * const mi_lttng_loglevel_str_debug_line
;
127 const char * const mi_lttng_loglevel_str_debug_module
;
128 const char * const mi_lttng_loglevel_str_debug_process
;
129 const char * const mi_lttng_loglevel_str_debug_program
;
130 const char * const mi_lttng_loglevel_str_debug_system
;
131 const char * const mi_lttng_loglevel_str_debug_unit
;
132 const char * const mi_lttng_loglevel_str_emerg
;
133 const char * const mi_lttng_loglevel_str_err
;
134 const char * const mi_lttng_loglevel_str_info
;
135 const char * const mi_lttng_loglevel_str_notice
;
136 const char * const mi_lttng_loglevel_str_unknown
;
137 const char * const mi_lttng_loglevel_str_warning
;
139 /* String related to loglevel type */
140 const char * const mi_lttng_loglevel_type_all
;
141 const char * const mi_lttng_loglevel_type_range
;
142 const char * const mi_lttng_loglevel_type_single
;
143 const char * const mi_lttng_loglevel_type_unknown
;
145 /* Sting related to lttng_calibrate */
146 const char * const mi_lttng_element_calibrate
;
147 const char * const mi_lttng_element_calibrate_function
;
149 /* String related to a lttng_snashot */
150 const char * const mi_lttng_element_snapshots
;
151 const char * const mi_lttng_element_snapshot_session_name
;
152 const char * const mi_lttng_element_snapshot_n_ptr
;
153 const char * const mi_lttng_element_snapshot_data_url
;
154 const char * const mi_lttng_element_snapshot_ctrl_url
;
155 const char * const mi_lttng_element_snapshot_max_size
;
157 /* Utility string function */
158 const char *mi_lttng_loglevel_string(int value
);
159 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
160 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
161 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
162 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
163 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
);
166 * Create an instance of a machine interface writer.
168 * fd_output File to which the XML content must be written. The file will be
169 * closed once the mi_writer has been destroyed.
171 * Returns an instance of a machine interface writer on success, NULL on
174 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
177 * Destroy an instance of a machine interface writer.
179 * writer An instance of a machine interface writer.
181 * Returns zero if the XML document could be closed cleanly. Negative values
184 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
187 * Open a command tag and add it's name node.
189 * writer An instance of a machine interface writer.
190 * command The command name.
192 * Returns zero if the XML document could be closed cleanly.
193 * Negative values indicate an error.
195 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
198 * Close a command tag.
200 * writer An instance of a machine interface writer.
202 * Returns zero if the XML document could be closed cleanly.
203 * Negative values indicate an error.
205 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
208 * Open an element tag.
210 * writer An instance of a machine interface writer.
211 * element_name Element tag name.
213 * Returns zero if the XML document could be closed cleanly.
214 * Negative values indicate an error.
216 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
217 const char *element_name
);
220 * Close the current element tag.
222 * writer An instance of a machine interface writer.
224 * Returns zero if the XML document could be closed cleanly.
225 * Negative values indicate an error.
227 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
230 * Close multiple element.
232 * writer An instance of a machine interface writer.
233 * nb_element Number of elements.
235 * Returns zero if the XML document could be closed cleanly.
236 * Negative values indicate an error.
238 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
239 unsigned int nb_element
);
242 * Write an element of type unsigned int.
244 * writer An instance of a machine interface writer.
245 * element_name Element name.
246 * value Unsigned int value of the element
248 * Returns zero if the element's value could be written.
249 * Negative values indicate an error.
251 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
252 const char *element_name
, uint64_t value
);
255 * Write an element of type signed int.
257 * writer An instance of a machine interface writer.
258 * element_name Element name.
259 * value Signed 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_signed_int(struct mi_writer
*writer
,
265 const char *element_name
, int64_t value
);
268 * Write an element of type boolean.
270 * writer An instance of a machine interface writer.
271 * element_name Element name.
272 * value Boolean 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_bool(struct mi_writer
*writer
,
278 const char *element_name
, int value
);
281 * Write an element of type string.
283 * writer An instance of a machine interface writer.
284 * element_name Element name.
285 * value String 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_string(struct mi_writer
*writer
,
291 const char *element_name
, const char *value
);
294 * Machine interface of struct version.
296 * writer An instance of a machine interface writer.
297 * version Version struct.
298 * lttng_description String value of the version description.
299 * lttng_license String value of the version license.
301 * Returns zero if the element's value could be written.
302 * Negative values indicate an error.
304 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
305 const char *lttng_description
, const char *lttng_license
);
308 * Machine interface: open a sessions element.
310 * writer An instance of a machine interface writer.
312 * Returns zero if the element's value could be written.
313 * Negative values indicate an error.
315 int mi_lttng_sessions_open(struct mi_writer
*writer
);
318 * Machine interface of struct session.
320 * writer An instance of a machine interface writer.
321 * session An instance of a session.
322 * is_open Defines whether or not the session element shall be closed.
323 * This should be used carefully and the client
324 * must close the session element.
325 * Use case: nested addtionnal information on a session
326 * ex: domain,channel event.
328 * Returns zero if the element's value could be written.
329 * Negative values indicate an error.
331 int mi_lttng_session(struct mi_writer
*writer
,
332 struct lttng_session
*session
, int is_open
);
335 * Machine interface: open a domains element.
337 * writer An instance of a machine interface writer.
339 * Returns zero if the element's value could be written.
340 * Negative values indicate an error.
342 int mi_lttng_domains_open(struct mi_writer
*writer
);
345 * Machine interface of struct domain.
347 * writer An instance of a machine interface writer.
348 * domain An instance of a domain.
350 * is_open Defines whether or not the session element shall be closed.
351 * This should be used carefully and the client
352 * must close the domain element.
353 * Use case: nested addition information on a domain
356 * Returns zero if the element's value could be written.
357 * Negative values indicate an error.
359 int mi_lttng_domain(struct mi_writer
*writer
,
360 struct lttng_domain
*domain
, int is_open
);
363 * Machine interface: open a channels element.
365 * writer An instance of a machine interface writer.
367 * Returns zero if the element's value could be written.
368 * Negative values indicate an error.
370 int mi_lttng_channels_open(struct mi_writer
*writer
);
373 * Machine interface of struct channel.
375 * writer An instance of a machine interface writer.
376 * channel An instance of a channel.
378 * is_open Defines whether or not the session element shall be closed.
379 * This should be used carefully and the client
380 * must close the channel element.
381 * Use case: nested addition information on a channel.
384 * Returns zero if the element's value could be written.
385 * Negative values indicate an error.
387 int mi_lttng_channel(struct mi_writer
*writer
,
388 struct lttng_channel
*channel
, int is_open
);
391 * Machine interface of struct channel_attr.
393 * writer An instance of a machine interface writer.
394 * attr An instance of a channel_attr struct.
396 * Returns zero if the element's value could be written.
397 * Negative values indicate an error.
399 int mi_lttng_channel_attr(struct mi_writer
*writer
,
400 struct lttng_channel_attr
*attr
);
403 * Machine interface for event common attributes.
405 * writer An instance of a mi writer.
406 * event single trace event.
408 * The common attribute are:
415 * Returns zero if the element's value could be written.
416 * Negative values indicate an error.
418 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
419 struct lttng_event
*event
);
422 * Machine interface for kernel tracepoint event with a loglevel.
424 * writer An instance of a mi writer.
425 * event single trace event.
427 * Returns zero if the element's value could be written.
428 * Negative values indicate an error.
430 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
431 struct lttng_event
*event
);
434 * Machine interface for kernel tracepoint event with no loglevel.
436 * writer An instance of a mi writer.
437 * event single trace event.
439 * Returns zero if the element's value could be written.
440 * Negative values indicate an error.
442 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
443 struct lttng_event
*event
);
446 * Machine interface for kernel function and probe event.
448 * writer An instance of a mi writer.
449 * event single trace event.
451 * Returns zero if the element's value could be written.
452 * Negative values indicate an error.
454 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
455 struct lttng_event
*event
);
458 * Machine interface for kernel function entry event.
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_function_entry(struct mi_writer
*writer
,
467 struct lttng_event
*event
);
470 * Machine interface: open an events element.
472 * writer An instance of a machine interface writer.
474 * Returns zero if the element's value could be written.
475 * Negative values indicate an error.
477 int mi_lttng_events_open(struct mi_writer
*writer
);
480 * Machine interface for printing an event.
481 * The trace event type currently supported are:
488 * writer An instance of a mi writer.
489 * event single trace event.
490 * is_open Defines whether or not the session element shall be closed.
491 * This should be used carefully and the client
492 * must close the event element.
493 * Use case: nested additional information
495 * Returns zero if the element's value could be written.
496 * Negative values indicate an error.
498 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
502 * Machine interface for struct lttng_event_field.
504 * writer An instance of a mi writer.
505 * field An event_field instance.
507 * Returns zero if the element's value could be written.
508 * Negative values indicate an error.
510 int mi_lttng_event_field(struct mi_writer
*writer
,
511 struct lttng_event_field
*field
);
514 * Machine interface: open a event_fields element.
516 * writer An instance of a machine interface writer.
518 * Returns zero if the element have be written.
519 * Negative values indicate an error.
521 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
524 * Machine interface: open a PIDs element.
526 * writer An instance of a machine interface writer.
528 * Returns zero if the element's value could be written.
529 * Negative values indicate an error.
531 int mi_lttng_pids_open(struct mi_writer
*writer
);
534 * Machine interface of a PID.
536 * writer An instance of a machine interface writer.
539 * is_open Defines whether or not the session element shall be closed.
540 * This should be used carefully and the client
541 * must close the pid element.
542 * Use case: nested addition information on a domain
545 * Returns zero if the element's value could be written.
546 * Negative values indicate an error.
548 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
552 * Machine interface for struct lttng_calibrate.
554 * writer An instance of a machine interface writer.
556 * calibrate A lttng_calibrate instance.
558 * Returns zero if the element's value could be written.
559 * Negative values indicate an error.
561 int mi_lttng_calibrate(struct mi_writer
*writer
,
562 struct lttng_calibrate
*calibrate
);
565 * Machine interface of a context.
567 * writer An instance of a machine interface writer
569 * context An instance of a lttng_event_context
571 * is_open Define if we close the context element
572 * This should be used carefully and the client
573 * need to close the context element.
574 * Returns zero if the element's value could be written.
575 * Negative values indicate an error.
577 int mi_lttng_context(struct mi_writer
*writer
,
578 struct lttng_event_context
*context
, int is_open
);
581 * Machine interface of a perf_counter_context.
583 * writer An instance of a machine interface writer
585 * contest An instance of a lttng_event_perf_counter_ctx
587 * Returns zero if the element's value could be written.
588 * Negative values indicate an error.
590 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
591 struct lttng_event_perf_counter_ctx
*perf_context
);
594 * Machine interface of the snapshot list_output.
595 * It specifies the session for which we are listing snapshots,
596 * and it opens a snapshots element to list a sequence
599 * writer An instance of a machine interface writer.
601 * session_name: Snapshot output for session "session_name".
603 * Note: The client has to close the session and the snapshots elements after
604 * having listed every lttng_snapshot_output.
606 * Returns zero if the element's value could be written.
607 * Negative values indicate an error.
609 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
610 const char *session_name
);
613 * Machine interface of the snapshot output.
614 * The machine interface serializes the following attributes:
615 * - id: ID of the snapshot output.
616 * - name: Name of the output.
617 * - data_url : Destination of the output.
618 * - ctrl_url: Destination of the output.
619 * - max_size: total size of all stream combined.
621 * writer An instance of a machine interface writer.
623 * output: A list of snapshot_output.
625 * Returns zero if the element's value could be written.
626 * Negative values indicate an error.
628 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
629 struct lttng_snapshot_output
*output
);
632 * Machine interface of the output of the command snapshot del output
633 * when deleting a snapshot either by id or by name.
634 * If the snapshot was found and successfully deleted using its id,
635 * it return the id of the snapshot and the current session name on which it
638 * Otherwise, it do the same process with the name of the snapshot, if the
639 * snapshot output id is undefined.
641 * writer An instance of a machine interface writer.
643 * id: ID of the snapshot output.
645 * name: Name of the snapshot.
647 * current_session_name: Session to which the snapshot belongs.
649 * Returns zero if the element's value could be written.
650 * Negative values indicate an error.
652 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
653 const char *name
, const char *current_session_name
);
656 * Machine interface of the output of the command snapshot add output
657 * when adding a snapshot from a user URL.
659 * If the snapshot was successfully added, the machine interface lists
661 * - id: ID of the newly add snapshot output.
662 * - current_session_name: Name of the session to which the output was added.
663 * - ctrl_url: Destination of the output.
664 * - max_size: total size of all stream combined.
666 * writer An instance of a machine interface writer.
668 * current_session_name: Session to which the snapshot belongs.
672 * output: iterator over a lttng_snapshot_output_list which contain
673 * the snapshot output informations.
675 * Returns zero if the element's value could be written.
676 * Negative values indicate an error.
678 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
679 const char *current_session_name
, const char *n_ptr
,
680 struct lttng_snapshot_output
*output
);
683 * Machine interface of the output of the command snapshot
684 * record from a URL (if given).
686 * If the snapshot is successfully recorded from a url, the machine interface
687 * output the following information:
688 * - url: Destination of the output stored in the snapshot.
690 * Otherwise, the machine interface output the data and ctrl url received
691 * from the command-line.
693 * writer An instance of a machine interface writer.
695 * current_session_name: Snapshot record for session "current_session_name".
697 * ctrl_url, data_url: Destination of the output receive from the command-line.
699 * Returns zero if the element's value could be written.
700 * Negative values indicate an error.
702 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
703 const char *current_session_name
, const char *url
,
704 const char *cmdline_ctrl_url
, const char *cmdline_data_url
);
706 #endif /* _MI_LTTNG_H */