iterator.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef _BABELTRACE_ITERATOR_H
  2. #define _BABELTRACE_ITERATOR_H
  3. /*
  4. * BabelTrace API Iterators
  5. *
  6. * Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. */
  26. #include <babeltrace/format.h>
  27. #include <babeltrace/context.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Flags for the iterator read_event */
  32. enum {
  33. BT_ITER_FLAG_LOST_EVENTS = (1 << 0),
  34. BT_ITER_FLAG_RETRY = (1 << 1),
  35. };
  36. /* Forward declarations */
  37. struct bt_iter;
  38. struct bt_saved_pos;
  39. /*
  40. * bt_iter is an abstract class, each format has to implement its own
  41. * iterator derived from this parent class.
  42. */
  43. /*
  44. * bt_iter_pos
  45. *
  46. * This structure represents the position where to set an iterator.
  47. *
  48. * type represents the type of seek to use.
  49. * u is the argument of the seek if necessary :
  50. * - seek_time is the real timestamp to seek to when using BT_SEEK_TIME, it
  51. * is expressed in nanoseconds
  52. * - restore is a position saved with bt_iter_get_pos, it is used with
  53. * BT_SEEK_RESTORE.
  54. *
  55. * Note about BT_SEEK_LAST: if many events happen to be at the last
  56. * timestamp, it is implementation-defined which event will be the last,
  57. * and the order of events with the same timestamp may not be the same
  58. * as normal iteration on the trace. Therefore, it is recommended to
  59. * only use BT_SEEK_LAST to get the timestamp of the last event(s) in
  60. * the trace.
  61. */
  62. enum bt_iter_pos_type {
  63. BT_SEEK_TIME, /* uses u.seek_time */
  64. BT_SEEK_RESTORE, /* uses u.restore */
  65. BT_SEEK_CUR,
  66. BT_SEEK_BEGIN,
  67. BT_SEEK_LAST,
  68. };
  69. struct bt_iter_pos {
  70. enum bt_iter_pos_type type;
  71. union {
  72. uint64_t seek_time;
  73. struct bt_saved_pos *restore;
  74. } u;
  75. };
  76. /*
  77. * bt_iter_next: Move trace collection position to the next event.
  78. *
  79. * Returns 0 on success, a negative value on error
  80. */
  81. int bt_iter_next(struct bt_iter *iter);
  82. /*
  83. * bt_iter_get_pos - Get the current iterator position.
  84. *
  85. * The position returned by this function needs to be freed by
  86. * bt_iter_free_pos after use.
  87. */
  88. struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
  89. /*
  90. * bt_iter_free_pos - Free the position.
  91. */
  92. void bt_iter_free_pos(struct bt_iter_pos *pos);
  93. /*
  94. * bt_iter_set_pos: move the iterator to a given position.
  95. *
  96. * On error, the stream_heap is reinitialized and returned empty.
  97. *
  98. * Return 0 for success.
  99. *
  100. * Return EOF if the position requested is after the last event of the
  101. * trace collection.
  102. * Return -EINVAL when called with invalid parameter.
  103. * Return -ENOMEM if the stream_heap could not be properly initialized.
  104. */
  105. int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
  106. /*
  107. * bt_iter_create_time_pos: create a position based on time
  108. *
  109. * This function allocates and returns a new bt_iter_pos (which must be freed
  110. * with bt_iter_free_pos) to be able to restore an iterator position based on a
  111. * real timestamp.
  112. */
  113. struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter,
  114. uint64_t timestamp);
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif /* _BABELTRACE_ITERATOR_H */