relayd: track the health thread's poll fd with fd-tracker
[lttng-tools.git] / src / bin / lttng-relayd / tracefile-array.h
1 #ifndef _TRACEFILE_ARRAY_H
2 #define _TRACEFILE_ARRAY_H
3
4 /*
5 * Copyright (C) 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License, version 2 only, as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 51
18 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include <limits.h>
22 #include <inttypes.h>
23 #include <pthread.h>
24 #include <stdbool.h>
25
26 struct tracefile {
27 /* Per-tracefile head/tail seq. */
28 uint64_t seq_head; /* Newest seqcount. Inclusive. */
29 uint64_t seq_tail; /* Oldest seqcount. Inclusive. */
30 };
31
32 enum tracefile_rotate_type {
33 TRACEFILE_ROTATE_READ,
34 TRACEFILE_ROTATE_WRITE,
35 };
36
37 /*
38 * Represents an array of trace files in a stream.
39 * head is the most recent file/trace packet.
40 * tail is the oldest file/trace packet.
41 *
42 * There are two heads: a "read" head and a "write" head. The "write" head is
43 * the position of the newest data file. The "read" head position is only moved
44 * forward when the index is received.
45 *
46 * The viewer uses the "read" head position as upper bound, which
47 * ensures it never attempts to open a non-existing index file.
48 */
49 struct tracefile_array {
50 struct tracefile *tf;
51 size_t count;
52
53 /* Current head/tail files. */
54 uint64_t file_head_read;
55 uint64_t file_head_write;
56 uint64_t file_tail;
57
58 /* Overall head/tail seq for the entire array. Inclusive. */
59 uint64_t seq_head;
60 uint64_t seq_tail;
61 };
62
63 struct tracefile_array *tracefile_array_create(size_t count);
64 void tracefile_array_destroy(struct tracefile_array *tfa);
65
66 void tracefile_array_file_rotate(struct tracefile_array *tfa, enum tracefile_rotate_type type);
67 void tracefile_array_commit_seq(struct tracefile_array *tfa,
68 uint64_t new_seq_head);
69 void tracefile_array_reset(struct tracefile_array *tfa);
70
71 uint64_t tracefile_array_get_read_file_index_head(struct tracefile_array *tfa);
72 /* May return -1ULL in the case where we have not received any indexes yet. */
73 uint64_t tracefile_array_get_seq_head(struct tracefile_array *tfa);
74
75 uint64_t tracefile_array_get_file_index_tail(struct tracefile_array *tfa);
76 /* May return -1ULL in the case where we have not received any indexes yet. */
77 uint64_t tracefile_array_get_seq_tail(struct tracefile_array *tfa);
78
79 bool tracefile_array_seq_in_file(struct tracefile_array *tfa,
80 uint64_t file_index, uint64_t seq);
81
82 #endif /* _STREAM_H */
This page took 0.030578 seconds and 4 git commands to generate.