MySQL 9.1.0
Source Code Documentation
trace_span.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTING_TRACE_SPAN_INCLUDED
27#define ROUTING_TRACE_SPAN_INCLUDED
28
29#include <chrono>
30#include <list>
31#include <string>
32#include <variant>
33#include <vector>
34
35struct TraceEvent {
37 std::pair<std::string,
38 std::variant<std::monostate, int64_t, bool, std::string>>;
39 using attributes_type = std::vector<element_type>;
40
41 TraceEvent(std::string name_, attributes_type attrs_)
42 : start_time_system(std::chrono::system_clock::now()),
43 start_time(std::chrono::steady_clock::now()),
44
46 name(std::move(name_)),
47 attrs(std::move(attrs_)) {}
48
49 TraceEvent(std::string name_)
50 : start_time_system(std::chrono::system_clock::now()),
51 start_time(std::chrono::steady_clock::now()),
53 name(std::move(name_)) {}
54
55 std::chrono::system_clock::time_point start_time_system;
56 std::chrono::steady_clock::time_point start_time;
57 std::chrono::steady_clock::time_point end_time;
58
59 std::list<TraceEvent> events;
60
61 std::string name;
62
64
65 enum class StatusCode {
66 kUnset,
67 kOk,
68 kError,
69 };
70
72};
73
74/**
75 * Events of a command.
76 */
77class TraceSpan {
78 public:
79 [[nodiscard]] bool active() const { return active_; }
80 void active(bool v) { active_ = v; }
81
82 [[nodiscard]] std::chrono::system_clock::time_point start_system_time_point()
83 const {
85 }
86
87 [[nodiscard]] std::chrono::steady_clock::time_point start_time_point() const {
88 return start_time_point_;
89 }
90
91 const std::list<TraceEvent> &events() const { return events_; }
92
93 std::list<TraceEvent> &events() { return events_; }
94
95 void clear() { events_.clear(); }
96
97 [[nodiscard]] bool empty() const { return events_.empty(); }
98
99 operator bool() const { return active_; }
100
101 private:
102 std::list<TraceEvent> events_;
103
104 std::chrono::system_clock::time_point start_system_time_point_{
105 std::chrono::system_clock::now()};
106 std::chrono::steady_clock::time_point start_time_point_{
107 std::chrono::steady_clock::now()};
108
109 bool active_{false};
110};
111
112#endif
Events of a command.
Definition: trace_span.h:77
void active(bool v)
Definition: trace_span.h:80
std::chrono::steady_clock::time_point start_time_point() const
Definition: trace_span.h:87
std::chrono::system_clock::time_point start_system_time_point_
Definition: trace_span.h:104
std::list< TraceEvent > events_
Definition: trace_span.h:102
std::list< TraceEvent > & events()
Definition: trace_span.h:93
bool active() const
Definition: trace_span.h:79
bool active_
Definition: trace_span.h:109
std::chrono::steady_clock::time_point start_time_point_
Definition: trace_span.h:106
const std::list< TraceEvent > & events() const
Definition: trace_span.h:91
std::chrono::system_clock::time_point start_system_time_point() const
Definition: trace_span.h:82
bool empty() const
Definition: trace_span.h:97
void clear()
Definition: trace_span.h:95
Definition: gcs_xcom_synode.h:64
Definition: trace_span.h:35
std::chrono::steady_clock::time_point end_time
Definition: trace_span.h:57
std::string name
Definition: trace_span.h:61
std::chrono::steady_clock::time_point start_time
Definition: trace_span.h:56
attributes_type attrs
Definition: trace_span.h:63
std::list< TraceEvent > events
Definition: trace_span.h:59
StatusCode
Definition: trace_span.h:65
std::chrono::system_clock::time_point start_time_system
Definition: trace_span.h:55
TraceEvent(std::string name_)
Definition: trace_span.h:49
StatusCode status_code
Definition: trace_span.h:71
std::vector< element_type > attributes_type
Definition: trace_span.h:39
std::pair< std::string, std::variant< std::monostate, int64_t, bool, std::string > > element_type
Definition: trace_span.h:38
TraceEvent(std::string name_, attributes_type attrs_)
Definition: trace_span.h:41