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;
40 * We don't use a std::vector here because it would make a copy of the C array.
43 template <typename ContainerType, typename DereferenceReturnType>
45 : public std::iterator<std::random_access_iterator_tag, std::size_t> {
47 explicit _iterator(ContainerType& list, std::size_t k) :
48 _list(list), _index(k)
52 _iterator& operator++() noexcept
58 _iterator& operator--() noexcept
64 _iterator& operator++(int) noexcept
70 _iterator& operator--(int) noexcept
76 bool operator==(_iterator other) const noexcept
78 return _index == other._index;
81 bool operator!=(_iterator other) const noexcept
83 return !(*this == other);
86 DereferenceReturnType& operator*() const noexcept
96 using iterator = _iterator<session_list, lttng_session>;
97 using const_iterator = _iterator<const session_list, const lttng_session>;
100 session_list() : _sessions_count(0), _sessions(nullptr)
104 session_list(session_list&& original, std::size_t new_count)
106 _sessions_count = new_count;
107 _sessions = std::move(original._sessions);
110 session_list(struct lttng_session *raw_sessions, std::size_t raw_sessions_count)
112 _sessions_count = raw_sessions_count;
113 _sessions.reset(raw_sessions);
116 iterator begin() noexcept
118 return iterator(*this, 0);
121 iterator end() noexcept
123 return iterator(*this, _sessions_count);
126 const_iterator begin() const noexcept
128 return const_iterator(*this, 0);
131 const_iterator end() const noexcept
133 return const_iterator(*this, _sessions_count);
136 std::size_t size() const noexcept
138 return _sessions_count;
141 void resize(std::size_t new_size) noexcept
143 _sessions_count = new_size;
146 lttng_session& operator[](std::size_t index)
148 LTTNG_ASSERT(index < _sessions_count);
149 return _sessions.get()[index];
152 const lttng_session& operator[](std::size_t index) const
154 LTTNG_ASSERT(index < _sessions_count);
155 return _sessions.get()[index];
159 std::size_t _sessions_count;
160 std::unique_ptr<lttng_session,
161 lttng::memory::create_deleter_class<lttng_session, lttng::free>::deleter>
165 char *get_session_name(void);
166 char *get_session_name_quiet(void);
167 void list_commands(struct cmd_struct *commands, FILE *ofp);
168 void list_cmd_options(FILE *ofp, struct poptOption *options);
169 void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options);
172 * Return the minimum order for which x <= (1UL << order).
173 * Return -1 if x is 0.
175 int get_count_order_u32(uint32_t x);
178 * Return the minimum order for which x <= (1UL << order).
179 * Return -1 if x is 0.
181 int get_count_order_u64(uint64_t x);
184 * Return the minimum order for which x <= (1UL << order).
185 * Return -1 if x is 0.
187 int get_count_order_ulong(unsigned long x);
189 const char *get_event_type_str(enum lttng_event_type event_type);
191 int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
193 int spawn_relayd(const char *pathname, int port);
194 int check_relayd(void);
195 void print_session_stats(const char *session_name);
196 int get_session_stats_str(const char *session_name, char **str);
197 int show_cmd_help(const char *cmd_name, const char *help_msg);
199 int print_trace_archive_location(const struct lttng_trace_archive_location *location,
200 const char *session_name);
202 int validate_exclusion_list(const char *event_name,
203 const struct lttng_dynamic_pointer_array *exclusions);
205 session_list list_sessions(const struct session_spec& spec);
207 #endif /* _LTTNG_UTILS_H */