728676b9509f417ed7f2b899cc2ed44d56cd70c8
[lttng-tools.git] / src / bin / lttng-relayd / viewer-session.hpp
1 #ifndef _VIEWER_SESSION_H
2 #define _VIEWER_SESSION_H
3
4 /*
5 * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
6 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
7 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * SPDX-License-Identifier: GPL-2.0-only
10 *
11 */
12
13 #include "lttng-viewer-abi.hpp"
14 #include "session.hpp"
15
16 #include <common/hashtable/hashtable.hpp>
17 #include <common/trace-chunk.hpp>
18
19 #include <inttypes.h>
20 #include <limits.h>
21 #include <pthread.h>
22 #include <urcu/list.h>
23 #include <urcu/ref.h>
24
25 struct relay_viewer_session {
26 /*
27 * The id of the relay viewer session. Uses the associated connection's socket FD.
28 */
29 uint64_t id;
30 /*
31 * Session list. Updates are protected by the session_list_lock.
32 * Traversals are protected by RCU.
33 * This list limits the design to having the sessions in at most
34 * one viewer session.
35 */
36 struct cds_list_head session_list; /* RCU list. */
37 pthread_mutex_t session_list_lock; /* Protects list updates. */
38 /*
39 * Unannounced stream list. Updates are protected by the
40 * unannounced_stream_list_lock. This lock nests inside
41 * the following locks (in order): relay session, ctf_trace,
42 * and relay stream.
43 *
44 * Traversals are protected by RCU.
45 */
46 struct cds_list_head unannounced_stream_list;
47 pthread_mutex_t unannounced_stream_list_lock;
48 /*
49 * Node in the global viewer sessions hashtable.
50 */
51 struct lttng_ht_node_u64 viewer_session_n;
52 /*
53 * The viewer session's current trace chunk is initially set, when
54 * a viewer attaches to the viewer session, to a copy the corresponding
55 * relay_session's current trace chunk.
56 *
57 * A live session always attempts to "catch-up" to the newest available
58 * trace chunk. This means that when a viewer reaches the end of a
59 * trace chunk, the viewer session may not transition to the "next" one:
60 * it jumps to the most recent trace chunk available (the one being
61 * produced by the relay_session). Hence, if the producer performs
62 * multiple rotations before a viewer completes the consumption of a
63 * trace chunk, it will skip over those "intermediary" trace chunks.
64 *
65 * A viewer session updates its current trace chunk when:
66 * 1) new viewer streams are created,
67 * 2) a new index is requested,
68 * 3) metadata is requested.
69 *
70 * Hence, as a general principle, the viewer session will reference the
71 * most recent trace chunk available _even if its streams do not point to
72 * it_. It indicates which trace chunk viewer streams should transition
73 * to when the end of their current trace chunk is reached.
74 *
75 * Note that a viewer session's trace chunk points to the session's
76 * output directory. The sub-directories in which the various stream files
77 * are created are considered as being a part of their name.
78 */
79 struct lttng_trace_chunk *current_trace_chunk;
80 };
81
82 struct relay_viewer_session *viewer_session_create();
83 void viewer_session_destroy(struct relay_viewer_session *vsession);
84 void viewer_session_close(struct relay_viewer_session *vsession);
85
86 enum lttng_viewer_attach_return_code viewer_session_attach(struct relay_viewer_session *vsession,
87 struct relay_session *session);
88 int viewer_session_is_attached(struct relay_viewer_session *vsession,
89 struct relay_session *session);
90 void viewer_session_close_one_session(struct relay_viewer_session *vsession,
91 struct relay_session *session);
92 int viewer_session_set_trace_chunk_copy(struct relay_viewer_session *vsession,
93 struct lttng_trace_chunk *relay_session_trace_chunk);
94
95 #endif /* _VIEWER_SESSION_H */
This page took 0.040428 seconds and 5 git commands to generate.