Commit f84adb9e authored by Christopher Powers's avatar Christopher Powers

Bug# 53874 "SETUP_INSTRUMENTS.TIMED='NO' should not change TIMER_WAIT

Handle combined instrument states of ENABLED and/or TIMED:

ENABLED TIMED
1 1 Aggregate stats, increment counter
1 0 Increment counter
0 1 Do nothing
0 0 Do nothing 
parent 81cdce4d
...@@ -1625,19 +1625,27 @@ static void end_mutex_wait_v1(PSI_mutex_locker* locker, int rc) ...@@ -1625,19 +1625,27 @@ static void end_mutex_wait_v1(PSI_mutex_locker* locker, int rc)
if (flag_events_waits_history_long) if (flag_events_waits_history_long)
insert_events_waits_history_long(wait); insert_events_waits_history_long(wait);
if (rc == 0 && wait->m_timer_state == TIMER_STATE_TIMED) if (rc == 0)
{ {
/* Thread safe: we are protected by the instrumented mutex */ /* Thread safe: we are protected by the instrumented mutex */
PFS_single_stat_chain *stat;
PFS_mutex *mutex= pfs_locker->m_target.m_mutex; PFS_mutex *mutex= pfs_locker->m_target.m_mutex;
PFS_single_stat_chain *stat= find_per_thread_mutex_class_wait_stat(wait->m_thread, mutex->m_class);
mutex->m_owner= wait->m_thread; mutex->m_owner= wait->m_thread;
mutex->m_last_locked= wait->m_timer_end; mutex->m_last_locked= wait->m_timer_end;
/* If timed then aggregate stats, else increment the value counts only */
if (wait->m_timer_state == TIMER_STATE_TIMED)
{
ulonglong wait_time= wait->m_timer_end - wait->m_timer_start; ulonglong wait_time= wait->m_timer_end - wait->m_timer_start;
aggregate_single_stat_chain(&mutex->m_wait_stat, wait_time); aggregate_single_stat_chain(&mutex->m_wait_stat, wait_time);
stat= find_per_thread_mutex_class_wait_stat(wait->m_thread, mutex->m_class);
aggregate_single_stat_chain(stat, wait_time); aggregate_single_stat_chain(stat, wait_time);
} }
else
{
increment_single_stat_chain(&mutex->m_wait_stat);
increment_single_stat_chain(stat);
}
}
wait->m_thread->m_wait_locker_count--; wait->m_thread->m_wait_locker_count--;
} }
...@@ -1682,20 +1690,26 @@ static void end_rwlock_rdwait_v1(PSI_rwlock_locker* locker, int rc) ...@@ -1682,20 +1690,26 @@ static void end_rwlock_rdwait_v1(PSI_rwlock_locker* locker, int rc)
The statistics generated are not safe, which is why they are The statistics generated are not safe, which is why they are
just statistics, not facts. just statistics, not facts.
*/ */
PFS_single_stat_chain *stat;
PFS_rwlock *rwlock= pfs_locker->m_target.m_rwlock; PFS_rwlock *rwlock= pfs_locker->m_target.m_rwlock;
PFS_single_stat_chain *stat= find_per_thread_rwlock_class_wait_stat(wait->m_thread, rwlock->m_class);
if (rwlock->m_readers == 0) if (rwlock->m_readers == 0)
rwlock->m_last_read= wait->m_timer_end; rwlock->m_last_read= wait->m_timer_end;
rwlock->m_writer= NULL; rwlock->m_writer= NULL;
rwlock->m_readers++; rwlock->m_readers++;
/* If timed then aggregate stats, else increment the value counts only */
if (wait->m_timer_state == TIMER_STATE_TIMED) if (wait->m_timer_state == TIMER_STATE_TIMED)
{ {
ulonglong wait_time= wait->m_timer_end - wait->m_timer_start; ulonglong wait_time= wait->m_timer_end - wait->m_timer_start;
aggregate_single_stat_chain(&rwlock->m_wait_stat, wait_time); aggregate_single_stat_chain(&rwlock->m_wait_stat, wait_time);
stat= find_per_thread_rwlock_class_wait_stat(wait->m_thread, rwlock->m_class);
aggregate_single_stat_chain(stat, wait_time); aggregate_single_stat_chain(stat, wait_time);
} }
else
{
increment_single_stat_chain(&rwlock->m_wait_stat);
increment_single_stat_chain(stat);
}
} }
wait->m_thread->m_wait_locker_count--; wait->m_thread->m_wait_locker_count--;
} }
...@@ -1735,21 +1749,26 @@ static void end_rwlock_wrwait_v1(PSI_rwlock_locker* locker, int rc) ...@@ -1735,21 +1749,26 @@ static void end_rwlock_wrwait_v1(PSI_rwlock_locker* locker, int rc)
if (rc == 0) if (rc == 0)
{ {
/* Thread safe : we are protected by the instrumented rwlock */ /* Thread safe : we are protected by the instrumented rwlock */
PFS_single_stat_chain *stat;
PFS_rwlock *rwlock= pfs_locker->m_target.m_rwlock; PFS_rwlock *rwlock= pfs_locker->m_target.m_rwlock;
PFS_single_stat_chain *stat= find_per_thread_rwlock_class_wait_stat(wait->m_thread, rwlock->m_class);
rwlock->m_writer= wait->m_thread; rwlock->m_writer= wait->m_thread;
rwlock->m_last_written= wait->m_timer_end; rwlock->m_last_written= wait->m_timer_end;
/* Reset the readers stats, they could be off */ /* Reset the readers stats, they could be off */
rwlock->m_readers= 0; rwlock->m_readers= 0;
rwlock->m_last_read= 0; rwlock->m_last_read= 0;
/* If timed then aggregate stats, else increment the value counts only */
if (wait->m_timer_state == TIMER_STATE_TIMED) if (wait->m_timer_state == TIMER_STATE_TIMED)
{ {
ulonglong wait_time= wait->m_timer_end - wait->m_timer_start; ulonglong wait_time= wait->m_timer_end - wait->m_timer_start;
aggregate_single_stat_chain(&rwlock->m_wait_stat, wait_time); aggregate_single_stat_chain(&rwlock->m_wait_stat, wait_time);
stat= find_per_thread_rwlock_class_wait_stat(wait->m_thread, rwlock->m_class);
aggregate_single_stat_chain(stat, wait_time); aggregate_single_stat_chain(stat, wait_time);
} }
else
{
increment_single_stat_chain(&rwlock->m_wait_stat);
increment_single_stat_chain(stat);
}
} }
wait->m_thread->m_wait_locker_count--; wait->m_thread->m_wait_locker_count--;
} }
...@@ -1803,16 +1822,21 @@ static void end_cond_wait_v1(PSI_cond_locker* locker, int rc) ...@@ -1803,16 +1822,21 @@ static void end_cond_wait_v1(PSI_cond_locker* locker, int rc)
in condition B. in condition B.
This is accepted, the data will be slightly inaccurate. This is accepted, the data will be slightly inaccurate.
*/ */
PFS_single_stat_chain *stat;
PFS_cond *cond= pfs_locker->m_target.m_cond; PFS_cond *cond= pfs_locker->m_target.m_cond;
PFS_single_stat_chain *stat= find_per_thread_cond_class_wait_stat(wait->m_thread, cond->m_class);
/* If timed then aggregate stats, else increment the value counts only */
if (wait->m_timer_state == TIMER_STATE_TIMED) if (wait->m_timer_state == TIMER_STATE_TIMED)
{ {
ulonglong wait_time= wait->m_timer_end - wait->m_timer_start; ulonglong wait_time= wait->m_timer_end - wait->m_timer_start;
aggregate_single_stat_chain(&cond->m_wait_stat, wait_time); aggregate_single_stat_chain(&cond->m_wait_stat, wait_time);
stat= find_per_thread_cond_class_wait_stat(wait->m_thread, cond->m_class);
aggregate_single_stat_chain(stat, wait_time); aggregate_single_stat_chain(stat, wait_time);
} }
else
{
increment_single_stat_chain(&cond->m_wait_stat);
increment_single_stat_chain(stat);
}
} }
wait->m_thread->m_wait_locker_count--; wait->m_thread->m_wait_locker_count--;
} }
...@@ -1855,12 +1879,18 @@ static void end_table_wait_v1(PSI_table_locker* locker) ...@@ -1855,12 +1879,18 @@ static void end_table_wait_v1(PSI_table_locker* locker)
if (flag_events_waits_history_long) if (flag_events_waits_history_long)
insert_events_waits_history_long(wait); insert_events_waits_history_long(wait);
PFS_table *table= pfs_locker->m_target.m_table;
/* If timed then aggregate stats, else increment the value counts only */
if (wait->m_timer_state == TIMER_STATE_TIMED) if (wait->m_timer_state == TIMER_STATE_TIMED)
{ {
PFS_table *table= pfs_locker->m_target.m_table;
ulonglong wait_time= wait->m_timer_end - wait->m_timer_start; ulonglong wait_time= wait->m_timer_end - wait->m_timer_start;
aggregate_single_stat_chain(&table->m_wait_stat, wait_time); aggregate_single_stat_chain(&table->m_wait_stat, wait_time);
} }
else
{
increment_single_stat_chain(&table->m_wait_stat);
}
/* /*
There is currently no per table and per thread aggregation. There is currently no per table and per thread aggregation.
...@@ -1962,14 +1992,21 @@ static void end_file_wait_v1(PSI_file_locker *locker, ...@@ -1962,14 +1992,21 @@ static void end_file_wait_v1(PSI_file_locker *locker,
if (flag_events_waits_history_long) if (flag_events_waits_history_long)
insert_events_waits_history_long(wait); insert_events_waits_history_long(wait);
PFS_single_stat_chain *stat;
PFS_file *file= pfs_locker->m_target.m_file; PFS_file *file= pfs_locker->m_target.m_file;
PFS_single_stat_chain *stat= find_per_thread_file_class_wait_stat(wait->m_thread, file->m_class);
/* If timed then aggregate stats, else increment the value counts only */
if (wait->m_timer_state == TIMER_STATE_TIMED)
{
ulonglong wait_time= wait->m_timer_end - wait->m_timer_start; ulonglong wait_time= wait->m_timer_end - wait->m_timer_start;
aggregate_single_stat_chain(&file->m_wait_stat, wait_time); aggregate_single_stat_chain(&file->m_wait_stat, wait_time);
stat= find_per_thread_file_class_wait_stat(wait->m_thread,
file->m_class);
aggregate_single_stat_chain(stat, wait_time); aggregate_single_stat_chain(stat, wait_time);
}
else
{
increment_single_stat_chain(&file->m_wait_stat);
increment_single_stat_chain(stat);
}
PFS_file_class *klass= file->m_class; PFS_file_class *klass= file->m_class;
......
...@@ -83,6 +83,22 @@ inline void aggregate_single_stat_chain(PFS_single_stat_chain *stat, ...@@ -83,6 +83,22 @@ inline void aggregate_single_stat_chain(PFS_single_stat_chain *stat,
while (stat); while (stat);
} }
/**
Increment the value counts in a statistic chain.
Used for instruments that are 'ENABLED' but not 'TIMED'.
@param stat the aggregated statistic chain
*/
inline void increment_single_stat_chain(PFS_single_stat_chain *stat)
{
do
{
if (*stat->m_control_flag)
stat->m_count++;
stat= stat->m_parent;
}
while (stat);
}
/** Statistics for COND usage. */ /** Statistics for COND usage. */
struct PFS_cond_stat struct PFS_cond_stat
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment