2 * Copyright (C) 2011 EfficiOS Inc.
4 * SPDX-License-Identifier: GPL-2.0-only
11 #include <common/argpar/argpar.h>
12 #include <common/container-wrapper.hpp>
13 #include <common/dynamic-array.hpp>
14 #include <common/make-unique-wrapper.hpp>
16 #include <lttng/lttng.h>
17 #include <lttng/session-internal.hpp>
23 extern char *opt_relayd_path;
24 extern int opt_no_sessiond;
25 extern char *opt_sessiond_path;
26 extern pid_t sessiond_pid;
40 explicit session_spec(type spec_type, const char *name_or_pattern = nullptr) noexcept :
41 type_(spec_type), value(name_or_pattern)
45 /* Disambiguate type enum from the member for buggy g++ versions. */
53 class session_storage {
55 session_storage(lttng_session *raw_sessions, std::size_t sessions_count) :
56 _array(raw_sessions), _count(sessions_count)
60 session_storage(session_storage&& original) noexcept :
61 _array(std::move(original._array)), _count(original._count)
65 session_storage(session_storage&& original, std::size_t new_count) :
66 _array(std::move(original._array)), _count(new_count)
70 session_storage(session_storage&) = delete;
71 session_storage& operator=(const session_storage& other) = delete;
72 session_storage& operator=(session_storage&& other) = delete;
73 ~session_storage() = default;
75 lttng_session_uptr _array = nullptr;
76 std::size_t _count = 0;
79 class session_list_operations {
81 static lttng_session& get(const lttng::cli::details::session_storage& storage,
82 std::size_t index) noexcept
84 return storage._array[index];
87 static std::size_t size(const lttng::cli::details::session_storage& storage)
89 return storage._count;
92 } /* namespace details */
95 * We don't use a std::vector here because it would make a copy of the C array.
98 : public lttng::utils::random_access_container_wrapper<details::session_storage,
100 details::session_list_operations> {
102 friend details::session_list_operations;
105 lttng::utils::random_access_container_wrapper<details::session_storage,
107 details::session_list_operations>(
112 session_list(session_list&& original) noexcept :
113 lttng::utils::random_access_container_wrapper<details::session_storage,
115 details::session_list_operations>(
116 std::move(original._container))
120 session_list(session_list&& original, std::size_t new_count) :
121 lttng::utils::random_access_container_wrapper<details::session_storage,
123 details::session_list_operations>(
124 { std::move(original._container), new_count })
128 session_list(lttng_session *raw_sessions, std::size_t raw_sessions_count) :
129 lttng::utils::random_access_container_wrapper<details::session_storage,
131 details::session_list_operations>(
132 { raw_sessions, raw_sessions_count })
136 session_list(session_list&) = delete;
137 session_list& operator=(const session_list& other) = delete;
138 session_list& operator=(session_list&& other) = delete;
139 ~session_list() = default;
141 void resize(std::size_t new_size) noexcept
143 _container._count = new_size;
147 lttng::cli::session_list list_sessions(const struct session_spec& spec);
148 } /* namespace cli */
149 } /* namespace lttng */
151 char *get_session_name();
152 char *get_session_name_quiet();
153 void list_commands(struct cmd_struct *commands, FILE *ofp);
154 void list_cmd_options(FILE *ofp, struct poptOption *options);
155 void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options);
158 * Return the minimum order for which x <= (1UL << order).
159 * Return -1 if x is 0.
161 int get_count_order_u32(uint32_t x);
164 * Return the minimum order for which x <= (1UL << order).
165 * Return -1 if x is 0.
167 int get_count_order_u64(uint64_t x);
170 * Return the minimum order for which x <= (1UL << order).
171 * Return -1 if x is 0.
173 int get_count_order_ulong(unsigned long x);
175 const char *get_event_type_str(enum lttng_event_type event_type);
177 int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
179 int spawn_relayd(const char *pathname, int port);
181 void print_session_stats(const char *session_name);
182 int get_session_stats_str(const char *session_name, char **str);
183 int show_cmd_help(const char *cmd_name, const char *help_msg);
185 int print_trace_archive_location(const struct lttng_trace_archive_location *location,
186 const char *session_name);
188 int validate_exclusion_list(const char *event_name,
189 const struct lttng_dynamic_pointer_array *exclusions);
192 * Ask the sessiond for the more details on the status of the kernel tracer and
193 * print it to stderr.
195 void print_kernel_tracer_status_error();
197 #endif /* _LTTNG_UTILS_H */