relayd: tracefile array: Allow head position to skip ahead
[lttng-tools.git] / src / bin / lttng-relayd / tracefile-array.h
CommitLineData
a44ca2ca
MD
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
26struct 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
78118e3b
MD
32enum tracefile_rotate_type {
33 TRACEFILE_ROTATE_READ,
34 TRACEFILE_ROTATE_WRITE,
35};
36
a44ca2ca
MD
37/*
38 * Represents an array of trace files in a stream.
78118e3b
MD
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.
a44ca2ca
MD
48 */
49struct tracefile_array {
50 struct tracefile *tf;
51 size_t count;
52
53 /* Current head/tail files. */
78118e3b
MD
54 uint64_t file_head_read;
55 uint64_t file_head_write;
a44ca2ca
MD
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
63struct tracefile_array *tracefile_array_create(size_t count);
64void tracefile_array_destroy(struct tracefile_array *tfa);
65
78118e3b 66void tracefile_array_file_rotate(struct tracefile_array *tfa, enum tracefile_rotate_type type);
62f6e9ef
MD
67void tracefile_array_commit_seq(struct tracefile_array *tfa,
68 uint64_t new_seq_head);
c31a8092 69void tracefile_array_reset(struct tracefile_array *tfa);
a44ca2ca 70
78118e3b 71uint64_t tracefile_array_get_read_file_index_head(struct tracefile_array *tfa);
a44ca2ca
MD
72/* May return -1ULL in the case where we have not received any indexes yet. */
73uint64_t tracefile_array_get_seq_head(struct tracefile_array *tfa);
74
75uint64_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. */
77uint64_t tracefile_array_get_seq_tail(struct tracefile_array *tfa);
78
79bool 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.036647 seconds and 4 git commands to generate.