1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
#ifndef PFS_TIMER_H
#define PFS_TIMER_H
/**
@file storage/perfschema/pfs_timer.h
Performance schema timers (declarations).
*/
#include <my_rdtsc.h>
#include "pfs_column_types.h"
/** Conversion factor, from micro seconds to pico seconds. */
#define MICROSEC_TO_PICOSEC 1000000
/**
A time normalizer.
A time normalizer consist of a transformation that
converts raw timer values (expressed in the timer unit)
to normalized values, expressed in picoseconds.
*/
struct time_normalizer
{
/**
Get a time normalizer for a given timer.
@param timer_name the timer name
@return the normalizer for the timer
*/
static time_normalizer* get(enum_timer_name timer_name);
/** Timer value at server statup. */
ulonglong m_v0;
/** Conversion factor from timer values to pico seconds. */
ulonglong m_factor;
/**
Convert a wait from timer units to pico seconds.
@param wait a wait, expressed in timer units
@return the wait, expressed in pico seconds
*/
inline ulonglong wait_to_pico(ulonglong wait)
{
return wait * m_factor;
}
/**
Convert a time from timer units to pico seconds.
@param t a time, expressed in timer units
@return the time, expressed in pico seconds
*/
inline ulonglong time_to_pico(ulonglong t)
{
return (t == 0 ? 0 : (t - m_v0) * m_factor);
}
/**
Convert start / end times from timer units to pico seconds.
@param start start time, expressed in timer units
@param end end time, expressed in timer units
@param[out] pico_start start time, expressed in pico seconds
@param[out] pico_end end time, expressed in pico seconds
@param[out] pico_wait wait time, expressed in pico seconds
*/
void to_pico(ulonglong start, ulonglong end,
ulonglong *pico_start, ulonglong *pico_end, ulonglong *pico_wait);
};
/**
Idle timer.
The timer used to measure all idle events.
*/
extern enum_timer_name idle_timer;
/**
Wait timer.
The timer used to measure all wait events.
*/
extern enum_timer_name wait_timer;
/**
Stage timer.
The timer used to measure all stage events.
*/
extern enum_timer_name stage_timer;
/**
Statement timer.
The timer used to measure all statement events.
*/
extern enum_timer_name statement_timer;
/**
Timer information data.
Characteristics about each suported timer.
*/
extern MYSQL_PLUGIN_IMPORT MY_TIMER_INFO sys_timer_info;
/** Initialize the timer component. */
void init_timers();
extern "C"
{
/** A timer function. */
typedef ulonglong (*timer_fct_t)(void);
}
/**
Get a timer value, in pico seconds.
@param timer_name the timer to use
@return timer value, in pico seconds
*/
ulonglong get_timer_pico_value(enum_timer_name timer_name);
/**
Get a timer value, in timer units.
@param timer_name the timer to use
@return timer value, in timer units
*/
ulonglong get_timer_raw_value(enum_timer_name timer_name);
/**
Get a timer value and function, in timer units.
This function is useful when code needs to call the same timer several times.
The returned timer function can be invoked directly, which avoids having to
resolve the timer by name for each call.
@param timer_name the timer to use
@param[out] fct the timer function
@return timer value, in timer units
*/
ulonglong get_timer_raw_value_and_function(enum_timer_name timer_name, timer_fct_t *fct);
#endif
|