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 /* Instance of a machine interface writer. */
31 struct config_writer
*writer
;
32 enum lttng_mi_output_type type
;
36 * Version information for the machine interface.
38 struct mi_lttng_version
{
39 char version
[NAME_MAX
]; /* Version number of package */
40 uint32_t version_major
; /* LTTng-Tools major version number */
41 uint32_t version_minor
; /* LTTng-Tools minor version number */
42 uint32_t version_patchlevel
; /* LTTng-Tools patchlevel version number */
43 char version_commit
[NAME_MAX
]; /* Commit hash of the current version */
44 char version_name
[NAME_MAX
];
45 char package_url
[NAME_MAX
]; /* Define to the home page for this package. */
48 /* Strings related to command */
49 const char * const mi_lttng_element_command
;
50 const char * const mi_lttng_element_command_name
;
51 const char * const mi_lttng_element_command_version
;
52 const char * const mi_lttng_element_command_enable_event
;
53 const char * const mi_lttng_element_command_list
;
54 const char * const mi_lttng_element_command_save
;
55 const char * const mi_lttng_element_command_load
;
56 const char * const mi_lttng_element_command_stop
;
57 const char * const mi_lttng_element_command_start
;
58 const char * const mi_lttng_element_command_create
;
59 const char * const mi_lttng_element_command_destroy
;
60 const char * const mi_lttng_element_command_calibrate
;
61 const char * const mi_lttng_element_command_add_context
;
62 const char * const mi_lttng_element_command_enable_channels
;
63 const char * const mi_lttng_element_command_output
;
64 const char * const mi_lttng_element_command_success
;
66 /* Strings related to version command */
67 const char * const mi_lttng_element_version
;
68 const char * const mi_lttng_element_version_str
;
69 const char * const mi_lttng_element_version_web
;
70 const char * const mi_lttng_element_version_major
;
71 const char * const mi_lttng_element_version_minor
;
72 const char * const mi_lttng_element_version_license
;
73 const char * const mi_lttng_element_version_commit
;
74 const char * const mi_lttng_element_version_patch_level
;
75 const char * const mi_lttng_element_version_description
;
77 /* String related to a lttng_event_field */
78 const char * const mi_lttng_element_event_field
;
79 const char * const mi_lttng_element_event_fields
;
81 /* String related to lttng_event_context */
82 const char * const mi_lttng_context_type_perf_counter
;
83 const char * const mi_lttng_context_type_perf_cpu_counter
;
84 const char * const mi_lttng_context_type_perf_thread_counter
;
86 /* String related to lttng_event_perf_counter_ctx */
87 const char * const mi_lttng_element_perf_counter_context
;
89 /* Strings related to pid */
90 const char * const mi_lttng_element_pids
;
91 const char * const mi_lttng_element_pid
;
92 const char * const mi_lttng_element_pid_id
;
94 /* Strings related to save command */
95 const char * const mi_lttng_element_save
;
97 /* Strings related to load command */
98 const char * const mi_lttng_element_load
;
100 /* General element of mi_lttng */
101 const char * const mi_lttng_element_type_other
;
102 const char * const mi_lttng_element_type_integer
;
103 const char * const mi_lttng_element_type_enum
;
104 const char * const mi_lttng_element_type_float
;
105 const char * const mi_lttng_element_type_string
;
106 const char * const mi_lttng_element_nowrite
;
107 const char * const mi_lttng_element_success
;
109 /* String related to loglevel */
110 const char * const mi_lttng_loglevel_str_alert
;
111 const char * const mi_lttng_loglevel_str_crit
;
112 const char * const mi_lttng_loglevel_str_debug
;
113 const char * const mi_lttng_loglevel_str_debug_function
;
114 const char * const mi_lttng_loglevel_str_debug_line
;
115 const char * const mi_lttng_loglevel_str_debug_module
;
116 const char * const mi_lttng_loglevel_str_debug_process
;
117 const char * const mi_lttng_loglevel_str_debug_program
;
118 const char * const mi_lttng_loglevel_str_debug_system
;
119 const char * const mi_lttng_loglevel_str_debug_unit
;
120 const char * const mi_lttng_loglevel_str_emerg
;
121 const char * const mi_lttng_loglevel_str_err
;
122 const char * const mi_lttng_loglevel_str_info
;
123 const char * const mi_lttng_loglevel_str_notice
;
124 const char * const mi_lttng_loglevel_str_unknown
;
125 const char * const mi_lttng_loglevel_str_warning
;
127 /* String related to loglevel type */
128 const char * const mi_lttng_loglevel_type_all
;
129 const char * const mi_lttng_loglevel_type_range
;
130 const char * const mi_lttng_loglevel_type_single
;
131 const char * const mi_lttng_loglevel_type_unknown
;
133 /* Sting related to lttng_calibrate */
134 const char * const mi_lttng_element_calibrate
;
135 const char * const mi_lttng_element_calibrate_function
;
137 /* Utility string function */
138 const char *mi_lttng_loglevel_string(int value
);
139 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
140 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
141 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
142 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
143 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
);
146 * Create an instance of a machine interface writer.
148 * fd_output File to which the XML content must be written. The file will be
149 * closed once the mi_writer has been destroyed.
151 * Returns an instance of a machine interface writer on success, NULL on
154 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
157 * Destroy an instance of a machine interface writer.
159 * writer An instance of a machine interface writer.
161 * Returns zero if the XML document could be closed cleanly. Negative values
164 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
167 * Open a command tag and add it's name node.
169 * writer An instance of a machine interface writer.
170 * command The command name.
172 * Returns zero if the XML document could be closed cleanly.
173 * Negative values indicate an error.
175 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
178 * Close a command tag.
180 * writer An instance of a machine interface writer.
182 * Returns zero if the XML document could be closed cleanly.
183 * Negative values indicate an error.
185 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
188 * Open an element tag.
190 * writer An instance of a machine interface writer.
191 * element_name Element tag name.
193 * Returns zero if the XML document could be closed cleanly.
194 * Negative values indicate an error.
196 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
197 const char *element_name
);
200 * Close the current element 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_close_element(struct mi_writer
*writer
);
210 * Close multiple element.
212 * writer An instance of a machine interface writer.
213 * nb_element Number of elements.
215 * Returns zero if the XML document could be closed cleanly.
216 * Negative values indicate an error.
218 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
219 unsigned int nb_element
);
222 * Write an element of type unsigned int.
224 * writer An instance of a machine interface writer.
225 * element_name Element name.
226 * value Unsigned int value of the element
228 * Returns zero if the element's value could be written.
229 * Negative values indicate an error.
231 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
232 const char *element_name
, uint64_t value
);
235 * Write an element of type signed int.
237 * writer An instance of a machine interface writer.
238 * element_name Element name.
239 * value Signed int value of the element.
241 * Returns zero if the element's value could be written.
242 * Negative values indicate an error.
244 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
245 const char *element_name
, int64_t value
);
248 * Write an element of type boolean.
250 * writer An instance of a machine interface writer.
251 * element_name Element name.
252 * value Boolean value of the element.
254 * Returns zero if the element's value could be written.
255 * Negative values indicate an error.
257 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
258 const char *element_name
, int value
);
261 * Write an element of type string.
263 * writer An instance of a machine interface writer.
264 * element_name Element name.
265 * value String value of the element.
267 * Returns zero if the element's value could be written.
268 * Negative values indicate an error.
270 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
271 const char *element_name
, const char *value
);
274 * Machine interface of struct version.
276 * writer An instance of a machine interface writer.
277 * version Version struct.
278 * lttng_description String value of the version description.
279 * lttng_license String value of the version license.
281 * Returns zero if the element's value could be written.
282 * Negative values indicate an error.
284 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
285 const char *lttng_description
, const char *lttng_license
);
288 * Machine interface: open a sessions element.
290 * writer An instance of a machine interface writer.
292 * Returns zero if the element's value could be written.
293 * Negative values indicate an error.
295 int mi_lttng_sessions_open(struct mi_writer
*writer
);
298 * Machine interface of struct session.
300 * writer An instance of a machine interface writer.
301 * session An instance of a session.
302 * is_open Defines whether or not the session element shall be closed.
303 * This should be used carefully and the client
304 * must close the session element.
305 * Use case: nested addtionnal information on a session
306 * ex: domain,channel event.
308 * Returns zero if the element's value could be written.
309 * Negative values indicate an error.
311 int mi_lttng_session(struct mi_writer
*writer
,
312 struct lttng_session
*session
, int is_open
);
315 * Machine interface: open a domains element.
317 * writer An instance of a machine interface writer.
319 * Returns zero if the element's value could be written.
320 * Negative values indicate an error.
322 int mi_lttng_domains_open(struct mi_writer
*writer
);
325 * Machine interface of struct domain.
327 * writer An instance of a machine interface writer.
328 * domain An instance of a domain.
330 * is_open Defines whether or not the session element shall be closed.
331 * This should be used carefully and the client
332 * must close the domain element.
333 * Use case: nested addition information on a domain
336 * Returns zero if the element's value could be written.
337 * Negative values indicate an error.
339 int mi_lttng_domain(struct mi_writer
*writer
,
340 struct lttng_domain
*domain
, int is_open
);
343 * Machine interface: open a channels element.
345 * writer An instance of a machine interface writer.
347 * Returns zero if the element's value could be written.
348 * Negative values indicate an error.
350 int mi_lttng_channels_open(struct mi_writer
*writer
);
353 * Machine interface of struct channel.
355 * writer An instance of a machine interface writer.
356 * channel An instance of a channel.
358 * is_open Defines whether or not the session element shall be closed.
359 * This should be used carefully and the client
360 * must close the channel element.
361 * Use case: nested addition information on a channel.
364 * Returns zero if the element's value could be written.
365 * Negative values indicate an error.
367 int mi_lttng_channel(struct mi_writer
*writer
,
368 struct lttng_channel
*channel
, int is_open
);
371 * Machine interface of struct channel_attr.
373 * writer An instance of a machine interface writer.
374 * attr An instance of a channel_attr struct.
376 * Returns zero if the element's value could be written.
377 * Negative values indicate an error.
379 int mi_lttng_channel_attr(struct mi_writer
*writer
,
380 struct lttng_channel_attr
*attr
);
383 * Machine interface for event common attributes.
385 * writer An instance of a mi writer.
386 * event single trace event.
388 * The common attribute are:
395 * Returns zero if the element's value could be written.
396 * Negative values indicate an error.
398 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
399 struct lttng_event
*event
);
402 * Machine interface for kernel tracepoint event with a loglevel.
404 * writer An instance of a mi writer.
405 * event single trace event.
407 * Returns zero if the element's value could be written.
408 * Negative values indicate an error.
410 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
411 struct lttng_event
*event
);
414 * Machine interface for kernel tracepoint event with no loglevel.
416 * writer An instance of a mi writer.
417 * event single trace event.
419 * Returns zero if the element's value could be written.
420 * Negative values indicate an error.
422 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
423 struct lttng_event
*event
);
426 * Machine interface for kernel function and probe event.
428 * writer An instance of a mi writer.
429 * event single trace event.
431 * Returns zero if the element's value could be written.
432 * Negative values indicate an error.
434 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
435 struct lttng_event
*event
);
438 * Machine interface for kernel function entry event.
440 * writer An instance of a mi writer.
441 * event single trace event.
443 * Returns zero if the element's value could be written.
444 * Negative values indicate an error.
446 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
447 struct lttng_event
*event
);
450 * Machine interface: open an events element.
452 * writer An instance of a machine interface writer.
454 * Returns zero if the element's value could be written.
455 * Negative values indicate an error.
457 int mi_lttng_events_open(struct mi_writer
*writer
);
460 * Machine interface for printing an event.
461 * The trace event type currently supported are:
468 * writer An instance of a mi writer.
469 * event single trace event.
470 * is_open Defines whether or not the session element shall be closed.
471 * This should be used carefully and the client
472 * must close the event element.
473 * Use case: nested additional information
475 * Returns zero if the element's value could be written.
476 * Negative values indicate an error.
478 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
482 * Machine interface for struct lttng_event_field.
484 * writer An instance of a mi writer.
485 * field An event_field instance.
487 * Returns zero if the element's value could be written.
488 * Negative values indicate an error.
490 int mi_lttng_event_field(struct mi_writer
*writer
,
491 struct lttng_event_field
*field
);
494 * Machine interface: open a event_fields element.
496 * writer An instance of a machine interface writer.
498 * Returns zero if the element could be written.
499 * Negative values indicate an error.
501 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
504 * Machine interface: open a PIDs element.
506 * writer An instance of a machine interface writer.
508 * Returns zero if the element's value could be written.
509 * Negative values indicate an error.
511 int mi_lttng_pids_open(struct mi_writer
*writer
);
514 * Machine interface of a PID.
516 * writer An instance of a machine interface writer.
519 * is_open Defines whether or not the session element shall be closed.
520 * This should be used carefully and the client
521 * must close the pid element.
522 * Use case: nested addition information on a domain
525 * Returns zero if the element's value could be written.
526 * Negative values indicate an error.
528 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
532 * Machine interface for struct lttng_calibrate.
534 * writer An instance of a machine interface writer.
536 * calibrate A lttng_calibrate instance.
538 * Returns zero if the element's value could be written.
539 * Negative values indicate an error.
541 int mi_lttng_calibrate(struct mi_writer
*writer
,
542 struct lttng_calibrate
*calibrate
);
545 * Machine interface of a context.
547 * writer An instance of a machine interface writer
549 * context An instance of a lttng_event_context
551 * is_open Define if we close the context element
552 * This should be used carefully and the client
553 * need to close the context element.
556 * Returns zero if the element's value could be written.
557 * Negative values indicate an error.
559 int mi_lttng_context(struct mi_writer
*writer
,
560 struct lttng_event_context
*context
, int is_open
);
563 * Machine interface of a perf_counter_context.
565 * writer An instance of a machine interface writer
567 * contest An instance of a lttng_event_perf_counter_ctx
569 * Returns zero if the element's value could be written.
570 * Negative values indicate an error.
572 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
573 struct lttng_event_perf_counter_ctx
*perf_context
);
575 #endif /* _MI_LTTNG_H */