1 #ifndef _TRACEFILE_ARRAY_H
2 #define _TRACEFILE_ARRAY_H
5 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * SPDX-License-Identifier: GPL-2.0-only
17 /* Per-tracefile head/tail seq. */
18 uint64_t seq_head
; /* Newest seqcount. Inclusive. */
19 uint64_t seq_tail
; /* Oldest seqcount. Inclusive. */
22 enum tracefile_rotate_type
{
23 TRACEFILE_ROTATE_READ
,
24 TRACEFILE_ROTATE_WRITE
,
28 * Represents an array of trace files in a stream.
29 * head is the most recent file/trace packet.
30 * tail is the oldest file/trace packet.
32 * There are two heads: a "read" head and a "write" head. The "write" head is
33 * the position of the newest data file. The "read" head position is only moved
34 * forward when the index is received.
36 * The viewer uses the "read" head position as upper bound, which
37 * ensures it never attempts to open a non-existing index file.
39 struct tracefile_array
{
43 /* Current head/tail files. */
44 uint64_t file_head_read
;
45 uint64_t file_head_write
;
48 /* Overall head/tail seq for the entire array. Inclusive. */
53 struct tracefile_array
*tracefile_array_create(size_t count
);
54 void tracefile_array_destroy(struct tracefile_array
*tfa
);
56 void tracefile_array_file_rotate(struct tracefile_array
*tfa
, enum tracefile_rotate_type type
);
57 void tracefile_array_commit_seq(struct tracefile_array
*tfa
,
58 uint64_t new_seq_head
);
59 void tracefile_array_reset(struct tracefile_array
*tfa
);
61 uint64_t tracefile_array_get_read_file_index_head(struct tracefile_array
*tfa
);
62 /* May return -1ULL in the case where we have not received any indexes yet. */
63 uint64_t tracefile_array_get_seq_head(struct tracefile_array
*tfa
);
65 uint64_t tracefile_array_get_file_index_tail(struct tracefile_array
*tfa
);
66 /* May return -1ULL in the case where we have not received any indexes yet. */
67 uint64_t tracefile_array_get_seq_tail(struct tracefile_array
*tfa
);
69 bool tracefile_array_seq_in_file(struct tracefile_array
*tfa
,
70 uint64_t file_index
, uint64_t seq
);
72 #endif /* _STREAM_H */