2 * Copyright (C) 2011 EfficiOS Inc.
4 * SPDX-License-Identifier: GPL-2.0-only
11 #include <common/argpar/argpar.h>
12 #include <common/dynamic-array.hpp>
13 #include <common/make-unique-wrapper.hpp>
15 #include <lttng/lttng.h>
21 extern char *opt_relayd_path;
22 extern int opt_no_sessiond;
23 extern char *opt_sessiond_path;
24 extern pid_t sessiond_pid;
35 explicit session_spec(type spec_type, const char *name_or_pattern = nullptr) noexcept :
36 type_(spec_type), value(name_or_pattern)
40 /* Disambiguate type enum from the member for buggy g++ versions. */
46 * We don't use a std::vector here because it would make a copy of the C array.
49 template <typename ContainerType, typename DereferenceReturnType>
50 class _iterator : public std::iterator<std::random_access_iterator_tag, std::size_t> {
52 explicit _iterator(ContainerType& list, std::size_t k) : _list(list), _index(k)
56 _iterator& operator++() noexcept
62 _iterator& operator--() noexcept
68 _iterator& operator++(int) noexcept
74 _iterator& operator--(int) noexcept
80 bool operator==(_iterator other) const noexcept
82 return _index == other._index;
85 bool operator!=(_iterator other) const noexcept
87 return !(*this == other);
90 DereferenceReturnType& operator*() const noexcept
100 using iterator = _iterator<session_list, lttng_session>;
101 using const_iterator = _iterator<const session_list, const lttng_session>;
104 session_list() : _sessions_count(0), _sessions(nullptr)
108 session_list(session_list&& original, std::size_t new_count)
110 _sessions_count = new_count;
111 _sessions = std::move(original._sessions);
114 session_list(struct lttng_session *raw_sessions, std::size_t raw_sessions_count)
116 _sessions_count = raw_sessions_count;
117 _sessions.reset(raw_sessions);
120 iterator begin() noexcept
122 return iterator(*this, 0);
125 iterator end() noexcept
127 return iterator(*this, _sessions_count);
130 const_iterator begin() const noexcept
132 return const_iterator(*this, 0);
135 const_iterator end() const noexcept
137 return const_iterator(*this, _sessions_count);
140 std::size_t size() const noexcept
142 return _sessions_count;
145 void resize(std::size_t new_size) noexcept
147 _sessions_count = new_size;
150 lttng_session& operator[](std::size_t index)
152 LTTNG_ASSERT(index < _sessions_count);
153 return _sessions.get()[index];
156 const lttng_session& operator[](std::size_t index) const
158 LTTNG_ASSERT(index < _sessions_count);
159 return _sessions.get()[index];
163 std::size_t _sessions_count;
164 std::unique_ptr<lttng_session,
165 lttng::memory::create_deleter_class<lttng_session, lttng::free>::deleter>
169 char *get_session_name(void);
170 char *get_session_name_quiet(void);
171 void list_commands(struct cmd_struct *commands, FILE *ofp);
172 void list_cmd_options(FILE *ofp, struct poptOption *options);
173 void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options);
176 * Return the minimum order for which x <= (1UL << order).
177 * Return -1 if x is 0.
179 int get_count_order_u32(uint32_t x);
182 * Return the minimum order for which x <= (1UL << order).
183 * Return -1 if x is 0.
185 int get_count_order_u64(uint64_t x);
188 * Return the minimum order for which x <= (1UL << order).
189 * Return -1 if x is 0.
191 int get_count_order_ulong(unsigned long x);
193 const char *get_event_type_str(enum lttng_event_type event_type);
195 int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
197 int spawn_relayd(const char *pathname, int port);
198 int check_relayd(void);
199 void print_session_stats(const char *session_name);
200 int get_session_stats_str(const char *session_name, char **str);
201 int show_cmd_help(const char *cmd_name, const char *help_msg);
203 int print_trace_archive_location(const struct lttng_trace_archive_location *location,
204 const char *session_name);
206 int validate_exclusion_list(const char *event_name,
207 const struct lttng_dynamic_pointer_array *exclusions);
209 session_list list_sessions(const struct session_spec& spec);
211 #endif /* _LTTNG_UTILS_H */