Test: client: start, stop, destroy: add tests for --glob/--all
[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>
c9e313bc 12#include <common/dynamic-array.hpp>
ca938aa5 13#include <common/make-unique-wrapper.hpp>
679b4943 14
b9dfb167
DG
15#include <lttng/lttng.h>
16
ca938aa5
OD
17#include <iterator>
18#include <memory>
28f23191
JG
19#include <popt.h>
20
8960e9cd 21extern char *opt_relayd_path;
92360082 22extern int opt_no_sessiond;
28f23191 23extern char *opt_sessiond_path;
92360082 24extern pid_t sessiond_pid;
8960e9cd 25
3c9bd23c
SM
26struct cmd_struct;
27
ca938aa5
OD
28struct session_spec {
29 enum type {
30 NAME,
31 GLOB_PATTERN,
32 ALL,
33 };
34
35 type type;
36 const char *value;
37};
38
39/*
40 * We don't use a std::vector here because it would make a copy of the C array.
41 */
42class session_list {
9497e2f7 43 template <typename ContainerType, typename DereferenceReturnType>
767954d2
JG
44 class _iterator
45 : public std::iterator<std::random_access_iterator_tag, std::size_t> {
ca938aa5 46 public:
767954d2
JG
47 explicit _iterator(ContainerType& list, std::size_t k) :
48 _list(list), _index(k)
ca938aa5
OD
49 {
50 }
51
767954d2 52 _iterator& operator++() noexcept
ca938aa5
OD
53 {
54 ++_index;
55 return *this;
56 }
57
767954d2 58 _iterator& operator--() noexcept
ca938aa5
OD
59 {
60 --_index;
61 return *this;
62 }
63
767954d2 64 _iterator& operator++(int) noexcept
ca938aa5
OD
65 {
66 _index++;
67 return *this;
68 }
69
767954d2 70 _iterator& operator--(int) noexcept
ca938aa5
OD
71 {
72 _index--;
73 return *this;
74 }
75
767954d2 76 bool operator==(_iterator other) const noexcept
ca938aa5
OD
77 {
78 return _index == other._index;
79 }
80
767954d2 81 bool operator!=(_iterator other) const noexcept
ca938aa5
OD
82 {
83 return !(*this == other);
84 }
85
9497e2f7 86 DereferenceReturnType& operator*() const noexcept
ca938aa5
OD
87 {
88 return _list[_index];
89 }
90
91 private:
9497e2f7 92 ContainerType& _list;
ca938aa5
OD
93 std::size_t _index;
94 };
95
767954d2
JG
96 using iterator = _iterator<session_list, lttng_session>;
97 using const_iterator = _iterator<const session_list, const lttng_session>;
9497e2f7 98
ca938aa5
OD
99public:
100 session_list() : _sessions_count(0), _sessions(nullptr)
101 {
102 }
103
104 session_list(session_list&& original, std::size_t new_count)
105 {
106 _sessions_count = new_count;
107 _sessions = std::move(original._sessions);
108 }
109
110 session_list(struct lttng_session *raw_sessions, std::size_t raw_sessions_count)
111 {
112 _sessions_count = raw_sessions_count;
113 _sessions.reset(raw_sessions);
114 }
115
116 iterator begin() noexcept
117 {
118 return iterator(*this, 0);
119 }
120
121 iterator end() noexcept
122 {
123 return iterator(*this, _sessions_count);
124 }
125
9497e2f7
JG
126 const_iterator begin() const noexcept
127 {
128 return const_iterator(*this, 0);
129 }
130
131 const_iterator end() const noexcept
132 {
133 return const_iterator(*this, _sessions_count);
134 }
135
ca938aa5
OD
136 std::size_t size() const noexcept
137 {
138 return _sessions_count;
139 }
140
141 void resize(std::size_t new_size) noexcept
142 {
143 _sessions_count = new_size;
144 }
145
146 lttng_session& operator[](std::size_t index)
147 {
148 LTTNG_ASSERT(index < _sessions_count);
149 return _sessions.get()[index];
150 }
151
152 const lttng_session& operator[](std::size_t index) const
153 {
154 LTTNG_ASSERT(index < _sessions_count);
155 return _sessions.get()[index];
156 }
157
158private:
159 std::size_t _sessions_count;
160 std::unique_ptr<lttng_session,
f053d40c 161 lttng::memory::create_deleter_class<lttng_session, lttng::free>::deleter>
ca938aa5
OD
162 _sessions;
163};
164
f3ed775e 165char *get_session_name(void);
1dac0189 166char *get_session_name_quiet(void);
3c9bd23c 167void list_commands(struct cmd_struct *commands, FILE *ofp);
679b4943 168void list_cmd_options(FILE *ofp, struct poptOption *options);
b083f028 169void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options);
f3ed775e 170
8ce58bad
MD
171/*
172 * Return the minimum order for which x <= (1UL << order).
173 * Return -1 if x is 0.
174 */
175int get_count_order_u32(uint32_t x);
176
177/*
178 * Return the minimum order for which x <= (1UL << order).
179 * Return -1 if x is 0.
180 */
181int get_count_order_u64(uint64_t x);
182
183/*
184 * Return the minimum order for which x <= (1UL << order).
185 * Return -1 if x is 0.
186 */
187int get_count_order_ulong(unsigned long x);
188
4fd2697f 189const char *get_event_type_str(enum lttng_event_type event_type);
b9dfb167 190
28f23191 191int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
b9dfb167 192
8960e9cd
DG
193int spawn_relayd(const char *pathname, int port);
194int check_relayd(void);
20fb9e02 195void print_session_stats(const char *session_name);
58f237ca 196int get_session_stats_str(const char *session_name, char **str);
4fc83d94 197int show_cmd_help(const char *cmd_name, const char *help_msg);
8960e9cd 198
28f23191
JG
199int print_trace_archive_location(const struct lttng_trace_archive_location *location,
200 const char *session_name);
bbbfd849 201
e358ddd5 202int validate_exclusion_list(const char *event_name,
28f23191 203 const struct lttng_dynamic_pointer_array *exclusions);
e358ddd5 204
ca938aa5
OD
205session_list list_sessions(const struct session_spec& spec);
206
f3ed775e 207#endif /* _LTTNG_UTILS_H */
This page took 0.082298 seconds and 4 git commands to generate.