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_output
;
61 const char * const mi_lttng_element_command_success
;
63 /* Strings related to version command */
64 const char * const mi_lttng_element_version
;
65 const char * const mi_lttng_element_version_str
;
66 const char * const mi_lttng_element_version_web
;
67 const char * const mi_lttng_element_version_major
;
68 const char * const mi_lttng_element_version_minor
;
69 const char * const mi_lttng_element_version_license
;
70 const char * const mi_lttng_element_version_commit
;
71 const char * const mi_lttng_element_version_patch_level
;
72 const char * const mi_lttng_element_version_description
;
74 /* String related to a lttng_event_field */
75 const char * const mi_lttng_element_event_field
;
76 const char * const mi_lttng_element_event_fields
;
78 /* Strings related to pid */
79 const char * const mi_lttng_element_pids
;
80 const char * const mi_lttng_element_pid
;
81 const char * const mi_lttng_element_pid_id
;
83 /* Strings related to save command */
84 const char * const mi_lttng_element_save
;
86 /* Strings related to load command */
87 const char * const mi_lttng_element_load
;
89 /* General element of mi_lttng */
90 const char * const mi_lttng_element_type_other
;
91 const char * const mi_lttng_element_type_integer
;
92 const char * const mi_lttng_element_type_enum
;
93 const char * const mi_lttng_element_type_float
;
94 const char * const mi_lttng_element_type_string
;
95 const char * const mi_lttng_element_nowrite
;
97 /* String related to loglevel */
98 const char * const mi_lttng_loglevel_str_alert
;
99 const char * const mi_lttng_loglevel_str_crit
;
100 const char * const mi_lttng_loglevel_str_debug
;
101 const char * const mi_lttng_loglevel_str_debug_function
;
102 const char * const mi_lttng_loglevel_str_debug_line
;
103 const char * const mi_lttng_loglevel_str_debug_module
;
104 const char * const mi_lttng_loglevel_str_debug_process
;
105 const char * const mi_lttng_loglevel_str_debug_program
;
106 const char * const mi_lttng_loglevel_str_debug_system
;
107 const char * const mi_lttng_loglevel_str_debug_unit
;
108 const char * const mi_lttng_loglevel_str_emerg
;
109 const char * const mi_lttng_loglevel_str_err
;
110 const char * const mi_lttng_loglevel_str_info
;
111 const char * const mi_lttng_loglevel_str_notice
;
112 const char * const mi_lttng_loglevel_str_unknown
;
113 const char * const mi_lttng_loglevel_str_warning
;
115 /* String related to loglevel type */
116 const char * const mi_lttng_loglevel_type_all
;
117 const char * const mi_lttng_loglevel_type_range
;
118 const char * const mi_lttng_loglevel_type_single
;
119 const char * const mi_lttng_loglevel_type_unknown
;
121 /* Sting related to lttng_calibrate */
122 const char * const mi_lttng_element_calibrate
;
123 const char * const mi_lttng_element_calibrate_function
;
125 /* Utility string function */
126 const char *mi_lttng_loglevel_string(int value
);
127 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
128 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
129 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
130 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
131 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
);
134 * Create an instance of a machine interface writer.
136 * fd_output File to which the XML content must be written. The file will be
137 * closed once the mi_writer has been destroyed.
139 * Returns an instance of a machine interface writer on success, NULL on
142 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
145 * Destroy an instance of a machine interface writer.
147 * writer An instance of a machine interface writer.
149 * Returns zero if the XML document could be closed cleanly. Negative values
152 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
155 * Open a command tag and add it's name node.
157 * writer An instance of a machine interface writer.
158 * command The command name.
160 * Returns zero if the XML document could be closed cleanly.
161 * Negative values indicate an error.
163 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
166 * Close a command tag.
168 * writer An instance of a machine interface writer.
170 * Returns zero if the XML document could be closed cleanly.
171 * Negative values indicate an error.
173 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
176 * Open an element tag.
178 * writer An instance of a machine interface writer.
179 * element_name Element tag name.
181 * Returns zero if the XML document could be closed cleanly.
182 * Negative values indicate an error.
184 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
185 const char *element_name
);
188 * Close the current element tag.
190 * writer An instance of a machine interface writer.
192 * Returns zero if the XML document could be closed cleanly.
193 * Negative values indicate an error.
195 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
198 * Close multiple element.
200 * writer An instance of a machine interface writer.
201 * nb_element Number of elements.
203 * Returns zero if the XML document could be closed cleanly.
204 * Negative values indicate an error.
206 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
207 unsigned int nb_element
);
210 * Write an element of type unsigned int.
212 * writer An instance of a machine interface writer.
213 * element_name Element name.
214 * value Unsigned int value of the element
216 * Returns zero if the element's value could be written.
217 * Negative values indicate an error.
219 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
220 const char *element_name
, uint64_t value
);
223 * Write an element of type signed int.
225 * writer An instance of a machine interface writer.
226 * element_name Element name.
227 * value Signed int value of the element.
229 * Returns zero if the element's value could be written.
230 * Negative values indicate an error.
232 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
233 const char *element_name
, int64_t value
);
236 * Write an element of type boolean.
238 * writer An instance of a machine interface writer.
239 * element_name Element name.
240 * value Boolean value of the element.
242 * Returns zero if the element's value could be written.
243 * Negative values indicate an error.
245 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
246 const char *element_name
, int value
);
249 * Write an element of type string.
251 * writer An instance of a machine interface writer.
252 * element_name Element name.
253 * value String value of the element.
255 * Returns zero if the element's value could be written.
256 * Negative values indicate an error.
258 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
259 const char *element_name
, const char *value
);
262 * Machine interface of struct version.
264 * writer An instance of a machine interface writer.
265 * version Version struct.
266 * lttng_description String value of the version description.
267 * lttng_license String value of the version license.
269 * Returns zero if the element's value could be written.
270 * Negative values indicate an error.
272 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
273 const char *lttng_description
, const char *lttng_license
);
276 * Machine interface: open a sessions element.
278 * writer An instance of a machine interface writer.
280 * Returns zero if the element's value could be written.
281 * Negative values indicate an error.
283 int mi_lttng_sessions_open(struct mi_writer
*writer
);
286 * Machine interface of struct session.
288 * writer An instance of a machine interface writer.
289 * session An instance of a session.
290 * is_open Defines whether or not the session element shall be closed.
291 * This should be used carefully and the client
292 * must close the session element.
293 * Use case: nested addtionnal information on a session
294 * ex: domain,channel event.
296 * Returns zero if the element's value could be written.
297 * Negative values indicate an error.
299 int mi_lttng_session(struct mi_writer
*writer
,
300 struct lttng_session
*session
, int is_open
);
303 * Machine interface: open a domains element.
305 * writer An instance of a machine interface writer.
307 * Returns zero if the element's value could be written.
308 * Negative values indicate an error.
310 int mi_lttng_domains_open(struct mi_writer
*writer
);
313 * Machine interface of struct domain.
315 * writer An instance of a machine interface writer.
316 * domain An instance of a domain.
318 * is_open Defines whether or not the session element shall be closed.
319 * This should be used carefully and the client
320 * must close the domain element.
321 * Use case: nested addition information on a domain
324 * Returns zero if the element's value could be written.
325 * Negative values indicate an error.
327 int mi_lttng_domain(struct mi_writer
*writer
,
328 struct lttng_domain
*domain
, int is_open
);
331 * Machine interface: open a channels element.
333 * writer An instance of a machine interface writer.
335 * Returns zero if the element's value could be written.
336 * Negative values indicate an error.
338 int mi_lttng_channels_open(struct mi_writer
*writer
);
341 * Machine interface of struct channel.
343 * writer An instance of a machine interface writer.
344 * channel An instance of a channel.
346 * is_open Defines whether or not the session element shall be closed.
347 * This should be used carefully and the client
348 * must close the channel element.
349 * Use case: nested addition information on a channel.
352 * Returns zero if the element's value could be written.
353 * Negative values indicate an error.
355 int mi_lttng_channel(struct mi_writer
*writer
,
356 struct lttng_channel
*channel
, int is_open
);
359 * Machine interface of struct channel_attr.
361 * writer An instance of a machine interface writer.
362 * attr An instance of a channel_attr struct.
364 * Returns zero if the element's value could be written.
365 * Negative values indicate an error.
367 int mi_lttng_channel_attr(struct mi_writer
*writer
,
368 struct lttng_channel_attr
*attr
);
371 * Machine interface for event common attributes.
373 * writer An instance of a mi writer.
374 * event single trace event.
376 * The common attribute are:
383 * Returns zero if the element's value could be written.
384 * Negative values indicate an error.
386 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
387 struct lttng_event
*event
);
390 * Machine interface for kernel tracepoint event with a loglevel.
392 * writer An instance of a mi writer.
393 * event single trace event.
395 * Returns zero if the element's value could be written.
396 * Negative values indicate an error.
398 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
399 struct lttng_event
*event
);
402 * Machine interface for kernel tracepoint event with no 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_no_loglevel(struct mi_writer
*writer
,
411 struct lttng_event
*event
);
414 * Machine interface for kernel function and probe event.
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_function_probe(struct mi_writer
*writer
,
423 struct lttng_event
*event
);
426 * Machine interface for kernel function entry 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_entry(struct mi_writer
*writer
,
435 struct lttng_event
*event
);
438 * Machine interface: open an events element.
440 * writer An instance of a machine interface writer.
442 * Returns zero if the element's value could be written.
443 * Negative values indicate an error.
445 int mi_lttng_events_open(struct mi_writer
*writer
);
448 * Machine interface for printing an event.
449 * The trace event type currently supported are:
456 * writer An instance of a mi writer.
457 * event single trace event.
458 * is_open Defines whether or not the session element shall be closed.
459 * This should be used carefully and the client
460 * must close the event element.
461 * Use case: nested additional information
463 * Returns zero if the element's value could be written.
464 * Negative values indicate an error.
466 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
470 * Machine interface for struct lttng_event_field.
472 * writer An instance of a mi writer.
473 * field An event_field instance.
475 * Returns zero if the element's value could be written.
476 * Negative values indicate an error.
478 int mi_lttng_event_field(struct mi_writer
*writer
,
479 struct lttng_event_field
*field
);
482 * Machine interface: open a event_fields element.
484 * writer An instance of a machine interface writer.
486 * Returns zero if the element's value could be written.
487 * Negative values indicate an error.
489 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
492 * Machine interface: open a PIDs element.
494 * writer An instance of a machine interface writer.
496 * Returns zero if the element's value could be written.
497 * Negative values indicate an error.
499 int mi_lttng_pids_open(struct mi_writer
*writer
);
502 * Machine interface of a PID.
504 * writer An instance of a machine interface writer.
507 * is_open Defines whether or not the session element shall be closed.
508 * This should be used carefully and the client
509 * must close the pid element.
510 * Use case: nested addition information on a domain
513 * Returns zero if the element's value could be written.
514 * Negative values indicate an error.
516 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
520 * Machine interface for struct lttng_calibrate.
522 * writer An instance of a machine interface writer.
524 * calibrate A lttng_calibrate instance.
526 * Returns zero if the element's value could be written.
527 * Negative values indicate an error.
529 int mi_lttng_calibrate(struct mi_writer
*writer
,
530 struct lttng_calibrate
*calibrate
);
532 #endif /* _MI_LTTNG_H */