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_list
;
53 const char * const mi_lttng_element_command_save
;
54 const char * const mi_lttng_element_command_load
;
55 const char * const mi_lttng_element_command_stop
;
56 const char * const mi_lttng_element_command_start
;
57 const char * const mi_lttng_element_command_create
;
58 const char * const mi_lttng_element_command_destroy
;
59 const char * const mi_lttng_element_command_calibrate
;
60 const char * const mi_lttng_element_command_add_context
;
61 const char * const mi_lttng_element_command_enable_channels
;
62 const char * const mi_lttng_element_command_output
;
63 const char * const mi_lttng_element_command_success
;
65 /* Strings related to version command */
66 const char * const mi_lttng_element_version
;
67 const char * const mi_lttng_element_version_str
;
68 const char * const mi_lttng_element_version_web
;
69 const char * const mi_lttng_element_version_major
;
70 const char * const mi_lttng_element_version_minor
;
71 const char * const mi_lttng_element_version_license
;
72 const char * const mi_lttng_element_version_commit
;
73 const char * const mi_lttng_element_version_patch_level
;
74 const char * const mi_lttng_element_version_description
;
76 /* String related to a lttng_event_field */
77 const char * const mi_lttng_element_event_field
;
78 const char * const mi_lttng_element_event_fields
;
80 /* String related to lttng_event_context */
81 const char * const mi_lttng_context_type_perf_counter
;
82 const char * const mi_lttng_context_type_perf_cpu_counter
;
83 const char * const mi_lttng_context_type_perf_thread_counter
;
85 /* String related to lttng_event_perf_counter_ctx */
86 const char * const mi_lttng_element_perf_counter_context
;
88 /* Strings related to pid */
89 const char * const mi_lttng_element_pids
;
90 const char * const mi_lttng_element_pid
;
91 const char * const mi_lttng_element_pid_id
;
93 /* Strings related to save command */
94 const char * const mi_lttng_element_save
;
96 /* Strings related to load command */
97 const char * const mi_lttng_element_load
;
99 /* General element of mi_lttng */
100 const char * const mi_lttng_element_type_other
;
101 const char * const mi_lttng_element_type_integer
;
102 const char * const mi_lttng_element_type_enum
;
103 const char * const mi_lttng_element_type_float
;
104 const char * const mi_lttng_element_type_string
;
105 const char * const mi_lttng_element_nowrite
;
106 const char * const mi_lttng_element_success
;
108 /* String related to loglevel */
109 const char * const mi_lttng_loglevel_str_alert
;
110 const char * const mi_lttng_loglevel_str_crit
;
111 const char * const mi_lttng_loglevel_str_debug
;
112 const char * const mi_lttng_loglevel_str_debug_function
;
113 const char * const mi_lttng_loglevel_str_debug_line
;
114 const char * const mi_lttng_loglevel_str_debug_module
;
115 const char * const mi_lttng_loglevel_str_debug_process
;
116 const char * const mi_lttng_loglevel_str_debug_program
;
117 const char * const mi_lttng_loglevel_str_debug_system
;
118 const char * const mi_lttng_loglevel_str_debug_unit
;
119 const char * const mi_lttng_loglevel_str_emerg
;
120 const char * const mi_lttng_loglevel_str_err
;
121 const char * const mi_lttng_loglevel_str_info
;
122 const char * const mi_lttng_loglevel_str_notice
;
123 const char * const mi_lttng_loglevel_str_unknown
;
124 const char * const mi_lttng_loglevel_str_warning
;
126 /* String related to loglevel type */
127 const char * const mi_lttng_loglevel_type_all
;
128 const char * const mi_lttng_loglevel_type_range
;
129 const char * const mi_lttng_loglevel_type_single
;
130 const char * const mi_lttng_loglevel_type_unknown
;
132 /* Sting related to lttng_calibrate */
133 const char * const mi_lttng_element_calibrate
;
134 const char * const mi_lttng_element_calibrate_function
;
136 /* Utility string function */
137 const char *mi_lttng_loglevel_string(int value
);
138 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
139 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
140 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
141 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
142 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
);
145 * Create an instance of a machine interface writer.
147 * fd_output File to which the XML content must be written. The file will be
148 * closed once the mi_writer has been destroyed.
150 * Returns an instance of a machine interface writer on success, NULL on
153 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
156 * Destroy an instance of a machine interface writer.
158 * writer An instance of a machine interface writer.
160 * Returns zero if the XML document could be closed cleanly. Negative values
163 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
166 * Open a command tag and add it's name node.
168 * writer An instance of a machine interface writer.
169 * command The command name.
171 * Returns zero if the XML document could be closed cleanly.
172 * Negative values indicate an error.
174 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
177 * Close a command tag.
179 * writer An instance of a machine interface writer.
181 * Returns zero if the XML document could be closed cleanly.
182 * Negative values indicate an error.
184 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
187 * Open an element tag.
189 * writer An instance of a machine interface writer.
190 * element_name Element tag name.
192 * Returns zero if the XML document could be closed cleanly.
193 * Negative values indicate an error.
195 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
196 const char *element_name
);
199 * Close the current element tag.
201 * writer An instance of a machine interface writer.
203 * Returns zero if the XML document could be closed cleanly.
204 * Negative values indicate an error.
206 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
209 * Close multiple element.
211 * writer An instance of a machine interface writer.
212 * nb_element Number of elements.
214 * Returns zero if the XML document could be closed cleanly.
215 * Negative values indicate an error.
217 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
218 unsigned int nb_element
);
221 * Write an element of type unsigned int.
223 * writer An instance of a machine interface writer.
224 * element_name Element name.
225 * value Unsigned int value of the element
227 * Returns zero if the element's value could be written.
228 * Negative values indicate an error.
230 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
231 const char *element_name
, uint64_t value
);
234 * Write an element of type signed int.
236 * writer An instance of a machine interface writer.
237 * element_name Element name.
238 * value Signed int value of the element.
240 * Returns zero if the element's value could be written.
241 * Negative values indicate an error.
243 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
244 const char *element_name
, int64_t value
);
247 * Write an element of type boolean.
249 * writer An instance of a machine interface writer.
250 * element_name Element name.
251 * value Boolean value of the element.
253 * Returns zero if the element's value could be written.
254 * Negative values indicate an error.
256 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
257 const char *element_name
, int value
);
260 * Write an element of type string.
262 * writer An instance of a machine interface writer.
263 * element_name Element name.
264 * value String value of the element.
266 * Returns zero if the element's value could be written.
267 * Negative values indicate an error.
269 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
270 const char *element_name
, const char *value
);
273 * Machine interface of struct version.
275 * writer An instance of a machine interface writer.
276 * version Version struct.
277 * lttng_description String value of the version description.
278 * lttng_license String value of the version license.
280 * Returns zero if the element's value could be written.
281 * Negative values indicate an error.
283 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
284 const char *lttng_description
, const char *lttng_license
);
287 * Machine interface: open a sessions element.
289 * writer An instance of a machine interface writer.
291 * Returns zero if the element's value could be written.
292 * Negative values indicate an error.
294 int mi_lttng_sessions_open(struct mi_writer
*writer
);
297 * Machine interface of struct session.
299 * writer An instance of a machine interface writer.
300 * session An instance of a session.
301 * is_open Defines whether or not the session element shall be closed.
302 * This should be used carefully and the client
303 * must close the session element.
304 * Use case: nested addtionnal information on a session
305 * ex: domain,channel event.
307 * Returns zero if the element's value could be written.
308 * Negative values indicate an error.
310 int mi_lttng_session(struct mi_writer
*writer
,
311 struct lttng_session
*session
, int is_open
);
314 * Machine interface: open a domains element.
316 * writer An instance of a machine interface writer.
318 * Returns zero if the element's value could be written.
319 * Negative values indicate an error.
321 int mi_lttng_domains_open(struct mi_writer
*writer
);
324 * Machine interface of struct domain.
326 * writer An instance of a machine interface writer.
327 * domain An instance of a domain.
329 * is_open Defines whether or not the session element shall be closed.
330 * This should be used carefully and the client
331 * must close the domain element.
332 * Use case: nested addition information on a domain
335 * Returns zero if the element's value could be written.
336 * Negative values indicate an error.
338 int mi_lttng_domain(struct mi_writer
*writer
,
339 struct lttng_domain
*domain
, int is_open
);
342 * Machine interface: open a channels element.
344 * writer An instance of a machine interface writer.
346 * Returns zero if the element's value could be written.
347 * Negative values indicate an error.
349 int mi_lttng_channels_open(struct mi_writer
*writer
);
352 * Machine interface of struct channel.
354 * writer An instance of a machine interface writer.
355 * channel An instance of a channel.
357 * is_open Defines whether or not the session element shall be closed.
358 * This should be used carefully and the client
359 * must close the channel element.
360 * Use case: nested addition information on a channel.
363 * Returns zero if the element's value could be written.
364 * Negative values indicate an error.
366 int mi_lttng_channel(struct mi_writer
*writer
,
367 struct lttng_channel
*channel
, int is_open
);
370 * Machine interface of struct channel_attr.
372 * writer An instance of a machine interface writer.
373 * attr An instance of a channel_attr struct.
375 * Returns zero if the element's value could be written.
376 * Negative values indicate an error.
378 int mi_lttng_channel_attr(struct mi_writer
*writer
,
379 struct lttng_channel_attr
*attr
);
382 * Machine interface for event common attributes.
384 * writer An instance of a mi writer.
385 * event single trace event.
387 * The common attribute are:
394 * Returns zero if the element's value could be written.
395 * Negative values indicate an error.
397 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
398 struct lttng_event
*event
);
401 * Machine interface for kernel tracepoint event with a loglevel.
403 * writer An instance of a mi writer.
404 * event single trace event.
406 * Returns zero if the element's value could be written.
407 * Negative values indicate an error.
409 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
410 struct lttng_event
*event
);
413 * Machine interface for kernel tracepoint event with no loglevel.
415 * writer An instance of a mi writer.
416 * event single trace event.
418 * Returns zero if the element's value could be written.
419 * Negative values indicate an error.
421 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
422 struct lttng_event
*event
);
425 * Machine interface for kernel function and probe event.
427 * writer An instance of a mi writer.
428 * event single trace event.
430 * Returns zero if the element's value could be written.
431 * Negative values indicate an error.
433 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
434 struct lttng_event
*event
);
437 * Machine interface for kernel function entry event.
439 * writer An instance of a mi writer.
440 * event single trace event.
442 * Returns zero if the element's value could be written.
443 * Negative values indicate an error.
445 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
446 struct lttng_event
*event
);
449 * Machine interface: open an events element.
451 * writer An instance of a machine interface writer.
453 * Returns zero if the element's value could be written.
454 * Negative values indicate an error.
456 int mi_lttng_events_open(struct mi_writer
*writer
);
459 * Machine interface for printing an event.
460 * The trace event type currently supported are:
467 * writer An instance of a mi writer.
468 * event single trace event.
469 * is_open Defines whether or not the session element shall be closed.
470 * This should be used carefully and the client
471 * must close the event element.
472 * Use case: nested additional information
474 * Returns zero if the element's value could be written.
475 * Negative values indicate an error.
477 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
481 * Machine interface for struct lttng_event_field.
483 * writer An instance of a mi writer.
484 * field An event_field instance.
486 * Returns zero if the element's value could be written.
487 * Negative values indicate an error.
489 int mi_lttng_event_field(struct mi_writer
*writer
,
490 struct lttng_event_field
*field
);
493 * Machine interface: open a event_fields element.
495 * writer An instance of a machine interface writer.
497 * Returns zero if the element could be written.
498 * Negative values indicate an error.
500 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
503 * Machine interface: open a PIDs element.
505 * writer An instance of a machine interface writer.
507 * Returns zero if the element's value could be written.
508 * Negative values indicate an error.
510 int mi_lttng_pids_open(struct mi_writer
*writer
);
513 * Machine interface of a PID.
515 * writer An instance of a machine interface writer.
518 * is_open Defines whether or not the session element shall be closed.
519 * This should be used carefully and the client
520 * must close the pid element.
521 * Use case: nested addition information on a domain
524 * Returns zero if the element's value could be written.
525 * Negative values indicate an error.
527 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
531 * Machine interface for struct lttng_calibrate.
533 * writer An instance of a machine interface writer.
535 * calibrate A lttng_calibrate instance.
537 * Returns zero if the element's value could be written.
538 * Negative values indicate an error.
540 int mi_lttng_calibrate(struct mi_writer
*writer
,
541 struct lttng_calibrate
*calibrate
);
544 * Machine interface of a context.
546 * writer An instance of a machine interface writer
548 * context An instance of a lttng_event_context
550 * is_open Define if we close the context element
551 * This should be used carefully and the client
552 * need to close the context element.
555 * Returns zero if the element's value could be written.
556 * Negative values indicate an error.
558 int mi_lttng_context(struct mi_writer
*writer
,
559 struct lttng_event_context
*context
, int is_open
);
562 * Machine interface of a perf_counter_context.
564 * writer An instance of a machine interface writer
566 * contest An instance of a lttng_event_perf_counter_ctx
568 * Returns zero if the element's value could be written.
569 * Negative values indicate an error.
571 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
572 struct lttng_event_perf_counter_ctx
*perf_context
);
574 #endif /* _MI_LTTNG_H */