events.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. #ifndef _BABELTRACE_CTF_EVENTS_H
  2. #define _BABELTRACE_CTF_EVENTS_H
  3. /*
  4. * BabelTrace
  5. *
  6. * CTF events API
  7. *
  8. * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation
  9. *
  10. * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  11. * Julien Desfossez <julien.desfossez@efficios.com>
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining
  14. * a copy of this software and associated documentation files (the
  15. * "Software"), to deal in the Software without restriction, including
  16. * without limitation the rights to use, copy, modify, merge, publish,
  17. * distribute, sublicense, and/or sell copies of the Software, and to
  18. * permit persons to whom the Software is furnished to do so, subject to
  19. * the following conditions:
  20. *
  21. * The above copyright notice and this permission notice shall be
  22. * included in all copies or substantial portions of the Software.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <stdint.h>
  33. #include <babeltrace/context.h>
  34. #include <babeltrace/clock-types.h>
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. struct bt_definition;
  39. struct bt_declaration;
  40. struct bt_ctf_event;
  41. struct bt_ctf_event_decl;
  42. struct bt_ctf_field_decl;
  43. /*
  44. * the top-level scopes in CTF
  45. */
  46. enum bt_ctf_scope {
  47. BT_TRACE_PACKET_HEADER = 0,
  48. BT_STREAM_PACKET_CONTEXT = 1,
  49. BT_STREAM_EVENT_HEADER = 2,
  50. BT_STREAM_EVENT_CONTEXT = 3,
  51. BT_EVENT_CONTEXT = 4,
  52. BT_EVENT_FIELDS = 5,
  53. };
  54. /*
  55. * the supported CTF types
  56. */
  57. enum ctf_type_id {
  58. CTF_TYPE_UNKNOWN = 0,
  59. CTF_TYPE_INTEGER,
  60. CTF_TYPE_FLOAT,
  61. CTF_TYPE_ENUM,
  62. CTF_TYPE_STRING,
  63. CTF_TYPE_STRUCT,
  64. CTF_TYPE_UNTAGGED_VARIANT,
  65. CTF_TYPE_VARIANT,
  66. CTF_TYPE_ARRAY,
  67. CTF_TYPE_SEQUENCE,
  68. NR_CTF_TYPES,
  69. };
  70. /*
  71. * the supported CTF string encodings
  72. */
  73. enum ctf_string_encoding {
  74. CTF_STRING_NONE = 0,
  75. CTF_STRING_UTF8,
  76. CTF_STRING_ASCII,
  77. CTF_STRING_UNKNOWN,
  78. };
  79. /*
  80. * bt_ctf_get_top_level_scope: return a definition of the top-level scope
  81. *
  82. * Top-level scopes are defined in the bt_ctf_scope enum.
  83. * In order to get a field or a field list, the user needs to pass a
  84. * scope as argument, this scope can be a top-level scope or a scope
  85. * relative to an arbitrary field. This function provides the mapping
  86. * between the enum and the actual definition of top-level scopes.
  87. * On error return NULL.
  88. */
  89. const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event,
  90. enum bt_ctf_scope scope);
  91. /*
  92. * bt_ctf_event_get_name: returns the name of the event or NULL on error
  93. */
  94. const char *bt_ctf_event_name(const struct bt_ctf_event *event);
  95. /*
  96. * bt_ctf_get_cycles: returns the timestamp of the event as written
  97. * in the packet (in cycles) or -1ULL on error.
  98. */
  99. uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *event);
  100. /*
  101. * bt_ctf_get_timestamp: returns the timestamp of the event offsetted
  102. * with the system clock source (in ns) or -1ULL on error
  103. */
  104. uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *event);
  105. /*
  106. * bt_ctf_get_field_list: obtain the list of fields for compound type
  107. *
  108. * This function can be used to obtain the list of fields contained
  109. * within a top-level scope of an event or a compound type: array,
  110. * sequence, structure, or variant.
  111. * This function sets the "list" pointer to an array of definition
  112. * pointers and set count to the number of elements in the array.
  113. * Return 0 on success and a negative value on error.
  114. *
  115. * The content pointed to by "list" should *not* be freed. It stays
  116. * valid as long as the event is unchanged (as long as the iterator
  117. * from which the event is extracted is unchanged).
  118. */
  119. int bt_ctf_get_field_list(const struct bt_ctf_event *event,
  120. const struct bt_definition *scope,
  121. struct bt_definition const * const **list,
  122. unsigned int *count);
  123. /*
  124. * bt_ctf_get_field: returns the definition of a specific field
  125. */
  126. const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *event,
  127. const struct bt_definition *scope,
  128. const char *field);
  129. /*
  130. * bt_ctf_get_index: if the field is an array or a sequence, return the element
  131. * at position index, otherwise return NULL;
  132. */
  133. const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *event,
  134. const struct bt_definition *field,
  135. unsigned int index);
  136. /*
  137. * bt_ctf_field_name: returns the name of a field or NULL on error
  138. */
  139. const char *bt_ctf_field_name(const struct bt_definition *def);
  140. /*
  141. * bt_ctf_get_decl_from_def: return the declaration of a field from
  142. * its definition or NULL on error
  143. */
  144. const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *def);
  145. /*
  146. * bt_ctf_get_decl_from_field_decl: return the declaration of a field from
  147. * a field_decl or NULL on error
  148. */
  149. const struct bt_declaration *bt_ctf_get_decl_from_field_decl(
  150. const struct bt_ctf_field_decl *field);
  151. /*
  152. * bt_ctf_field_type: returns the type of a field or -1 if unknown
  153. */
  154. enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *decl);
  155. /*
  156. * bt_ctf_get_int_signedness: return the signedness of an integer
  157. *
  158. * return 0 if unsigned
  159. * return 1 if signed
  160. * return -1 on error
  161. */
  162. int bt_ctf_get_int_signedness(const struct bt_declaration *decl);
  163. /*
  164. * bt_ctf_get_int_base: return the base of an int or a negative value on error
  165. */
  166. int bt_ctf_get_int_base(const struct bt_declaration *decl);
  167. /*
  168. * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
  169. * value on error
  170. */
  171. int bt_ctf_get_int_byte_order(const struct bt_declaration *decl);
  172. /*
  173. * bt_ctf_get_int_len: return the size, in bits, of an int or a negative
  174. * value on error
  175. */
  176. ssize_t bt_ctf_get_int_len(const struct bt_declaration *decl);
  177. /*
  178. * bt_ctf_get_encoding: return the encoding of an int, a string, or of
  179. * the integer contained in a char array or a sequence.
  180. * return a negative value on error
  181. */
  182. enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *decl);
  183. /*
  184. * bt_ctf_get_array_len: return the len of an array or a negative
  185. * value on error
  186. */
  187. int bt_ctf_get_array_len(const struct bt_declaration *decl);
  188. /*
  189. * bt_ctf_get_struct_field_count: return the number of fields in a structure.
  190. * Returns a negative value on error.
  191. */
  192. uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *field);
  193. /*
  194. * Field access functions
  195. *
  196. * These functions return the value associated with the field passed in
  197. * parameter.
  198. *
  199. * If the field does not exist or is not of the type requested, the value
  200. * returned is undefined. To check if an error occured, use the
  201. * bt_ctf_field_get_error() function after accessing a field.
  202. *
  203. * bt_ctf_get_enum_int gets the integer field of an enumeration.
  204. * bt_ctf_get_enum_str gets the string matching the current enumeration
  205. * value, or NULL if the current value does not match any string.
  206. */
  207. uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
  208. int64_t bt_ctf_get_int64(const struct bt_definition *field);
  209. const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
  210. const char *bt_ctf_get_enum_str(const struct bt_definition *field);
  211. char *bt_ctf_get_char_array(const struct bt_definition *field);
  212. char *bt_ctf_get_string(const struct bt_definition *field);
  213. double bt_ctf_get_float(const struct bt_definition *field);
  214. const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
  215. const struct bt_definition *bt_ctf_get_struct_field_index(
  216. const struct bt_definition *field, uint64_t i);
  217. /*
  218. * bt_ctf_field_get_error: returns the last error code encountered while
  219. * accessing a field and reset the error flag.
  220. * Return 0 if no error, a negative value otherwise.
  221. */
  222. int bt_ctf_field_get_error(void);
  223. /*
  224. * bt_ctf_get_event_decl_list: get a list of all the event declarations in
  225. * a trace.
  226. *
  227. * The list array is pointed to the array of event declarations.
  228. * The number of events in the array is written in count.
  229. *
  230. * Return 0 on success and a negative value on error.
  231. *
  232. * The content pointed to by "list" should *not* be freed. It stays
  233. * valid as long as the trace is opened.
  234. */
  235. int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
  236. struct bt_ctf_event_decl * const **list,
  237. unsigned int *count);
  238. /*
  239. * bt_ctf_get_decl_event_name: return the name of the event or NULL on error
  240. */
  241. const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
  242. /*
  243. * bt_ctf_get_decl_fields: get all field declarations in a scope of an event
  244. *
  245. * The list array is pointed to the array of field declaration.
  246. * The number of field declaration in the array is written in count.
  247. *
  248. * Returns 0 on success and a negative value on error
  249. *
  250. * The content pointed to by "list" should *not* be freed. It stays
  251. * valid as long as the trace is opened.
  252. */
  253. int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl,
  254. enum bt_ctf_scope scope,
  255. struct bt_ctf_field_decl const * const **list,
  256. unsigned int *count);
  257. /*
  258. * bt_ctf_get_decl_field_name: return the name of a field decl or NULL on error
  259. */
  260. const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
  261. #ifdef __cplusplus
  262. }
  263. #endif
  264. #endif /* _BABELTRACE_CTF_EVENTS_H */