File: pfs_timer.h

package info (click to toggle)
mysql-8.0 8.0.44-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,272,892 kB
  • sloc: cpp: 4,685,345; ansic: 412,712; pascal: 108,395; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; python: 21,816; sh: 17,285; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,083; makefile: 1,793; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (178 lines) | stat: -rw-r--r-- 5,537 bytes parent folder | download
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* Copyright (c) 2008, 2025, Oracle and/or its affiliates.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License, version 2.0,
  as published by the Free Software Foundation.

  This program is designed to work with certain software (including
  but not limited to OpenSSL) that is licensed under separate terms,
  as designated in a particular file or component or in included license
  documentation.  The authors of MySQL hereby grant you an additional
  permission to link the program and your derivative works with the
  separately licensed software that they have either included with
  the program or referenced in the documentation.

  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, version 2.0, 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, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef PFS_TIMER_H
#define PFS_TIMER_H

/**
  @file storage/perfschema/pfs_timer.h
  Performance schema timers (declarations).
*/

#include "my_config.h"
#include "my_inttypes.h"
#include "my_rdtsc.h"

#include "storage/perfschema/pfs_column_types.h"
#include "storage/perfschema/pfs_histogram.h"

/** Conversion factor, from micro seconds to pico seconds. */
#define MICROSEC_TO_PICOSEC 1000000

/** Conversion factor, from nano seconds to pico seconds. */
#define NANOSEC_TO_PICOSEC 1000

#ifndef MY_CONFIG_H
/* my_config.h MUST be included before testing HAVE_XXX flags. */
#error "This build is broken"
#endif

/*
  HAVE_SYS_TIMES_H:
  - cmakedefine from config.h.cmake
  - testable after #include "my_config.h"

  HAVE_GETHRTIME:
  - cmakedefine from config.h.cmake
  - testable after #include "my_config.h"

  HAVE_CLOCK_GETTIME:
  - cmakedefine from config.h.cmake
  - testable after #include "my_config.h"

  HAVE_CLOCK_REALTIME:
  - cmakedefine from config.h.cmake
  - testable after #include "my_config.h"
  - not to be confused with CLOCK_REALTIME,
    which is set in #include <times.h>

  __APPLE__:
  __MACH__:
*/

/*
  See my_timer_nanoseconds() in mysys/my_rdtsc.cc
  This logic matches my_timer_nanoseconds(),
  to find out at compile time if a nanosecond
  timer is available or not.
*/

#if defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME)
#define HAVE_NANOSEC_TIMER
/*
  Testing HAVE_CLOCK_REALTIME instead of CLOCK_REALTIME
*/
#elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_REALTIME)
#define HAVE_NANOSEC_TIMER
#elif defined(__APPLE__) && defined(__MACH__)
#define HAVE_NANOSEC_TIMER
#endif

#ifdef HAVE_NANOSEC_TIMER
/* Use NANOSECOND for statements and the like. */
#define USED_TIMER_NAME TIMER_NAME_NANOSEC
#define USED_TIMER my_timer_nanoseconds
#else
/* Otherwise use MICROSECOND for statements and the like. */
#define USED_TIMER_NAME TIMER_NAME_MICROSEC
#define USED_TIMER my_timer_microseconds
#endif

ulonglong inline get_idle_timer() { return USED_TIMER(); }

ulonglong inline get_wait_timer() { return my_timer_cycles(); }

ulonglong inline get_stage_timer() { return USED_TIMER(); }

ulonglong inline get_statement_timer() { return USED_TIMER(); }

ulonglong inline get_transaction_timer() { return USED_TIMER(); }

ulonglong inline get_thread_cpu_timer() { return my_timer_thread_cpu(); }

/**
  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 the statement timer.
    @return the normalizer for the timer
  */
  static time_normalizer *get_idle();
  static time_normalizer *get_wait();
  static time_normalizer *get_stage();
  static time_normalizer *get_statement();
  static time_normalizer *get_transaction();

  /** Timer value at server startup. */
  ulonglong m_v0;
  /** Conversion factor from timer values to pico seconds. */
  ulonglong m_factor;
  /** Histogram bucket timers, expressed in timer unit. */
  ulonglong m_bucket_timer[NUMBER_OF_BUCKETS + 1];

  /**
    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) const {
    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) const {
    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) const;

  ulong bucket_index(ulonglong t);
};

/**
  Timer information data.
  Characteristics about each supported timer.
*/
extern MY_TIMER_INFO pfs_timer_info;

/** Initialize the timer component. */
void init_timers();

#endif