MySQL 8.0.39
Source Code Documentation
pfs_timer.h
Go to the documentation of this file.
1/* Copyright (c) 2008, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
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, version 2.0, 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#ifndef PFS_TIMER_H
25#define PFS_TIMER_H
26
27/**
28 @file storage/perfschema/pfs_timer.h
29 Performance schema timers (declarations).
30*/
31
32#include "my_config.h"
33#include "my_inttypes.h"
34#include "my_rdtsc.h"
35
38
39/** Conversion factor, from micro seconds to pico seconds. */
40#define MICROSEC_TO_PICOSEC 1000000
41
42/** Conversion factor, from nano seconds to pico seconds. */
43#define NANOSEC_TO_PICOSEC 1000
44
45#ifndef MY_CONFIG_H
46/* my_config.h MUST be included before testing HAVE_XXX flags. */
47#error "This build is broken"
48#endif
49
50/*
51 HAVE_SYS_TIMES_H:
52 - cmakedefine from config.h.cmake
53 - testable after #include "my_config.h"
54
55 HAVE_GETHRTIME:
56 - cmakedefine from config.h.cmake
57 - testable after #include "my_config.h"
58
59 HAVE_CLOCK_GETTIME:
60 - cmakedefine from config.h.cmake
61 - testable after #include "my_config.h"
62
63 HAVE_CLOCK_REALTIME:
64 - cmakedefine from config.h.cmake
65 - testable after #include "my_config.h"
66 - not to be confused with CLOCK_REALTIME,
67 which is set in #include <times.h>
68
69 __APPLE__:
70 __MACH__:
71*/
72
73/*
74 See my_timer_nanoseconds() in mysys/my_rdtsc.cc
75 This logic matches my_timer_nanoseconds(),
76 to find out at compile time if a nanosecond
77 timer is available or not.
78*/
79
80#if defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME)
81#define HAVE_NANOSEC_TIMER
82/*
83 Testing HAVE_CLOCK_REALTIME instead of CLOCK_REALTIME
84*/
85#elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_REALTIME)
86#define HAVE_NANOSEC_TIMER
87#elif defined(__APPLE__) && defined(__MACH__)
88#define HAVE_NANOSEC_TIMER
89#endif
90
91#ifdef HAVE_NANOSEC_TIMER
92/* Use NANOSECOND for statements and the like. */
93#define USED_TIMER_NAME TIMER_NAME_NANOSEC
94#define USED_TIMER my_timer_nanoseconds
95#else
96/* Otherwise use MICROSECOND for statements and the like. */
97#define USED_TIMER_NAME TIMER_NAME_MICROSEC
98#define USED_TIMER my_timer_microseconds
99#endif
100
101ulonglong inline get_idle_timer() { return USED_TIMER(); }
102
104
106
108
110
112
113/**
114 A time normalizer.
115 A time normalizer consist of a transformation that
116 converts raw timer values (expressed in the timer unit)
117 to normalized values, expressed in picoseconds.
118*/
120 /**
121 Get a time normalizer for the statement timer.
122 @return the normalizer for the timer
123 */
124 static time_normalizer *get_idle();
125 static time_normalizer *get_wait();
126 static time_normalizer *get_stage();
129
130 /** Timer value at server startup. */
132 /** Conversion factor from timer values to pico seconds. */
134 /** Histogram bucket timers, expressed in timer unit. */
136
137 /**
138 Convert a wait from timer units to pico seconds.
139 @param wait a wait, expressed in timer units
140 @return the wait, expressed in pico seconds
141 */
143 return wait * m_factor;
144 }
145
146 /**
147 Convert a time from timer units to pico seconds.
148 @param t a time, expressed in timer units
149 @return the time, expressed in pico seconds
150 */
152 return (t == 0 ? 0 : (t - m_v0) * m_factor);
153 }
154
155 /**
156 Convert start / end times from timer units to pico seconds.
157 @param start start time, expressed in timer units
158 @param end end time, expressed in timer units
159 @param[out] pico_start start time, expressed in pico seconds
160 @param[out] pico_end end time, expressed in pico seconds
161 @param[out] pico_wait wait time, expressed in pico seconds
162 */
163 void to_pico(ulonglong start, ulonglong end, ulonglong *pico_start,
164 ulonglong *pico_end, ulonglong *pico_wait) const;
165
166 ulong bucket_index(ulonglong t);
167};
168
169/**
170 Timer information data.
171 Characteristics about each supported timer.
172*/
174
175/** Initialize the timer component. */
176void init_timers();
177
178#endif
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:177
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Multi-platform timer code.
ulonglong my_timer_cycles(void)
A cycle timer.
Definition: my_rdtsc.cc:98
ulonglong my_timer_thread_cpu(void)
A THREAD CPU timer.
Definition: my_rdtsc.cc:319
static int wait(mysql_cond_t *that, mysql_mutex_t *mutex_arg, const char *, unsigned int)
Definition: mysql_cond_v1_native.cc:63
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
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:36
ulonglong get_wait_timer()
Definition: pfs_timer.h:103
MY_TIMER_INFO pfs_timer_info
Timer information data.
Definition: pfs_timer.cc:40
ulonglong get_thread_cpu_timer()
Definition: pfs_timer.h:111
#define USED_TIMER
Definition: pfs_timer.h:94
ulonglong get_statement_timer()
Definition: pfs_timer.h:107
ulonglong get_stage_timer()
Definition: pfs_timer.h:105
void init_timers()
Initialize the timer component.
Definition: pfs_timer.cc:62
ulonglong get_transaction_timer()
Definition: pfs_timer.h:109
ulonglong get_idle_timer()
Definition: pfs_timer.h:101
Characteristics of all the supported timers.
Definition: my_rdtsc.h:53
A time normalizer.
Definition: pfs_timer.h:119
ulonglong time_to_pico(ulonglong t) const
Convert a time from timer units to pico seconds.
Definition: pfs_timer.h:151
static time_normalizer * get_idle()
Get a time normalizer for the statement timer.
Definition: pfs_timer.cc:151
void to_pico(ulonglong start, ulonglong end, ulonglong *pico_start, ulonglong *pico_end, ulonglong *pico_wait) const
Convert start / end times from timer units to pico seconds.
Definition: pfs_timer.cc:171
ulonglong wait_to_pico(ulonglong wait) const
Convert a wait from timer units to pico seconds.
Definition: pfs_timer.h:142
static time_normalizer * get_stage()
Definition: pfs_timer.cc:159
ulonglong m_bucket_timer[NUMBER_OF_BUCKETS+1]
Histogram bucket timers, expressed in timer unit.
Definition: pfs_timer.h:135
static time_normalizer * get_transaction()
Definition: pfs_timer.cc:167
ulong bucket_index(ulonglong t)
Definition: pfs_timer.cc:190
static time_normalizer * get_wait()
Definition: pfs_timer.cc:155
ulonglong m_factor
Conversion factor from timer values to pico seconds.
Definition: pfs_timer.h:133
ulonglong m_v0
Timer value at server startup.
Definition: pfs_timer.h:131
static time_normalizer * get_statement()
Definition: pfs_timer.cc:163