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 class iterator : public std::iterator<std::random_access_iterator_tag, std::size_t> {
45 explicit iterator(session_list& list, std::size_t k) : _list(list), _index(k)
49 iterator& operator++() noexcept
55 iterator& operator--() noexcept
61 iterator& operator++(int) noexcept
67 iterator& operator--(int) noexcept
73 bool operator==(iterator other) const noexcept
75 return _index == other._index;
78 bool operator!=(iterator other) const noexcept
80 return !(*this == other);
83 lttng_session& operator*() const noexcept
94 session_list() : _sessions_count(0), _sessions(nullptr)
98 session_list(session_list&& original, std::size_t new_count)
100 _sessions_count = new_count;
101 _sessions = std::move(original._sessions);
104 session_list(struct lttng_session *raw_sessions, std::size_t raw_sessions_count)
106 _sessions_count = raw_sessions_count;
107 _sessions.reset(raw_sessions);
110 iterator begin() noexcept
112 return iterator(*this, 0);
115 iterator end() noexcept
117 return iterator(*this, _sessions_count);
120 std::size_t size() const noexcept
122 return _sessions_count;
125 void resize(std::size_t new_size) noexcept
127 _sessions_count = new_size;
130 lttng_session& operator[](std::size_t index)
132 LTTNG_ASSERT(index < _sessions_count);
133 return _sessions.get()[index];
136 const lttng_session& operator[](std::size_t index) const
138 LTTNG_ASSERT(index < _sessions_count);
139 return _sessions.get()[index];
143 std::size_t _sessions_count;
144 std::unique_ptr<lttng_session,
145 lttng::details::create_unique_class<lttng_session, lttng::free>>
149 char *get_session_name(void);
150 char *get_session_name_quiet(void);
151 void list_commands(struct cmd_struct *commands, FILE *ofp);
152 void list_cmd_options(FILE *ofp, struct poptOption *options);
153 void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options);
156 * Return the minimum order for which x <= (1UL << order).
157 * Return -1 if x is 0.
159 int get_count_order_u32(uint32_t x);
162 * Return the minimum order for which x <= (1UL << order).
163 * Return -1 if x is 0.
165 int get_count_order_u64(uint64_t x);
168 * Return the minimum order for which x <= (1UL << order).
169 * Return -1 if x is 0.
171 int get_count_order_ulong(unsigned long x);
173 const char *get_event_type_str(enum lttng_event_type event_type);
175 int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
177 int spawn_relayd(const char *pathname, int port);
178 int check_relayd(void);
179 void print_session_stats(const char *session_name);
180 int get_session_stats_str(const char *session_name, char **str);
181 int show_cmd_help(const char *cmd_name, const char *help_msg);
183 int print_trace_archive_location(const struct lttng_trace_archive_location *location,
184 const char *session_name);
186 int validate_exclusion_list(const char *event_name,
187 const struct lttng_dynamic_pointer_array *exclusions);
189 session_list list_sessions(const struct session_spec& spec);
191 #endif /* _LTTNG_UTILS_H */