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_output
;
59 const char * const mi_lttng_element_command_success
;
61 /* Strings related to version command */
62 const char * const mi_lttng_element_version
;
63 const char * const mi_lttng_element_version_str
;
64 const char * const mi_lttng_element_version_web
;
65 const char * const mi_lttng_element_version_major
;
66 const char * const mi_lttng_element_version_minor
;
67 const char * const mi_lttng_element_version_license
;
68 const char * const mi_lttng_element_version_commit
;
69 const char * const mi_lttng_element_version_patch_level
;
70 const char * const mi_lttng_element_version_description
;
72 /* String related to a lttng_event_field */
73 const char * const mi_lttng_element_event_field
;
74 const char * const mi_lttng_element_event_fields
;
76 /* Strings related to pid */
77 const char * const mi_lttng_element_pids
;
78 const char * const mi_lttng_element_pid
;
79 const char * const mi_lttng_element_pid_id
;
81 /* Strings related to save command */
82 const char * const mi_lttng_element_save
;
84 /* Strings related to load command */
85 const char * const mi_lttng_element_load
;
87 /* General element of mi_lttng */
88 const char * const mi_lttng_element_type_other
;
89 const char * const mi_lttng_element_type_integer
;
90 const char * const mi_lttng_element_type_enum
;
91 const char * const mi_lttng_element_type_float
;
92 const char * const mi_lttng_element_type_string
;
93 const char * const mi_lttng_element_nowrite
;
95 /* String related to loglevel */
96 const char * const mi_lttng_loglevel_str_alert
;
97 const char * const mi_lttng_loglevel_str_crit
;
98 const char * const mi_lttng_loglevel_str_debug
;
99 const char * const mi_lttng_loglevel_str_debug_function
;
100 const char * const mi_lttng_loglevel_str_debug_line
;
101 const char * const mi_lttng_loglevel_str_debug_module
;
102 const char * const mi_lttng_loglevel_str_debug_process
;
103 const char * const mi_lttng_loglevel_str_debug_program
;
104 const char * const mi_lttng_loglevel_str_debug_system
;
105 const char * const mi_lttng_loglevel_str_debug_unit
;
106 const char * const mi_lttng_loglevel_str_emerg
;
107 const char * const mi_lttng_loglevel_str_err
;
108 const char * const mi_lttng_loglevel_str_info
;
109 const char * const mi_lttng_loglevel_str_notice
;
110 const char * const mi_lttng_loglevel_str_unknown
;
111 const char * const mi_lttng_loglevel_str_warning
;
113 /* String related to loglevel type */
114 const char * const mi_lttng_loglevel_type_all
;
115 const char * const mi_lttng_loglevel_type_range
;
116 const char * const mi_lttng_loglevel_type_single
;
117 const char * const mi_lttng_loglevel_type_unknown
;
119 /* Utility string function */
120 const char *mi_lttng_loglevel_string(int value
);
121 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
);
122 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value
);
123 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
);
124 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
);
127 * Create an instance of a machine interface writer.
129 * fd_output File to which the XML content must be written. The file will be
130 * closed once the mi_writer has been destroyed.
132 * Returns an instance of a machine interface writer on success, NULL on
135 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
138 * Destroy an instance of a machine interface writer.
140 * writer An instance of a machine interface writer.
142 * Returns zero if the XML document could be closed cleanly. Negative values
145 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
148 * Open a command tag and add it's name node.
150 * writer An instance of a machine interface writer.
151 * command The command name.
153 * Returns zero if the XML document could be closed cleanly.
154 * Negative values indicate an error.
156 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
159 * Close a command tag.
161 * writer An instance of a machine interface writer.
163 * Returns zero if the XML document could be closed cleanly.
164 * Negative values indicate an error.
166 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
169 * Open an element tag.
171 * writer An instance of a machine interface writer.
172 * element_name Element tag name.
174 * Returns zero if the XML document could be closed cleanly.
175 * Negative values indicate an error.
177 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
178 const char *element_name
);
181 * Close the current element tag.
183 * writer An instance of a machine interface writer.
185 * Returns zero if the XML document could be closed cleanly.
186 * Negative values indicate an error.
188 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
191 * Close multiple element.
193 * writer An instance of a machine interface writer.
194 * nb_element Number of elements.
196 * Returns zero if the XML document could be closed cleanly.
197 * Negative values indicate an error.
199 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
200 unsigned int nb_element
);
203 * Write an element of type unsigned int.
205 * writer An instance of a machine interface writer.
206 * element_name Element name.
207 * value Unsigned int value of the element
209 * Returns zero if the element's value could be written.
210 * Negative values indicate an error.
212 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
213 const char *element_name
, uint64_t value
);
216 * Write an element of type signed int.
218 * writer An instance of a machine interface writer.
219 * element_name Element name.
220 * value Signed int value of the element.
222 * Returns zero if the element's value could be written.
223 * Negative values indicate an error.
225 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
226 const char *element_name
, int64_t value
);
229 * Write an element of type boolean.
231 * writer An instance of a machine interface writer.
232 * element_name Element name.
233 * value Boolean value of the element.
235 * Returns zero if the element's value could be written.
236 * Negative values indicate an error.
238 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
239 const char *element_name
, int value
);
242 * Write an element of type string.
244 * writer An instance of a machine interface writer.
245 * element_name Element name.
246 * value String value of the element.
248 * Returns zero if the element's value could be written.
249 * Negative values indicate an error.
251 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
252 const char *element_name
, const char *value
);
255 * Machine interface of struct version.
257 * writer An instance of a machine interface writer.
258 * version Version struct.
259 * lttng_description String value of the version description.
260 * lttng_license String value of the version license.
262 * Returns zero if the element's value could be written.
263 * Negative values indicate an error.
265 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
266 const char *lttng_description
, const char *lttng_license
);
269 * Machine interface: open a sessions element.
271 * writer An instance of a machine interface writer.
273 * Returns zero if the element's value could be written.
274 * Negative values indicate an error.
276 int mi_lttng_sessions_open(struct mi_writer
*writer
);
279 * Machine interface of struct session.
281 * writer An instance of a machine interface writer.
282 * session An instance of a session.
283 * is_open Defines whether or not the session element shall be closed.
284 * This should be used carefully and the client
285 * must close the session element.
286 * Use case: nested addtionnal information on a session
287 * ex: domain,channel event.
289 * Returns zero if the element's value could be written.
290 * Negative values indicate an error.
292 int mi_lttng_session(struct mi_writer
*writer
,
293 struct lttng_session
*session
, int is_open
);
296 * Machine interface: open a domains element.
298 * writer An instance of a machine interface writer.
300 * Returns zero if the element's value could be written.
301 * Negative values indicate an error.
303 int mi_lttng_domains_open(struct mi_writer
*writer
);
306 * Machine interface of struct domain.
308 * writer An instance of a machine interface writer.
309 * domain An instance of a domain.
311 * is_open Defines whether or not the session element shall be closed.
312 * This should be used carefully and the client
313 * must close the domain element.
314 * Use case: nested addition information on a domain
317 * Returns zero if the element's value could be written.
318 * Negative values indicate an error.
320 int mi_lttng_domain(struct mi_writer
*writer
,
321 struct lttng_domain
*domain
, int is_open
);
324 * Machine interface: open a channels element.
326 * writer An instance of a machine interface writer.
328 * Returns zero if the element's value could be written.
329 * Negative values indicate an error.
331 int mi_lttng_channels_open(struct mi_writer
*writer
);
334 * Machine interface of struct channel.
336 * writer An instance of a machine interface writer.
337 * channel An instance of a channel.
339 * is_open Defines whether or not the session element shall be closed.
340 * This should be used carefully and the client
341 * must close the channel element.
342 * Use case: nested addition information on a channel.
345 * Returns zero if the element's value could be written.
346 * Negative values indicate an error.
348 int mi_lttng_channel(struct mi_writer
*writer
,
349 struct lttng_channel
*channel
, int is_open
);
352 * Machine interface of struct channel_attr.
354 * writer An instance of a machine interface writer.
355 * attr An instance of a channel_attr struct.
357 * Returns zero if the element's value could be written.
358 * Negative values indicate an error.
360 int mi_lttng_channel_attr(struct mi_writer
*writer
,
361 struct lttng_channel_attr
*attr
);
364 * Machine interface for event common attributes.
366 * writer An instance of a mi writer.
367 * event single trace event.
369 * The common attribute are:
376 * Returns zero if the element's value could be written.
377 * Negative values indicate an error.
379 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
380 struct lttng_event
*event
);
383 * Machine interface for kernel tracepoint event with a loglevel.
385 * writer An instance of a mi writer.
386 * event single trace event.
388 * Returns zero if the element's value could be written.
389 * Negative values indicate an error.
391 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
392 struct lttng_event
*event
);
395 * Machine interface for kernel tracepoint event with no loglevel.
397 * writer An instance of a mi writer.
398 * event single trace event.
400 * Returns zero if the element's value could be written.
401 * Negative values indicate an error.
403 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
404 struct lttng_event
*event
);
407 * Machine interface for kernel function and probe event.
409 * writer An instance of a mi writer.
410 * event single trace event.
412 * Returns zero if the element's value could be written.
413 * Negative values indicate an error.
415 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
416 struct lttng_event
*event
);
419 * Machine interface for kernel function entry event.
421 * writer An instance of a mi writer.
422 * event single trace event.
424 * Returns zero if the element's value could be written.
425 * Negative values indicate an error.
427 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
428 struct lttng_event
*event
);
431 * Machine interface: open an events element.
433 * writer An instance of a machine interface writer.
435 * Returns zero if the element's value could be written.
436 * Negative values indicate an error.
438 int mi_lttng_events_open(struct mi_writer
*writer
);
441 * Machine interface for printing an event.
442 * The trace event type currently supported are:
449 * writer An instance of a mi writer.
450 * event single trace event.
451 * is_open Defines whether or not the session element shall be closed.
452 * This should be used carefully and the client
453 * must close the event element.
454 * Use case: nested additional information
456 * Returns zero if the element's value could be written.
457 * Negative values indicate an error.
459 int mi_lttng_event(struct mi_writer
*writer
, struct lttng_event
*event
,
463 * Machine interface for struct lttng_event_field.
465 * writer An instance of a mi writer.
466 * field An event_field instance.
468 * Returns zero if the element's value could be written.
469 * Negative values indicate an error.
471 int mi_lttng_event_field(struct mi_writer
*writer
,
472 struct lttng_event_field
*field
);
475 * Machine interface: open a event_fields element.
477 * writer An instance of a machine interface writer.
479 * Returns zero if the element's value could be written.
480 * Negative values indicate an error.
482 int mi_lttng_event_fields_open(struct mi_writer
*writer
);
485 * Machine interface: open a PIDs element.
487 * writer An instance of a machine interface writer.
489 * Returns zero if the element's value could be written.
490 * Negative values indicate an error.
492 int mi_lttng_pids_open(struct mi_writer
*writer
);
495 * Machine interface of a PID.
497 * writer An instance of a machine interface writer.
500 * is_open Defines whether or not the session element shall be closed.
501 * This should be used carefully and the client
502 * must close the pid element.
503 * Use case: nested addition information on a domain
506 * Returns zero if the element's value could be written.
507 * Negative values indicate an error.
509 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
512 #endif /* _MI_LTTNG_H */