Commit | Line | Data |
---|---|---|
a44ca2ca MD |
1 | #ifndef _TRACEFILE_ARRAY_H |
2 | #define _TRACEFILE_ARRAY_H | |
3 | ||
4 | /* | |
ab5be9fa | 5 | * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
a44ca2ca | 6 | * |
ab5be9fa | 7 | * SPDX-License-Identifier: GPL-2.0-only |
a44ca2ca | 8 | * |
a44ca2ca MD |
9 | */ |
10 | ||
11 | #include <limits.h> | |
12 | #include <inttypes.h> | |
13 | #include <pthread.h> | |
14 | #include <stdbool.h> | |
15 | ||
16 | struct tracefile { | |
17 | /* Per-tracefile head/tail seq. */ | |
18 | uint64_t seq_head; /* Newest seqcount. Inclusive. */ | |
19 | uint64_t seq_tail; /* Oldest seqcount. Inclusive. */ | |
20 | }; | |
21 | ||
78118e3b MD |
22 | enum tracefile_rotate_type { |
23 | TRACEFILE_ROTATE_READ, | |
24 | TRACEFILE_ROTATE_WRITE, | |
25 | }; | |
26 | ||
a44ca2ca MD |
27 | /* |
28 | * Represents an array of trace files in a stream. | |
78118e3b MD |
29 | * head is the most recent file/trace packet. |
30 | * tail is the oldest file/trace packet. | |
31 | * | |
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. | |
35 | * | |
36 | * The viewer uses the "read" head position as upper bound, which | |
37 | * ensures it never attempts to open a non-existing index file. | |
a44ca2ca MD |
38 | */ |
39 | struct tracefile_array { | |
40 | struct tracefile *tf; | |
41 | size_t count; | |
42 | ||
43 | /* Current head/tail files. */ | |
78118e3b MD |
44 | uint64_t file_head_read; |
45 | uint64_t file_head_write; | |
a44ca2ca MD |
46 | uint64_t file_tail; |
47 | ||
48 | /* Overall head/tail seq for the entire array. Inclusive. */ | |
49 | uint64_t seq_head; | |
50 | uint64_t seq_tail; | |
51 | }; | |
52 | ||
53 | struct tracefile_array *tracefile_array_create(size_t count); | |
54 | void tracefile_array_destroy(struct tracefile_array *tfa); | |
55 | ||
78118e3b | 56 | void tracefile_array_file_rotate(struct tracefile_array *tfa, enum tracefile_rotate_type type); |
62f6e9ef MD |
57 | void tracefile_array_commit_seq(struct tracefile_array *tfa, |
58 | uint64_t new_seq_head); | |
c31a8092 | 59 | void tracefile_array_reset(struct tracefile_array *tfa); |
a44ca2ca | 60 | |
78118e3b | 61 | uint64_t tracefile_array_get_read_file_index_head(struct tracefile_array *tfa); |
a44ca2ca MD |
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); | |
64 | ||
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); | |
68 | ||
69 | bool tracefile_array_seq_in_file(struct tracefile_array *tfa, | |
70 | uint64_t file_index, uint64_t seq); | |
71 | ||
72 | #endif /* _STREAM_H */ |