writer.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef BABELTRACE_CTF_WRITER_WRITER_H
  2. #define BABELTRACE_CTF_WRITER_WRITER_H
  3. /*
  4. * BabelTrace - CTF Writer: Writer
  5. *
  6. * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  7. *
  8. * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26. * SOFTWARE.
  27. *
  28. * The Common Trace Format (CTF) Specification is available at
  29. * http://www.efficios.com/ctf
  30. */
  31. #include <babeltrace/ctf-ir/field-types.h>
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. struct bt_ctf_writer;
  36. struct bt_ctf_stream;
  37. struct bt_ctf_stream_class;
  38. struct bt_ctf_clock;
  39. /*
  40. * bt_ctf_writer_create: create a writer instance.
  41. *
  42. * Allocate a new writer that will produce a trace in the given path.
  43. * The creation of a writer sets its reference count to 1.
  44. *
  45. * @param path Path to the trace's containing folder (string is copied).
  46. *
  47. * Returns an allocated writer on success, NULL on error.
  48. */
  49. extern struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
  50. /*
  51. * bt_ctf_writer_create_stream: create a stream instance.
  52. *
  53. * Allocate a new stream instance and register it to the writer. The creation of
  54. * a stream sets its reference count to 1.
  55. *
  56. * @param writer Writer instance.
  57. * @param stream_class Stream class to instantiate.
  58. *
  59. * Returns an allocated stream on success, NULL on error.
  60. */
  61. extern struct bt_ctf_stream *bt_ctf_writer_create_stream(
  62. struct bt_ctf_writer *writer,
  63. struct bt_ctf_stream_class *stream_class);
  64. /*
  65. * bt_ctf_writer_add_environment_field: add an environment field to the trace.
  66. *
  67. * Add an environment field to the trace. The name and value parameters are
  68. * copied.
  69. *
  70. * @param writer Writer instance.
  71. * @param name Name of the environment field (will be copied).
  72. * @param value Value of the environment field (will be copied).
  73. *
  74. * Returns 0 on success, a negative value on error.
  75. */
  76. extern int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer,
  77. const char *name,
  78. const char *value);
  79. /*
  80. * bt_ctf_writer_add_clock: add a clock to the trace.
  81. *
  82. * Add a clock to the trace. Clocks assigned to stream classes must be
  83. * registered to the writer.
  84. *
  85. * @param writer Writer instance.
  86. * @param clock Clock to add to the trace.
  87. *
  88. * Returns 0 on success, a negative value on error.
  89. */
  90. extern int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer,
  91. struct bt_ctf_clock *clock);
  92. /*
  93. * bt_ctf_writer_get_metadata_string: get meta-data string.
  94. *
  95. * Get the trace's TSDL meta-data. The caller assumes the ownership of the
  96. * returned string.
  97. *
  98. * @param writer Writer instance.
  99. *
  100. * Returns the metadata string on success, NULL on error.
  101. */
  102. extern char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
  103. /*
  104. * bt_ctf_writer_flush_metadata: flush the trace's metadata to disk.
  105. *
  106. * Flush the trace's metadata to the metadata file. Note that the metadata will
  107. * be flushed automatically when the Writer instance is released (last call to
  108. * bt_ctf_writer_put).
  109. *
  110. * @param writer Writer instance.
  111. */
  112. extern void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
  113. /*
  114. * bt_ctf_writer_set_byte_order: set a field type's byte order.
  115. *
  116. * Set the trace's byte order. Defaults to the host machine's endianness.
  117. *
  118. * @param writer Writer instance.
  119. * @param byte_order Trace's byte order.
  120. *
  121. * Returns 0 on success, a negative value on error.
  122. *
  123. * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according
  124. * to the CTF specification, is defined as "the byte order described in the
  125. * trace description".
  126. */
  127. extern int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer,
  128. enum bt_ctf_byte_order byte_order);
  129. /*
  130. * bt_ctf_writer_get and bt_ctf_writer_put: increment and decrement the
  131. * writer's reference count.
  132. *
  133. * You may also use bt_ctf_get() and bt_ctf_put() with writer objects.
  134. *
  135. * These functions ensure that the writer won't be destroyed while it
  136. * is in use. The same number of get and put (plus one extra put to
  137. * release the initial reference done at creation) have to be done to
  138. * destroy a writer.
  139. *
  140. * When the writer's reference count is decremented to 0 by a
  141. * bt_ctf_writer_put, the writer is freed.
  142. *
  143. * @param writer Writer instance.
  144. */
  145. extern void bt_ctf_writer_get(struct bt_ctf_writer *writer);
  146. extern void bt_ctf_writer_put(struct bt_ctf_writer *writer);
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif /* BABELTRACE_CTF_WRITER_WRITER_H */