lttng: make session_storage::_array a unique_ptr to array
[lttng-tools.git] / src / bin / lttng / utils.hpp
CommitLineData
f3ed775e 1/*
21cf9b6b 2 * Copyright (C) 2011 EfficiOS Inc.
f3ed775e 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
f3ed775e 5 *
f3ed775e
DG
6 */
7
8#ifndef _LTTNG_UTILS_H
9#define _LTTNG_UTILS_H
10
e358ddd5 11#include <common/argpar/argpar.h>
6e11909e 12#include <common/container-wrapper.hpp>
c9e313bc 13#include <common/dynamic-array.hpp>
ca938aa5 14#include <common/make-unique-wrapper.hpp>
679b4943 15
b9dfb167
DG
16#include <lttng/lttng.h>
17
ca938aa5
OD
18#include <iterator>
19#include <memory>
28f23191
JG
20#include <popt.h>
21
8960e9cd 22extern char *opt_relayd_path;
92360082 23extern int opt_no_sessiond;
28f23191 24extern char *opt_sessiond_path;
92360082 25extern pid_t sessiond_pid;
8960e9cd 26
3c9bd23c
SM
27struct cmd_struct;
28
6e11909e
JG
29namespace lttng {
30namespace cli {
31
ca938aa5 32struct session_spec {
42a11b8f 33 enum class type {
ca938aa5
OD
34 NAME,
35 GLOB_PATTERN,
36 ALL,
37 };
38
42a11b8f
JG
39 explicit session_spec(type spec_type, const char *name_or_pattern = nullptr) noexcept :
40 type_(spec_type), value(name_or_pattern)
41 {
42 }
43
44 /* Disambiguate type enum from the member for buggy g++ versions. */
45 type type_;
ca938aa5
OD
46 const char *value;
47};
48
f74e820c 49class session_list;
9497e2f7 50
f74e820c
JG
51namespace details {
52class session_storage {
ca938aa5 53public:
f74e820c
JG
54 session_storage(lttng_session *raw_sessions, std::size_t sessions_count) :
55 _array(raw_sessions), _count(sessions_count)
ca938aa5
OD
56 {
57 }
58
f74e820c
JG
59 session_storage(session_storage&& original) :
60 _array(std::move(original._array)), _count(original._count)
ca938aa5 61 {
ca938aa5
OD
62 }
63
f74e820c
JG
64 session_storage(session_storage&& original, std::size_t new_count) :
65 _array(std::move(original._array)), _count(new_count)
ca938aa5 66 {
ca938aa5
OD
67 }
68
a1949b5a 69 std::unique_ptr<lttng_session[],
f74e820c
JG
70 lttng::memory::create_deleter_class<lttng_session, lttng::free>::deleter>
71 _array = nullptr;
72 std::size_t _count = 0;
73};
ca938aa5 74
f74e820c
JG
75class session_list_operations {
76public:
77 static lttng_session& get(const lttng::cli::details::session_storage& storage,
78 std::size_t index) noexcept
ca938aa5 79 {
a1949b5a 80 return storage._array[index];
ca938aa5
OD
81 }
82
f74e820c 83 static std::size_t size(const lttng::cli::details::session_storage& storage)
9497e2f7 84 {
f74e820c 85 return storage._count;
9497e2f7 86 }
f74e820c
JG
87};
88} /* namespace details */
89
90/*
91 * We don't use a std::vector here because it would make a copy of the C array.
92 */
93class session_list
94 : public lttng::utils::random_access_container_wrapper<details::session_storage,
95 lttng_session&,
96 details::session_list_operations> {
97public:
98 friend details::session_list_operations;
9497e2f7 99
f74e820c
JG
100 session_list() :
101 lttng::utils::random_access_container_wrapper<details::session_storage,
102 lttng_session&,
103 details::session_list_operations>(
104 { nullptr, 0 })
9497e2f7 105 {
9497e2f7
JG
106 }
107
f74e820c
JG
108 session_list(session_list&& original) :
109 lttng::utils::random_access_container_wrapper<details::session_storage,
110 lttng_session&,
111 details::session_list_operations>(
56e5528d 112 std::move(original._container))
ca938aa5 113 {
ca938aa5
OD
114 }
115
f74e820c
JG
116 session_list(session_list&& original, std::size_t new_count) :
117 lttng::utils::random_access_container_wrapper<details::session_storage,
118 lttng_session&,
119 details::session_list_operations>(
120 { std::move(original._container), new_count })
ca938aa5 121 {
ca938aa5
OD
122 }
123
f74e820c
JG
124 session_list(lttng_session *raw_sessions, std::size_t raw_sessions_count) :
125 lttng::utils::random_access_container_wrapper<details::session_storage,
126 lttng_session&,
127 details::session_list_operations>(
128 { raw_sessions, raw_sessions_count })
ca938aa5 129 {
ca938aa5
OD
130 }
131
f74e820c 132 void resize(std::size_t new_size) noexcept
ca938aa5 133 {
f74e820c 134 _container._count = new_size;
ca938aa5 135 }
ca938aa5
OD
136};
137
6e11909e
JG
138lttng::cli::session_list list_sessions(const struct session_spec& spec);
139} /* namespace cli */
140} /* namespace lttng */
141
f3ed775e 142char *get_session_name(void);
1dac0189 143char *get_session_name_quiet(void);
3c9bd23c 144void list_commands(struct cmd_struct *commands, FILE *ofp);
679b4943 145void list_cmd_options(FILE *ofp, struct poptOption *options);
b083f028 146void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options);
f3ed775e 147
8ce58bad
MD
148/*
149 * Return the minimum order for which x <= (1UL << order).
150 * Return -1 if x is 0.
151 */
152int get_count_order_u32(uint32_t x);
153
154/*
155 * Return the minimum order for which x <= (1UL << order).
156 * Return -1 if x is 0.
157 */
158int get_count_order_u64(uint64_t x);
159
160/*
161 * Return the minimum order for which x <= (1UL << order).
162 * Return -1 if x is 0.
163 */
164int get_count_order_ulong(unsigned long x);
165
4fd2697f 166const char *get_event_type_str(enum lttng_event_type event_type);
b9dfb167 167
28f23191 168int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
b9dfb167 169
8960e9cd
DG
170int spawn_relayd(const char *pathname, int port);
171int check_relayd(void);
20fb9e02 172void print_session_stats(const char *session_name);
58f237ca 173int get_session_stats_str(const char *session_name, char **str);
4fc83d94 174int show_cmd_help(const char *cmd_name, const char *help_msg);
8960e9cd 175
28f23191
JG
176int print_trace_archive_location(const struct lttng_trace_archive_location *location,
177 const char *session_name);
bbbfd849 178
e358ddd5 179int validate_exclusion_list(const char *event_name,
28f23191 180 const struct lttng_dynamic_pointer_array *exclusions);
e358ddd5 181
f3ed775e 182#endif /* _LTTNG_UTILS_H */
This page took 0.086357 seconds and 4 git commands to generate.