Skip to content

Commit ccc0030

Browse files
committed
Bug#14298586 - NANOSECOND TIMER NOT WORKING ON WINDOWS
Before this fix, the table performance_schema.setup_timers used always the nanosecond timer for stages and statements, be default. The problem with that is that this timer may not be available for the platform used, and in this case, stages and statements timing is not functioning properly out of the box. For example, the NANOSECOND timer is not available on windows platforms. With this fix, the idle, stage and statement timers are set to: - use the preferred timers when available, - use alternate timers when the preferred timers are not supported. This is a major change for ease of use, as it avoids the need to explicitly update table setup_timers.
1 parent 3df6243 commit ccc0030

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

mysql-test/suite/perfschema/r/start_server_nothing.result

+6-6
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ events_waits_history_long YES
160160
global_instrumentation YES
161161
thread_instrumentation YES
162162
statements_digest YES
163-
select * from performance_schema.setup_timers;
164-
NAME TIMER_NAME
165-
idle MICROSECOND
166-
wait CYCLE
167-
stage NANOSECOND
168-
statement NANOSECOND
163+
select NAME from performance_schema.setup_timers;
164+
NAME
165+
idle
166+
wait
167+
stage
168+
statement
169169
select * from performance_schema.accounts;
170170
USER HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS
171171
select * from performance_schema.cond_instances;

mysql-test/suite/perfschema/t/start_server_nothing.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ show variables like "performance_schema%";
1111
select * from performance_schema.setup_instruments;
1212
select TIMER_NAME from performance_schema.performance_timers;
1313
select * from performance_schema.setup_consumers;
14-
select * from performance_schema.setup_timers;
14+
select NAME from performance_schema.setup_timers;
1515

1616
# All empty
1717
select * from performance_schema.accounts;

storage/perfschema/pfs_timer.cc

+70-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -117,6 +117,75 @@ void init_timers(void)
117117

118118
to_pico_data[TIMER_NAME_TICK].m_v0= tick_v0;
119119
to_pico_data[TIMER_NAME_TICK].m_factor= tick_to_pico;
120+
121+
/*
122+
Depending on the platform and build options,
123+
some timers may not be available.
124+
Pick best replacements.
125+
*/
126+
127+
/*
128+
For STAGE and STATEMENT, a timer with a fixed frequency is better.
129+
The prefered timer is nanosecond, or lower resolutions.
130+
*/
131+
132+
if (nanosec_to_pico != 0)
133+
{
134+
/* Normal case. */
135+
stage_timer= TIMER_NAME_NANOSEC;
136+
statement_timer= TIMER_NAME_NANOSEC;
137+
}
138+
else if (microsec_to_pico != 0)
139+
{
140+
/* Windows. */
141+
stage_timer= TIMER_NAME_MICROSEC;
142+
statement_timer= TIMER_NAME_MICROSEC;
143+
}
144+
else if (millisec_to_pico != 0)
145+
{
146+
/* Robustness, no known cases. */
147+
stage_timer= TIMER_NAME_MILLISEC;
148+
statement_timer= TIMER_NAME_MILLISEC;
149+
}
150+
else if (tick_to_pico != 0)
151+
{
152+
/* Robustness, no known cases. */
153+
stage_timer= TIMER_NAME_TICK;
154+
statement_timer= TIMER_NAME_TICK;
155+
}
156+
else
157+
{
158+
/* Robustness, no known cases. */
159+
stage_timer= TIMER_NAME_CYCLE;
160+
statement_timer= TIMER_NAME_CYCLE;
161+
}
162+
163+
/*
164+
For IDLE, a timer with a fixed frequency is critical,
165+
as the CPU clock may slow down a lot if the server is completely idle.
166+
The prefered timer is microsecond, or lower resolutions.
167+
*/
168+
169+
if (microsec_to_pico != 0)
170+
{
171+
/* Normal case. */
172+
idle_timer= TIMER_NAME_MICROSEC;
173+
}
174+
else if (millisec_to_pico != 0)
175+
{
176+
/* Robustness, no known cases. */
177+
idle_timer= TIMER_NAME_MILLISEC;
178+
}
179+
else if (tick_to_pico != 0)
180+
{
181+
/* Robustness, no known cases. */
182+
idle_timer= TIMER_NAME_TICK;
183+
}
184+
else
185+
{
186+
/* Robustness, no known cases. */
187+
idle_timer= TIMER_NAME_CYCLE;
188+
}
120189
}
121190

122191
ulonglong get_timer_raw_value(enum_timer_name timer_name)

0 commit comments

Comments
 (0)