1 #ifndef _VIEWER_SESSION_H
2 #define _VIEWER_SESSION_H
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>
9 * SPDX-License-Identifier: GPL-2.0-only
13 #include "lttng-viewer-abi.hpp"
14 #include "session.hpp"
16 #include <common/hashtable/hashtable.hpp>
17 #include <common/trace-chunk.hpp>
22 #include <urcu/list.h>
25 struct relay_viewer_session {
27 * The id of the relay viewer session. Uses the associated connection's socket FD.
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
36 struct cds_list_head session_list; /* RCU list. */
37 pthread_mutex_t session_list_lock; /* Protects list updates. */
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,
44 * Traversals are protected by RCU.
46 struct cds_list_head unannounced_stream_list;
47 pthread_mutex_t unannounced_stream_list_lock;
49 * Node in the global viewer sessions hashtable.
51 struct lttng_ht_node_u64 viewer_session_n;
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.
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.
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.
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.
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.
79 struct lttng_trace_chunk *current_trace_chunk;
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);
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);
95 #endif /* _VIEWER_SESSION_H */