MySQL 8.3.0
Source Code Documentation
trace_span.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef ROUTING_TRACE_SPAN_INCLUDED
26#define ROUTING_TRACE_SPAN_INCLUDED
27
28#include <chrono>
29#include <list>
30#include <string>
31#include <variant>
32#include <vector>
33
34struct TraceEvent {
36 std::pair<std::string,
37 std::variant<std::monostate, int64_t, bool, std::string>>;
38 using attributes_type = std::vector<element_type>;
39
40 TraceEvent(std::string name_, attributes_type attrs_)
41 : start_time_system(std::chrono::system_clock::now()),
42 start_time(std::chrono::steady_clock::now()),
43
45 name(std::move(name_)),
46 attrs(std::move(attrs_)) {}
47
48 TraceEvent(std::string name_)
49 : start_time_system(std::chrono::system_clock::now()),
50 start_time(std::chrono::steady_clock::now()),
52 name(std::move(name_)) {}
53
54 std::chrono::system_clock::time_point start_time_system;
55 std::chrono::steady_clock::time_point start_time;
56 std::chrono::steady_clock::time_point end_time;
57
58 std::list<TraceEvent> events;
59
60 std::string name;
61
63
64 enum class StatusCode {
65 kUnset,
66 kOk,
67 kError,
68 };
69
71};
72
73/**
74 * Events of a command.
75 */
76class TraceSpan {
77 public:
78 [[nodiscard]] bool active() const { return active_; }
79 void active(bool v) { active_ = v; }
80
81 [[nodiscard]] std::chrono::system_clock::time_point start_system_time_point()
82 const {
84 }
85
86 [[nodiscard]] std::chrono::steady_clock::time_point start_time_point() const {
87 return start_time_point_;
88 }
89
90 const std::list<TraceEvent> &events() const { return events_; }
91
92 std::list<TraceEvent> &events() { return events_; }
93
94 void clear() { events_.clear(); }
95
96 [[nodiscard]] bool empty() const { return events_.empty(); }
97
98 operator bool() const { return active_; }
99
100 private:
101 std::list<TraceEvent> events_;
102
103 std::chrono::system_clock::time_point start_system_time_point_{
104 std::chrono::system_clock::now()};
105 std::chrono::steady_clock::time_point start_time_point_{
106 std::chrono::steady_clock::now()};
107
108 bool active_{false};
109};
110
111#endif
Events of a command.
Definition: trace_span.h:76
void active(bool v)
Definition: trace_span.h:79
std::chrono::steady_clock::time_point start_time_point() const
Definition: trace_span.h:86
std::chrono::system_clock::time_point start_system_time_point_
Definition: trace_span.h:103
std::list< TraceEvent > events_
Definition: trace_span.h:101
std::list< TraceEvent > & events()
Definition: trace_span.h:92
bool active() const
Definition: trace_span.h:78
bool active_
Definition: trace_span.h:108
std::chrono::steady_clock::time_point start_time_point_
Definition: trace_span.h:105
const std::list< TraceEvent > & events() const
Definition: trace_span.h:90
std::chrono::system_clock::time_point start_system_time_point() const
Definition: trace_span.h:81
bool empty() const
Definition: trace_span.h:96
void clear()
Definition: trace_span.h:94
Definition: varlen_sort.h:174
Definition: trace_span.h:34
std::chrono::steady_clock::time_point end_time
Definition: trace_span.h:56
std::string name
Definition: trace_span.h:60
std::chrono::steady_clock::time_point start_time
Definition: trace_span.h:55
attributes_type attrs
Definition: trace_span.h:62
std::list< TraceEvent > events
Definition: trace_span.h:58
StatusCode
Definition: trace_span.h:64
std::chrono::system_clock::time_point start_time_system
Definition: trace_span.h:54
TraceEvent(std::string name_)
Definition: trace_span.h:48
StatusCode status_code
Definition: trace_span.h:70
std::vector< element_type > attributes_type
Definition: trace_span.h:38
std::pair< std::string, std::variant< std::monostate, int64_t, bool, std::string > > element_type
Definition: trace_span.h:37
TraceEvent(std::string name_, attributes_type attrs_)
Definition: trace_span.h:40