MySQL 8.0.30
Source Code Documentation
pfs_timer.h
Go to the documentation of this file.
1/* Copyright (c) 2008, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef PFS_TIMER_H
24#define PFS_TIMER_H
25
26/**
27 @file storage/perfschema/pfs_timer.h
28 Performance schema timers (declarations).
29*/
30
31#include "my_config.h"
32#include "my_inttypes.h"
33#include "my_rdtsc.h"
34
37
38/** Conversion factor, from micro seconds to pico seconds. */
39#define MICROSEC_TO_PICOSEC 1000000
40
41/** Conversion factor, from nano seconds to pico seconds. */
42#define NANOSEC_TO_PICOSEC 1000
43
44#ifndef MY_CONFIG_H
45/* my_config.h MUST be included before testing HAVE_XXX flags. */
46#error "This build is broken"
47#endif
48
49/*
50 HAVE_SYS_TIMES_H:
51 - cmakedefine from config.h.cmake
52 - testable after #include "my_config.h"
53
54 HAVE_GETHRTIME:
55 - cmakedefine from config.h.cmake
56 - testable after #include "my_config.h"
57
58 HAVE_CLOCK_GETTIME:
59 - cmakedefine from config.h.cmake
60 - testable after #include "my_config.h"
61
62 HAVE_CLOCK_REALTIME:
63 - cmakedefine from config.h.cmake
64 - testable after #include "my_config.h"
65 - not to be confused with CLOCK_REALTIME,
66 which is set in #include <times.h>
67
68 __APPLE__:
69 __MACH__:
70*/
71
72/*
73 See my_timer_nanoseconds() in mysys/my_rdtsc.cc
74 This logic matches my_timer_nanoseconds(),
75 to find out at compile time if a nanosecond
76 timer is available or not.
77*/
78
79#if defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME)
80#define HAVE_NANOSEC_TIMER
81/*
82 Testing HAVE_CLOCK_REALTIME instead of CLOCK_REALTIME
83*/
84#elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_REALTIME)
85#define HAVE_NANOSEC_TIMER
86#elif defined(__APPLE__) && defined(__MACH__)
87#define HAVE_NANOSEC_TIMER
88#endif
89
90#ifdef HAVE_NANOSEC_TIMER
91/* Use NANOSECOND for statements and the like. */
92#define USED_TIMER_NAME TIMER_NAME_NANOSEC
93#define USED_TIMER my_timer_nanoseconds
94#else
95/* Otherwise use MICROSECOND for statements and the like. */
96#define USED_TIMER_NAME TIMER_NAME_MICROSEC
97#define USED_TIMER my_timer_microseconds
98#endif
99
100ulonglong inline get_idle_timer() { return USED_TIMER(); }
101
103
105
107
109
111
112/**
113 A time normalizer.
114 A time normalizer consist of a transformation that
115 converts raw timer values (expressed in the timer unit)
116 to normalized values, expressed in picoseconds.
117*/
119 /**
120 Get a time normalizer for the statement timer.
121 @return the normalizer for the timer
122 */
123 static time_normalizer *get_idle();
124 static time_normalizer *get_wait();
125 static time_normalizer *get_stage();
128
129 /** Timer value at server startup. */
131 /** Conversion factor from timer values to pico seconds. */
133 /** Histogram bucket timers, expressed in timer unit. */
135
136 /**
137 Convert a wait from timer units to pico seconds.
138 @param wait a wait, expressed in timer units
139 @return the wait, expressed in pico seconds
140 */
142
143 /**
144 Convert a time from timer units to pico seconds.
145 @param t a time, expressed in timer units
146 @return the time, expressed in pico seconds
147 */
149 return (t == 0 ? 0 : (t - m_v0) * m_factor);
150 }
151
152 /**
153 Convert start / end times from timer units to pico seconds.
154 @param start start time, expressed in timer units
155 @param end end time, expressed in timer units
156 @param[out] pico_start start time, expressed in pico seconds
157 @param[out] pico_end end time, expressed in pico seconds
158 @param[out] pico_wait wait time, expressed in pico seconds
159 */
160 void to_pico(ulonglong start, ulonglong end, ulonglong *pico_start,
161 ulonglong *pico_end, ulonglong *pico_wait);
162
163 ulong bucket_index(ulonglong t);
164};
165
166/**
167 Timer information data.
168 Characteristics about each supported timer.
169*/
171
172/** Initialize the timer component. */
173void init_timers();
174
175#endif
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:168
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Multi-platform timer code.
ulonglong my_timer_cycles(void)
A cycle timer.
Definition: my_rdtsc.cc:97
ulonglong my_timer_thread_cpu(void)
A THREAD CPU timer.
Definition: my_rdtsc.cc:318
stdx::expected< size_t, std::error_code > wait(int epfd, epoll_event *fd_events, size_t num_fd_events, std::chrono::milliseconds timeout)
Definition: linux_epoll.h:82
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
Data types for columns used in the performance schema tables (declarations)
#define NUMBER_OF_BUCKETS
Number of buckets used in histograms.
Definition: pfs_histogram.h:35
ulonglong get_wait_timer()
Definition: pfs_timer.h:102
MY_TIMER_INFO pfs_timer_info
Timer information data.
Definition: pfs_timer.cc:39
ulonglong get_thread_cpu_timer()
Definition: pfs_timer.h:110
#define USED_TIMER
Definition: pfs_timer.h:93
ulonglong get_statement_timer()
Definition: pfs_timer.h:106
ulonglong get_stage_timer()
Definition: pfs_timer.h:104
void init_timers()
Initialize the timer component.
Definition: pfs_timer.cc:61
ulonglong get_transaction_timer()
Definition: pfs_timer.h:108
ulonglong get_idle_timer()
Definition: pfs_timer.h:100
Characteristics of all the supported timers.
Definition: my_rdtsc.h:52
A time normalizer.
Definition: pfs_timer.h:118
static time_normalizer * get_idle()
Get a time normalizer for the statement timer.
Definition: pfs_timer.cc:150
void to_pico(ulonglong start, ulonglong end, ulonglong *pico_start, ulonglong *pico_end, ulonglong *pico_wait)
Convert start / end times from timer units to pico seconds.
Definition: pfs_timer.cc:170
ulonglong time_to_pico(ulonglong t)
Convert a time from timer units to pico seconds.
Definition: pfs_timer.h:148
static time_normalizer * get_stage()
Definition: pfs_timer.cc:158
ulonglong m_bucket_timer[NUMBER_OF_BUCKETS+1]
Histogram bucket timers, expressed in timer unit.
Definition: pfs_timer.h:134
static time_normalizer * get_transaction()
Definition: pfs_timer.cc:166
ulong bucket_index(ulonglong t)
Definition: pfs_timer.cc:189
static time_normalizer * get_wait()
Definition: pfs_timer.cc:154
ulonglong m_factor
Conversion factor from timer values to pico seconds.
Definition: pfs_timer.h:132
ulonglong wait_to_pico(ulonglong wait)
Convert a wait from timer units to pico seconds.
Definition: pfs_timer.h:141
ulonglong m_v0
Timer value at server startup.
Definition: pfs_timer.h:130
static time_normalizer * get_statement()
Definition: pfs_timer.cc:162