2 * Copyright (C) 2011 EfficiOS Inc.
4 * SPDX-License-Identifier: GPL-2.0-only
11 #include <common/container-wrapper.hpp>
12 #include <common/dynamic-array.hpp>
13 #include <common/make-unique-wrapper.hpp>
15 #include <lttng/lttng.h>
16 #include <lttng/session-internal.hpp>
18 #include <vendor/argpar/argpar.h>
24 extern char *opt_relayd_path;
25 extern int opt_no_sessiond;
26 extern char *opt_sessiond_path;
27 extern pid_t sessiond_pid;
41 explicit session_spec(type spec_type, const char *name_or_pattern = nullptr) noexcept :
42 type_(spec_type), value(name_or_pattern)
46 /* Disambiguate type enum from the member for buggy g++ versions. */
54 class session_storage {
56 session_storage(lttng_session *raw_sessions, std::size_t sessions_count) :
57 _array(raw_sessions), _count(sessions_count)
61 session_storage(session_storage&& original) noexcept :
62 _array(std::move(original._array)), _count(original._count)
66 session_storage(session_storage&& original, std::size_t new_count) :
67 _array(std::move(original._array)), _count(new_count)
71 session_storage(session_storage&) = delete;
72 session_storage& operator=(const session_storage& other) = delete;
73 session_storage& operator=(session_storage&& other) = delete;
74 ~session_storage() = default;
76 lttng_session_uptr _array = nullptr;
77 std::size_t _count = 0;
80 class session_list_operations {
82 static lttng_session& get(const lttng::cli::details::session_storage& storage,
83 std::size_t index) noexcept
85 return storage._array[index];
88 static std::size_t size(const lttng::cli::details::session_storage& storage)
90 return storage._count;
93 } /* namespace details */
96 * We don't use a std::vector here because it would make a copy of the C array.
99 : public lttng::utils::random_access_container_wrapper<details::session_storage,
101 details::session_list_operations> {
103 friend details::session_list_operations;
106 lttng::utils::random_access_container_wrapper<details::session_storage,
108 details::session_list_operations>(
113 session_list(session_list&& original) noexcept :
114 lttng::utils::random_access_container_wrapper<details::session_storage,
116 details::session_list_operations>(
117 std::move(original._container))
121 session_list(session_list&& original, std::size_t new_count) :
122 lttng::utils::random_access_container_wrapper<details::session_storage,
124 details::session_list_operations>(
125 { std::move(original._container), new_count })
129 session_list(lttng_session *raw_sessions, std::size_t raw_sessions_count) :
130 lttng::utils::random_access_container_wrapper<details::session_storage,
132 details::session_list_operations>(
133 { raw_sessions, raw_sessions_count })
137 session_list(session_list&) = delete;
138 session_list& operator=(const session_list& other) = delete;
139 session_list& operator=(session_list&& other) = delete;
140 ~session_list() = default;
142 void resize(std::size_t new_size) noexcept
144 _container._count = new_size;
148 lttng::cli::session_list list_sessions(const struct session_spec& spec);
149 } /* namespace cli */
150 } /* namespace lttng */
152 char *get_session_name();
153 char *get_session_name_quiet();
154 void list_commands(struct cmd_struct *commands, FILE *ofp);
155 void list_cmd_options(FILE *ofp, struct poptOption *options);
156 void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options);
159 * Return the minimum order for which x <= (1UL << order).
160 * Return -1 if x is 0.
162 int get_count_order_u32(uint32_t x);
165 * Return the minimum order for which x <= (1UL << order).
166 * Return -1 if x is 0.
168 int get_count_order_u64(uint64_t x);
171 * Return the minimum order for which x <= (1UL << order).
172 * Return -1 if x is 0.
174 int get_count_order_ulong(unsigned long x);
176 const char *get_event_type_str(enum lttng_event_type event_type);
178 int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
180 int spawn_relayd(const char *pathname, int port);
182 void print_session_stats(const char *session_name);
183 int get_session_stats_str(const char *session_name, char **str);
184 int show_cmd_help(const char *cmd_name, const char *help_msg);
186 int print_trace_archive_location(const struct lttng_trace_archive_location *location,
187 const char *session_name);
189 int validate_exclusion_list(const char *event_name,
190 const struct lttng_dynamic_pointer_array *exclusions);
193 * Ask the sessiond for the more details on the status of the kernel tracer and
194 * print it to stderr.
196 void print_kernel_tracer_status_error();
198 #endif /* _LTTNG_UTILS_H */