lttng: start: move static symbols to anonymous namespace
[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 {
43 class iterator : public std::iterator<std::random_access_iterator_tag, std::size_t> {
44 public:
45 explicit iterator(session_list& list, std::size_t k) : _list(list), _index(k)
46 {
47 }
48
49 iterator& operator++() noexcept
50 {
51 ++_index;
52 return *this;
53 }
54
55 iterator& operator--() noexcept
56 {
57 --_index;
58 return *this;
59 }
60
61 iterator& operator++(int) noexcept
62 {
63 _index++;
64 return *this;
65 }
66
67 iterator& operator--(int) noexcept
68 {
69 _index--;
70 return *this;
71 }
72
73 bool operator==(iterator other) const noexcept
74 {
75 return _index == other._index;
76 }
77
78 bool operator!=(iterator other) const noexcept
79 {
80 return !(*this == other);
81 }
82
83 lttng_session& operator*() const noexcept
84 {
85 return _list[_index];
86 }
87
88 private:
89 session_list& _list;
90 std::size_t _index;
91 };
92
93public:
94 session_list() : _sessions_count(0), _sessions(nullptr)
95 {
96 }
97
98 session_list(session_list&& original, std::size_t new_count)
99 {
100 _sessions_count = new_count;
101 _sessions = std::move(original._sessions);
102 }
103
104 session_list(struct lttng_session *raw_sessions, std::size_t raw_sessions_count)
105 {
106 _sessions_count = raw_sessions_count;
107 _sessions.reset(raw_sessions);
108 }
109
110 iterator begin() noexcept
111 {
112 return iterator(*this, 0);
113 }
114
115 iterator end() noexcept
116 {
117 return iterator(*this, _sessions_count);
118 }
119
120 std::size_t size() const noexcept
121 {
122 return _sessions_count;
123 }
124
125 void resize(std::size_t new_size) noexcept
126 {
127 _sessions_count = new_size;
128 }
129
130 lttng_session& operator[](std::size_t index)
131 {
132 LTTNG_ASSERT(index < _sessions_count);
133 return _sessions.get()[index];
134 }
135
136 const lttng_session& operator[](std::size_t index) const
137 {
138 LTTNG_ASSERT(index < _sessions_count);
139 return _sessions.get()[index];
140 }
141
142private:
143 std::size_t _sessions_count;
144 std::unique_ptr<lttng_session,
145 lttng::details::create_unique_class<lttng_session, lttng::free>>
146 _sessions;
147};
148
f3ed775e 149char *get_session_name(void);
1dac0189 150char *get_session_name_quiet(void);
3c9bd23c 151void list_commands(struct cmd_struct *commands, FILE *ofp);
679b4943 152void list_cmd_options(FILE *ofp, struct poptOption *options);
b083f028 153void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options);
f3ed775e 154
8ce58bad
MD
155/*
156 * Return the minimum order for which x <= (1UL << order).
157 * Return -1 if x is 0.
158 */
159int get_count_order_u32(uint32_t x);
160
161/*
162 * Return the minimum order for which x <= (1UL << order).
163 * Return -1 if x is 0.
164 */
165int get_count_order_u64(uint64_t x);
166
167/*
168 * Return the minimum order for which x <= (1UL << order).
169 * Return -1 if x is 0.
170 */
171int get_count_order_ulong(unsigned long x);
172
4fd2697f 173const char *get_event_type_str(enum lttng_event_type event_type);
b9dfb167 174
28f23191 175int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
b9dfb167 176
8960e9cd
DG
177int spawn_relayd(const char *pathname, int port);
178int check_relayd(void);
20fb9e02 179void print_session_stats(const char *session_name);
58f237ca 180int get_session_stats_str(const char *session_name, char **str);
4fc83d94 181int show_cmd_help(const char *cmd_name, const char *help_msg);
8960e9cd 182
28f23191
JG
183int print_trace_archive_location(const struct lttng_trace_archive_location *location,
184 const char *session_name);
bbbfd849 185
e358ddd5 186int validate_exclusion_list(const char *event_name,
28f23191 187 const struct lttng_dynamic_pointer_array *exclusions);
e358ddd5 188
ca938aa5
OD
189session_list list_sessions(const struct session_spec& spec);
190
f3ed775e 191#endif /* _LTTNG_UTILS_H */
This page took 0.080428 seconds and 4 git commands to generate.