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_version
;
51 const char * const mi_lttng_element_command_list
;
52 const char * const mi_lttng_element_command_save
;
53 const char * const mi_lttng_element_command_load
;
54 const char * const mi_lttng_element_command_name
;
55 const char * const mi_lttng_element_command_output
;
56 const char * const mi_lttng_element_command_success
;
58 /* Strings related to version command */
59 const char * const mi_lttng_element_version
;
60 const char * const mi_lttng_element_version_str
;
61 const char * const mi_lttng_element_version_web
;
62 const char * const mi_lttng_element_version_major
;
63 const char * const mi_lttng_element_version_minor
;
64 const char * const mi_lttng_element_version_license
;
65 const char * const mi_lttng_element_version_commit
;
66 const char * const mi_lttng_element_version_patch_level
;
67 const char * const mi_lttng_element_version_description
;
69 /* String related to a lttng_event_field */
70 const char * const mi_lttng_element_event_field
;
71 const char * const mi_lttng_element_event_fields
;
73 /* Strings related to pid */
74 const char * const mi_lttng_element_pids
;
75 const char * const mi_lttng_element_pid
;
76 const char * const mi_lttng_element_pid_id
;
78 /* Strings related to save command */
79 const char * const mi_lttng_element_save
;
81 /* Strings related to load command */
82 const char * const mi_lttng_element_load
;
84 /* General element of mi_lttng */
85 const char * const mi_lttng_element_type_other
;
86 const char * const mi_lttng_element_type_integer
;
87 const char * const mi_lttng_element_type_enum
;
88 const char * const mi_lttng_element_type_float
;
89 const char * const mi_lttng_element_type_string
;
90 const char * const mi_lttng_element_nowrite
;
92 /* String related to loglevel */
93 const char * const mi_lttng_loglevel_str_alert
;
94 const char * const mi_lttng_loglevel_str_crit
;
95 const char * const mi_lttng_loglevel_str_debug
;
96 const char * const mi_lttng_loglevel_str_debug_function
;
97 const char * const mi_lttng_loglevel_str_debug_line
;
98 const char * const mi_lttng_loglevel_str_debug_module
;
99 const char * const mi_lttng_loglevel_str_debug_process
;
100 const char * const mi_lttng_loglevel_str_debug_program
;
101 const char * const mi_lttng_loglevel_str_debug_system
;
102 const char * const mi_lttng_loglevel_str_debug_unit
;
103 const char * const mi_lttng_loglevel_str_emerg
;
104 const char * const mi_lttng_loglevel_str_err
;
105 const char * const mi_lttng_loglevel_str_info
;
106 const char * const mi_lttng_loglevel_str_notice
;
107 const char * const mi_lttng_loglevel_str_unknown
;
108 const char * const mi_lttng_loglevel_str_warning
;
110 /* String related to loglevel type */
111 const char * const mi_lttng_loglevel_type_all
;
112 const char * const mi_lttng_loglevel_type_range
;
113 const char * const mi_lttng_loglevel_type_single
;
114 const char * const mi_lttng_loglevel_type_unknown
;
116 /* Utility string function */
117 const char *mi_lttng_loglevel_string(int value
);
118 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
119 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
120 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
121 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
124 * Create an instance of a machine interface writer.
126 * fd_output File to which the XML content must be written. The file will be
127 * closed once the mi_writer has been destroyed.
129 * Returns an instance of a machine interface writer on success, NULL on
132 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
135 * Destroy an instance of a machine interface writer.
137 * writer An instance of a machine interface writer.
139 * Returns zero if the XML document could be closed cleanly. Negative values
142 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
145 * Open a command tag and add it's name node.
147 * writer An instance of a machine interface writer.
148 * command The command name.
150 * Returns zero if the XML document could be closed cleanly.
151 * Negative values indicate an error.
153 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
156 * Close a command tag.
158 * writer An instance of a machine interface writer.
160 * Returns zero if the XML document could be closed cleanly.
161 * Negative values indicate an error.
163 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
166 * Open an element tag.
168 * writer An instance of a machine interface writer.
169 * element_name Element tag name.
171 * Returns zero if the XML document could be closed cleanly.
172 * Negative values indicate an error.
174 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
175 const char *element_name
);
178 * Close the current element 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_close_element(struct mi_writer
*writer
);
188 * Close multiple element.
190 * writer An instance of a machine interface writer.
191 * nb_element Number of elements.
193 * Returns zero if the XML document could be closed cleanly.
194 * Negative values indicate an error.
196 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
197 unsigned int nb_element
);
200 * Write an element of type unsigned int.
202 * writer An instance of a machine interface writer.
203 * element_name Element name.
204 * value Unsigned int value of the element
206 * Returns zero if the element's value could be written.
207 * Negative values indicate an error.
209 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
210 const char *element_name
, uint64_t value
);
213 * Write an element of type signed int.
215 * writer An instance of a machine interface writer.
216 * element_name Element name.
217 * value Signed int value of the element.
219 * Returns zero if the element's value could be written.
220 * Negative values indicate an error.
222 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
223 const char *element_name
, int64_t value
);
226 * Write an element of type boolean.
228 * writer An instance of a machine interface writer.
229 * element_name Element name.
230 * value Boolean value of the element.
232 * Returns zero if the element's value could be written.
233 * Negative values indicate an error.
235 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
236 const char *element_name
, int value
);
239 * Write an element of type string.
241 * writer An instance of a machine interface writer.
242 * element_name Element name.
243 * value String value of the element.
245 * Returns zero if the element's value could be written.
246 * Negative values indicate an error.
248 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
249 const char *element_name
, const char *value
);
252 * Machine interface of struct version.
254 * writer An instance of a machine interface writer.
255 * version Version struct.
256 * lttng_description String value of the version description.
257 * lttng_license String value of the version license.
259 * Returns zero if the element's value could be written.
260 * Negative values indicate an error.
262 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
263 const char *lttng_description
, const char *lttng_license
);
266 * Machine interface: open a sessions element.
268 * writer An instance of a machine interface writer.
270 * Returns zero if the element's value could be written.
271 * Negative values indicate an error.
273 int mi_lttng_sessions_open(struct mi_writer
*writer
);
276 * Machine interface of struct session.
278 * writer An instance of a machine interface writer.
279 * session An instance of a session.
280 * is_open Defines whether or not the session element shall be closed.
281 * This should be used carefully and the client
282 * must close the session element.
283 * Use case: nested addtionnal information on a session
284 * ex: domain,channel event.
286 * Returns zero if the element's value could be written.
287 * Negative values indicate an error.
289 int mi_lttng_session(struct mi_writer
*writer
,
290 struct lttng_session
*session
, int is_open
);
293 * Machine interface: open a domains element.
295 * writer An instance of a machine interface writer.
297 * Returns zero if the element's value could be written.
298 * Negative values indicate an error.
300 int mi_lttng_domains_open(struct mi_writer
*writer
);
303 * Machine interface of struct domain.
305 * writer An instance of a machine interface writer.
306 * domain An instance of a domain.
308 * is_open Defines whether or not the session element shall be closed.
309 * This should be used carefully and the client
310 * must close the domain element.
311 * Use case: nested addition information on a domain
314 * Returns zero if the element's value could be written.
315 * Negative values indicate an error.
317 int mi_lttng_domain(struct mi_writer
*writer
,
318 struct lttng_domain
*domain
, int is_open
);
321 * Machine interface: open a channels element.
323 * writer An instance of a machine interface writer.
325 * Returns zero if the element's value could be written.
326 * Negative values indicate an error.
328 int mi_lttng_channels_open(struct mi_writer
*writer
);
331 * Machine interface of struct channel.
333 * writer An instance of a machine interface writer.
334 * channel An instance of a channel.
336 * is_open Defines whether or not the session element shall be closed.
337 * This should be used carefully and the client
338 * must close the channel element.
339 * Use case: nested addition information on a channel.
342 * Returns zero if the element's value could be written.
343 * Negative values indicate an error.
345 int mi_lttng_channel(struct mi_writer
*writer
,
346 struct lttng_channel
*channel
, int is_open
);
349 * Machine interface of struct channel_attr.
351 * writer An instance of a machine interface writer.
352 * attr An instance of a channel_attr struct.
354 * Returns zero if the element's value could be written.
355 * Negative values indicate an error.
357 int mi_lttng_channel_attr(struct mi_writer
*writer
,
358 struct lttng_channel_attr
*attr
);
361 * Machine interface for event common attributes.
363 * writer An instance of a mi writer.
364 * event single trace event.
366 * The common attribute are:
373 * Returns zero if the element's value could be written.
374 * Negative values indicate an error.
376 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
377 struct lttng_event
*event
);
380 * Machine interface for kernel tracepoint event with a loglevel.
382 * writer An instance of a mi writer.
383 * event single trace event.
385 * Returns zero if the element's value could be written.
386 * Negative values indicate an error.
388 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
389 struct lttng_event
*event
);
392 * Machine interface for kernel tracepoint event with no loglevel.
394 * writer An instance of a mi writer.
395 * event single trace event.
397 * Returns zero if the element's value could be written.
398 * Negative values indicate an error.
400 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
401 struct lttng_event
*event
);
404 * Machine interface for kernel function and probe event.
406 * writer An instance of a mi writer.
407 * event single trace event.
409 * Returns zero if the element's value could be written.
410 * Negative values indicate an error.
412 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
413 struct lttng_event
*event
);
416 * Machine interface for kernel function entry event.
418 * writer An instance of a mi writer.
419 * event single trace event.
421 * Returns zero if the element's value could be written.
422 * Negative values indicate an error.
424 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
425 struct lttng_event
*event
);
428 * Machine interface: open an events element.
430 * writer An instance of a machine interface writer.
432 * Returns zero if the element's value could be written.
433 * Negative values indicate an error.
435 int mi_lttng_events_open(struct mi_writer
*writer
);
438 * Machine interface for printing an event.
439 * The trace event type currently supported are:
446 * writer An instance of a mi writer.
447 * event single trace event.
448 * is_open Defines whether or not the session element shall be closed.
449 * This should be used carefully and the client
450 * must close the event element.
451 * Use case: nested additional information
453 * Returns zero if the element's value could be written.
454 * Negative values indicate an error.
456 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
460 * Machine interface for struct lttng_event_field.
462 * writer An instance of a mi writer.
463 * field An event_field instance.
465 * Returns zero if the element's value could be written.
466 * Negative values indicate an error.
468 int mi_lttng_event_field(struct mi_writer
*writer
,
469 struct lttng_event_field
*field
);
472 * Machine interface: open a event_fields 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_event_fields_open(struct mi_writer
*writer
);
482 * Machine interface: open a PIDs 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_pids_open(struct mi_writer
*writer
);
492 * Machine interface of a PID.
494 * writer An instance of a machine interface writer.
497 * is_open Defines whether or not the session element shall be closed.
498 * This should be used carefully and the client
499 * must close the pid element.
500 * Use case: nested addition information on a domain
503 * Returns zero if the element's value could be written.
504 * Negative values indicate an error.
506 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
509 #endif /* _MI_LTTNG_H */