Clean-up: lttng: utils: missing special member functions
[lttng-tools.git] / src / bin / lttng / utils.hpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifndef _LTTNG_UTILS_H
9 #define _LTTNG_UTILS_H
10
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>
15
16 #include <lttng/lttng.h>
17 #include <lttng/session-internal.hpp>
18
19 #include <iterator>
20 #include <memory>
21 #include <popt.h>
22
23 extern char *opt_relayd_path;
24 extern int opt_no_sessiond;
25 extern char *opt_sessiond_path;
26 extern pid_t sessiond_pid;
27
28 struct cmd_struct;
29
30 namespace lttng {
31 namespace cli {
32
33 struct session_spec {
34 enum class type {
35 NAME,
36 GLOB_PATTERN,
37 ALL,
38 };
39
40 explicit session_spec(type spec_type, const char *name_or_pattern = nullptr) noexcept :
41 type_(spec_type), value(name_or_pattern)
42 {
43 }
44
45 /* Disambiguate type enum from the member for buggy g++ versions. */
46 type type_;
47 const char *value;
48 };
49
50 class session_list;
51
52 namespace details {
53 class session_storage {
54 public:
55 session_storage(lttng_session *raw_sessions, std::size_t sessions_count) :
56 _array(raw_sessions), _count(sessions_count)
57 {
58 }
59
60 session_storage(session_storage&& original) noexcept :
61 _array(std::move(original._array)), _count(original._count)
62 {
63 }
64
65 session_storage(session_storage&& original, std::size_t new_count) :
66 _array(std::move(original._array)), _count(new_count)
67 {
68 }
69
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;
74
75 lttng_session_uptr _array = nullptr;
76 std::size_t _count = 0;
77 };
78
79 class session_list_operations {
80 public:
81 static lttng_session& get(const lttng::cli::details::session_storage& storage,
82 std::size_t index) noexcept
83 {
84 return storage._array[index];
85 }
86
87 static std::size_t size(const lttng::cli::details::session_storage& storage)
88 {
89 return storage._count;
90 }
91 };
92 } /* namespace details */
93
94 /*
95 * We don't use a std::vector here because it would make a copy of the C array.
96 */
97 class session_list
98 : public lttng::utils::random_access_container_wrapper<details::session_storage,
99 lttng_session&,
100 details::session_list_operations> {
101 public:
102 friend details::session_list_operations;
103
104 session_list() :
105 lttng::utils::random_access_container_wrapper<details::session_storage,
106 lttng_session&,
107 details::session_list_operations>(
108 { nullptr, 0 })
109 {
110 }
111
112 session_list(session_list&& original) noexcept :
113 lttng::utils::random_access_container_wrapper<details::session_storage,
114 lttng_session&,
115 details::session_list_operations>(
116 std::move(original._container))
117 {
118 }
119
120 session_list(session_list&& original, std::size_t new_count) :
121 lttng::utils::random_access_container_wrapper<details::session_storage,
122 lttng_session&,
123 details::session_list_operations>(
124 { std::move(original._container), new_count })
125 {
126 }
127
128 session_list(lttng_session *raw_sessions, std::size_t raw_sessions_count) :
129 lttng::utils::random_access_container_wrapper<details::session_storage,
130 lttng_session&,
131 details::session_list_operations>(
132 { raw_sessions, raw_sessions_count })
133 {
134 }
135
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;
140
141 void resize(std::size_t new_size) noexcept
142 {
143 _container._count = new_size;
144 }
145 };
146
147 lttng::cli::session_list list_sessions(const struct session_spec& spec);
148 } /* namespace cli */
149 } /* namespace lttng */
150
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);
156
157 /*
158 * Return the minimum order for which x <= (1UL << order).
159 * Return -1 if x is 0.
160 */
161 int get_count_order_u32(uint32_t x);
162
163 /*
164 * Return the minimum order for which x <= (1UL << order).
165 * Return -1 if x is 0.
166 */
167 int get_count_order_u64(uint64_t x);
168
169 /*
170 * Return the minimum order for which x <= (1UL << order).
171 * Return -1 if x is 0.
172 */
173 int get_count_order_ulong(unsigned long x);
174
175 const char *get_event_type_str(enum lttng_event_type event_type);
176
177 int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
178
179 int spawn_relayd(const char *pathname, int port);
180 int check_relayd();
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);
184
185 int print_trace_archive_location(const struct lttng_trace_archive_location *location,
186 const char *session_name);
187
188 int validate_exclusion_list(const char *event_name,
189 const struct lttng_dynamic_pointer_array *exclusions);
190
191 /*
192 * Ask the sessiond for the more details on the status of the kernel tracer and
193 * print it to stderr.
194 */
195 void print_kernel_tracer_status_error();
196
197 #endif /* _LTTNG_UTILS_H */
This page took 0.032929 seconds and 4 git commands to generate.