+void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
+ struct packet_index *prev_index,
+ struct packet_index *cur_index)
+{
+ uint64_t events_discarded_diff;
+
+ /* Update packet index time information */
+
+ /* Current packet begin/end */
+ stream->current.real.begin =
+ cur_index->ts_real.timestamp_begin;
+ stream->current.cycles.begin =
+ cur_index->ts_cycles.timestamp_begin;
+ stream->current.real.end =
+ cur_index->ts_real.timestamp_end;
+ stream->current.cycles.end =
+ cur_index->ts_cycles.timestamp_end;
+
+ /* Update packet index discarded event information */
+ events_discarded_diff = cur_index->events_discarded;
+ if (prev_index) {
+ /* Previous packet begin/end */
+ stream->prev.cycles.begin =
+ prev_index->ts_cycles.timestamp_begin;
+ stream->prev.real.begin =
+ prev_index->ts_real.timestamp_begin;
+ stream->prev.cycles.end =
+ prev_index->ts_cycles.timestamp_end;
+ stream->prev.real.end =
+ prev_index->ts_real.timestamp_end;
+
+ events_discarded_diff -= prev_index->events_discarded;
+ /*
+ * Deal with 32-bit wrap-around if the tracer provided a
+ * 32-bit field.
+ */
+ if (prev_index->events_discarded_len == 32) {
+ events_discarded_diff = (uint32_t) events_discarded_diff;
+ }
+ } else {
+ /*
+ * First packet: use current packet info as limits for
+ * previous packet.
+ */
+ stream->prev.cycles.begin =
+ stream->prev.cycles.end =
+ stream->current.cycles.begin;
+ stream->prev.real.begin =
+ stream->prev.real.end =
+ stream->current.real.begin;
+ }
+ stream->events_discarded = events_discarded_diff;
+}
+