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 type */
142 const char * const mi_lttng_loglevel_type_all
;
143 const char * const mi_lttng_loglevel_type_range
;
144 const char * const mi_lttng_loglevel_type_single
;
145 const char * const mi_lttng_loglevel_type_unknown
;
147 /* Sting related to lttng_calibrate */
148 const char * const mi_lttng_element_calibrate
;
149 const char * const mi_lttng_element_calibrate_function
;
151 /* String related to a lttng_snashot */
152 const char * const mi_lttng_element_snapshot_ctrl_url
;
153 const char * const mi_lttng_element_snapshot_data_url
;
154 const char * const mi_lttng_element_snapshot_max_size
;
155 const char * const mi_lttng_element_snapshot_n_ptr
;
156 const char * const mi_lttng_element_snapshot_session_name
;
157 const char * const mi_lttng_element_snapshots
;
159 /* Utility string function */
160 const char *mi_lttng_loglevel_string(int value
);
161 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
162 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
163 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
164 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
165 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
);
168 * Create an instance of a machine interface writer.
170 * fd_output File to which the XML content must be written. The file will be
171 * closed once the mi_writer has been destroyed.
173 * Returns an instance of a machine interface writer on success, NULL on
176 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
179 * Destroy an instance of a machine interface writer.
181 * writer An instance of a machine interface writer.
183 * Returns zero if the XML document could be closed cleanly. Negative values
186 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
189 * Open a command tag and add it's name node.
191 * writer An instance of a machine interface writer.
192 * command The command name.
194 * Returns zero if the XML document could be closed cleanly.
195 * Negative values indicate an error.
197 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
200 * Close a command tag.
202 * writer An instance of a machine interface writer.
204 * Returns zero if the XML document could be closed cleanly.
205 * Negative values indicate an error.
207 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
210 * Open an element tag.
212 * writer An instance of a machine interface writer.
213 * element_name Element tag name.
215 * Returns zero if the XML document could be closed cleanly.
216 * Negative values indicate an error.
218 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
219 const char *element_name
);
222 * Close the current element tag.
224 * writer An instance of a machine interface writer.
226 * Returns zero if the XML document could be closed cleanly.
227 * Negative values indicate an error.
229 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
232 * Close multiple element.
234 * writer An instance of a machine interface writer.
235 * nb_element Number of elements.
237 * Returns zero if the XML document could be closed cleanly.
238 * Negative values indicate an error.
240 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
241 unsigned int nb_element
);
244 * Write an element of type unsigned int.
246 * writer An instance of a machine interface writer.
247 * element_name Element name.
248 * value Unsigned int value of the element
250 * Returns zero if the element's value could be written.
251 * Negative values indicate an error.
253 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
254 const char *element_name
, uint64_t value
);
257 * Write an element of type signed int.
259 * writer An instance of a machine interface writer.
260 * element_name Element name.
261 * value Signed int value of the element.
263 * Returns zero if the element's value could be written.
264 * Negative values indicate an error.
266 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
267 const char *element_name
, int64_t value
);
270 * Write an element of type boolean.
272 * writer An instance of a machine interface writer.
273 * element_name Element name.
274 * value Boolean value of the element.
276 * Returns zero if the element's value could be written.
277 * Negative values indicate an error.
279 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
280 const char *element_name
, int value
);
283 * Write an element of type string.
285 * writer An instance of a machine interface writer.
286 * element_name Element name.
287 * value String value of the element.
289 * Returns zero if the element's value could be written.
290 * Negative values indicate an error.
292 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
293 const char *element_name
, const char *value
);
296 * Machine interface of struct version.
298 * writer An instance of a machine interface writer.
299 * version Version struct.
300 * lttng_description String value of the version description.
301 * lttng_license String value of the version license.
303 * Returns zero if the element's value could be written.
304 * Negative values indicate an error.
306 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
307 const char *lttng_description
, const char *lttng_license
);
310 * Machine interface: open a sessions element.
312 * writer An instance of a machine interface writer.
314 * Returns zero if the element's value could be written.
315 * Negative values indicate an error.
317 int mi_lttng_sessions_open(struct mi_writer
*writer
);
320 * Machine interface of struct session.
322 * writer An instance of a machine interface writer.
323 * session An instance of a session.
324 * is_open Defines whether or not the session element shall be closed.
325 * This should be used carefully and the client
326 * must close the session element.
327 * Use case: nested addtionnal information on a session
328 * ex: domain,channel event.
330 * Returns zero if the element's value could be written.
331 * Negative values indicate an error.
333 int mi_lttng_session(struct mi_writer
*writer
,
334 struct lttng_session
*session
, int is_open
);
337 * Machine interface: open a domains element.
339 * writer An instance of a machine interface writer.
341 * Returns zero if the element's value could be written.
342 * Negative values indicate an error.
344 int mi_lttng_domains_open(struct mi_writer
*writer
);
347 * Machine interface of struct domain.
349 * writer An instance of a machine interface writer.
350 * domain An instance of a domain.
352 * is_open Defines whether or not the session element shall be closed.
353 * This should be used carefully and the client
354 * must close the domain element.
355 * Use case: nested addition information on a domain
358 * Returns zero if the element's value could be written.
359 * Negative values indicate an error.
361 int mi_lttng_domain(struct mi_writer
*writer
,
362 struct lttng_domain
*domain
, int is_open
);
365 * Machine interface: open a channels element.
367 * writer An instance of a machine interface writer.
369 * Returns zero if the element's value could be written.
370 * Negative values indicate an error.
372 int mi_lttng_channels_open(struct mi_writer
*writer
);
375 * Machine interface of struct channel.
377 * writer An instance of a machine interface writer.
378 * channel An instance of a channel.
380 * is_open Defines whether or not the session element shall be closed.
381 * This should be used carefully and the client
382 * must close the channel element.
383 * Use case: nested addition information on a channel.
386 * Returns zero if the element's value could be written.
387 * Negative values indicate an error.
389 int mi_lttng_channel(struct mi_writer
*writer
,
390 struct lttng_channel
*channel
, int is_open
);
393 * Machine interface of struct channel_attr.
395 * writer An instance of a machine interface writer.
396 * attr An instance of a channel_attr struct.
398 * Returns zero if the element's value could be written.
399 * Negative values indicate an error.
401 int mi_lttng_channel_attr(struct mi_writer
*writer
,
402 struct lttng_channel_attr
*attr
);
405 * Machine interface for event common attributes.
407 * writer An instance of a mi writer.
408 * event single trace event.
410 * The common attribute are:
417 * Returns zero if the element's value could be written.
418 * Negative values indicate an error.
420 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
421 struct lttng_event
*event
);
424 * Machine interface for kernel tracepoint event with a loglevel.
426 * writer An instance of a mi writer.
427 * event single trace event.
429 * Returns zero if the element's value could be written.
430 * Negative values indicate an error.
432 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
433 struct lttng_event
*event
);
436 * Machine interface for kernel tracepoint event with no loglevel.
438 * writer An instance of a mi writer.
439 * event single trace event.
441 * Returns zero if the element's value could be written.
442 * Negative values indicate an error.
444 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
445 struct lttng_event
*event
);
448 * Machine interface for kernel function and probe event.
450 * writer An instance of a mi writer.
451 * event single trace event.
453 * Returns zero if the element's value could be written.
454 * Negative values indicate an error.
456 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
457 struct lttng_event
*event
);
460 * Machine interface for kernel function entry event.
462 * writer An instance of a mi writer.
463 * event single trace event.
465 * Returns zero if the element's value could be written.
466 * Negative values indicate an error.
468 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
469 struct lttng_event
*event
);
472 * Machine interface: open an events element.
474 * writer An instance of a machine interface writer.
476 * Returns zero if the element's value could be written.
477 * Negative values indicate an error.
479 int mi_lttng_events_open(struct mi_writer
*writer
);
482 * Machine interface for printing an event.
483 * The trace event type currently supported are:
490 * writer An instance of a mi writer.
491 * event single trace event.
492 * is_open Defines whether or not the session element shall be closed.
493 * This should be used carefully and the client
494 * must close the event element.
495 * Use case: nested additional information
497 * Returns zero if the element's value could be written.
498 * Negative values indicate an error.
500 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
504 * Machine interface for struct lttng_event_field.
506 * writer An instance of a mi writer.
507 * field An event_field instance.
509 * Returns zero if the element's value could be written.
510 * Negative values indicate an error.
512 int mi_lttng_event_field(struct mi_writer
*writer
,
513 struct lttng_event_field
*field
);
516 * Machine interface: open a event_fields element.
518 * writer An instance of a machine interface writer.
520 * Returns zero if the element have be written.
521 * Negative values indicate an error.
523 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
526 * Machine interface: open a PIDs element.
528 * writer An instance of a machine interface writer.
530 * Returns zero if the element's value could be written.
531 * Negative values indicate an error.
533 int mi_lttng_pids_open(struct mi_writer
*writer
);
536 * Machine interface of a PID.
538 * writer An instance of a machine interface writer.
541 * is_open Defines whether or not the session element shall be closed.
542 * This should be used carefully and the client
543 * must close the pid element.
544 * Use case: nested addition information on a domain
547 * Returns zero if the element's value could be written.
548 * Negative values indicate an error.
550 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
554 * Machine interface for struct lttng_calibrate.
556 * writer An instance of a machine interface writer.
558 * calibrate A lttng_calibrate instance.
560 * Returns zero if the element's value could be written.
561 * Negative values indicate an error.
563 int mi_lttng_calibrate(struct mi_writer
*writer
,
564 struct lttng_calibrate
*calibrate
);
567 * Machine interface of a context.
569 * writer An instance of a machine interface writer
571 * context An instance of a lttng_event_context
573 * is_open Define if we close the context element
574 * This should be used carefully and the client
575 * need to close the context element.
576 * Returns zero if the element's value could be written.
577 * Negative values indicate an error.
579 int mi_lttng_context(struct mi_writer
*writer
,
580 struct lttng_event_context
*context
, int is_open
);
583 * Machine interface of a perf_counter_context.
585 * writer An instance of a machine interface writer
587 * contest An instance of a lttng_event_perf_counter_ctx
589 * Returns zero if the element's value could be written.
590 * Negative values indicate an error.
592 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
593 struct lttng_event_perf_counter_ctx
*perf_context
);
596 * Machine interface of the snapshot list_output.
597 * It specifies the session for which we are listing snapshots,
598 * and it opens a snapshots element to list a sequence
601 * writer An instance of a machine interface writer.
603 * session_name: Snapshot output for session "session_name".
605 * Note: The client has to close the session and the snapshots elements after
606 * having listed every lttng_snapshot_output.
608 * Returns zero if the element's value could be written.
609 * Negative values indicate an error.
611 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
612 const char *session_name
);
615 * Machine interface of the snapshot output.
616 * The machine interface serializes the following attributes:
617 * - id: ID of the snapshot output.
618 * - name: Name of the output.
619 * - data_url : Destination of the output.
620 * - ctrl_url: Destination of the output.
621 * - max_size: total size of all stream combined.
623 * writer An instance of a machine interface writer.
625 * output: A list of snapshot_output.
627 * Returns zero if the element's value could be written.
628 * Negative values indicate an error.
630 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
631 struct lttng_snapshot_output
*output
);
634 * Machine interface of the output of the command snapshot del output
635 * when deleting a snapshot either by id or by name.
636 * If the snapshot was found and successfully deleted using its id,
637 * it return the id of the snapshot and the current session name on which it
640 * Otherwise, it do the same process with the name of the snapshot, if the
641 * snapshot output id is undefined.
643 * writer An instance of a machine interface writer.
645 * id: ID of the snapshot output.
647 * name: Name of the snapshot.
649 * current_session_name: Session to which the snapshot belongs.
651 * Returns zero if the element's value could be written.
652 * Negative values indicate an error.
654 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
655 const char *name
, const char *current_session_name
);
658 * Machine interface of the output of the command snapshot add output
659 * when adding a snapshot from a user URL.
661 * If the snapshot was successfully added, the machine interface lists
663 * - id: ID of the newly add snapshot output.
664 * - current_session_name: Name of the session to which the output was added.
665 * - ctrl_url: Destination of the output.
666 * - max_size: total size of all stream combined.
668 * writer An instance of a machine interface writer.
670 * current_session_name: Session to which the snapshot belongs.
674 * output: iterator over a lttng_snapshot_output_list which contain
675 * the snapshot output informations.
677 * Returns zero if the element's value could be written.
678 * Negative values indicate an error.
680 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
681 const char *current_session_name
, const char *n_ptr
,
682 struct lttng_snapshot_output
*output
);
685 * Machine interface of the output of the command snapshot
686 * record from a URL (if given).
688 * If the snapshot is successfully recorded from a url, the machine interface
689 * output the following information:
690 * - url: Destination of the output stored in the snapshot.
692 * Otherwise, the machine interface output the data and ctrl url received
693 * from the command-line.
695 * writer An instance of a machine interface writer.
697 * current_session_name: Snapshot record for session "current_session_name".
699 * ctrl_url, data_url: Destination of the output receive from the command-line.
701 * Returns zero if the element's value could be written.
702 * Negative values indicate an error.
704 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
705 const char *current_session_name
, const char *url
,
706 const char *cmdline_ctrl_url
, const char *cmdline_data_url
);
708 #endif /* _MI_LTTNG_H */