summaryrefslogtreecommitdiff
path: root/storage/perfschema/table_events_stages.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/perfschema/table_events_stages.cc')
-rw-r--r--storage/perfschema/table_events_stages.cc212
1 files changed, 122 insertions, 90 deletions
diff --git a/storage/perfschema/table_events_stages.cc b/storage/perfschema/table_events_stages.cc
index 95e7f187d24..cd6c79df36c 100644
--- a/storage/perfschema/table_events_stages.cc
+++ b/storage/perfschema/table_events_stages.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2010, 2018, 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, version 2.0,
@@ -26,12 +26,14 @@
*/
#include "my_global.h"
-#include "my_pthread.h"
+#include "my_thread.h"
#include "table_events_stages.h"
#include "pfs_instr_class.h"
#include "pfs_instr.h"
#include "pfs_events_stages.h"
#include "pfs_timer.h"
+#include "pfs_buffer_container.h"
+#include "field.h"
THR_LOCK table_events_stages_current::m_table_lock;
@@ -40,11 +42,10 @@ table_events_stages_current::m_share=
{
{ C_STRING_WITH_LEN("events_stages_current") },
&pfs_truncatable_acl,
- &table_events_stages_current::create,
+ table_events_stages_current::create,
NULL, /* write_row */
- &table_events_stages_current::delete_all_rows,
- NULL, /* get_row_count */
- 1000, /* records */
+ table_events_stages_current::delete_all_rows,
+ table_events_stages_current::get_row_count,
sizeof(PFS_simple_index), /* ref length */
&m_table_lock,
{ C_STRING_WITH_LEN("CREATE TABLE events_stages_current("
@@ -56,8 +57,11 @@ table_events_stages_current::m_share=
"TIMER_START BIGINT unsigned,"
"TIMER_END BIGINT unsigned,"
"TIMER_WAIT BIGINT unsigned,"
+ "WORK_COMPLETED BIGINT unsigned,"
+ "WORK_ESTIMATED BIGINT unsigned,"
"NESTING_EVENT_ID BIGINT unsigned,"
- "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT'))") }
+ "NESTING_EVENT_TYPE ENUM('TRANSACTION', 'STATEMENT', 'STAGE', 'WAIT'))") },
+ false /* perpetual */
};
THR_LOCK table_events_stages_history::m_table_lock;
@@ -67,11 +71,10 @@ table_events_stages_history::m_share=
{
{ C_STRING_WITH_LEN("events_stages_history") },
&pfs_truncatable_acl,
- &table_events_stages_history::create,
+ table_events_stages_history::create,
NULL, /* write_row */
- &table_events_stages_history::delete_all_rows,
- NULL, /* get_row_count */
- 1000, /* records */
+ table_events_stages_history::delete_all_rows,
+ table_events_stages_history::get_row_count,
sizeof(pos_events_stages_history), /* ref length */
&m_table_lock,
{ C_STRING_WITH_LEN("CREATE TABLE events_stages_history("
@@ -83,8 +86,11 @@ table_events_stages_history::m_share=
"TIMER_START BIGINT unsigned,"
"TIMER_END BIGINT unsigned,"
"TIMER_WAIT BIGINT unsigned,"
+ "WORK_COMPLETED BIGINT unsigned,"
+ "WORK_ESTIMATED BIGINT unsigned,"
"NESTING_EVENT_ID BIGINT unsigned,"
- "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT'))") }
+ "NESTING_EVENT_TYPE ENUM('TRANSACTION', 'STATEMENT', 'STAGE', 'WAIT'))") },
+ false /* perpetual */
};
THR_LOCK table_events_stages_history_long::m_table_lock;
@@ -94,11 +100,10 @@ table_events_stages_history_long::m_share=
{
{ C_STRING_WITH_LEN("events_stages_history_long") },
&pfs_truncatable_acl,
- &table_events_stages_history_long::create,
+ table_events_stages_history_long::create,
NULL, /* write_row */
- &table_events_stages_history_long::delete_all_rows,
- NULL, /* get_row_count */
- 10000, /* records */
+ table_events_stages_history_long::delete_all_rows,
+ table_events_stages_history_long::get_row_count,
sizeof(PFS_simple_index), /* ref length */
&m_table_lock,
{ C_STRING_WITH_LEN("CREATE TABLE events_stages_history_long("
@@ -110,8 +115,11 @@ table_events_stages_history_long::m_share=
"TIMER_START BIGINT unsigned,"
"TIMER_END BIGINT unsigned,"
"TIMER_WAIT BIGINT unsigned,"
+ "WORK_COMPLETED BIGINT unsigned,"
+ "WORK_ESTIMATED BIGINT unsigned,"
"NESTING_EVENT_ID BIGINT unsigned,"
- "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT'))") }
+ "NESTING_EVENT_TYPE ENUM('TRANSACTION', 'STATEMENT', 'STAGE', 'WAIT'))") },
+ false /* perpetual */
};
table_events_stages_common::table_events_stages_common
@@ -126,8 +134,6 @@ table_events_stages_common::table_events_stages_common
*/
void table_events_stages_common::make_row(PFS_events_stages *stage)
{
- const char *base;
- const char *safe_source_file;
ulonglong timer_end;
m_row_exists= false;
@@ -158,15 +164,19 @@ void table_events_stages_common::make_row(PFS_events_stages *stage)
m_row.m_name= klass->m_name;
m_row.m_name_length= klass->m_name_length;
- safe_source_file= stage->m_source_file;
- if (unlikely(safe_source_file == NULL))
- return;
+ /* Disable source file and line to avoid stale __FILE__ pointers. */
+ m_row.m_source_length= 0;
- base= base_name(safe_source_file);
- m_row.m_source_length= (uint)my_snprintf(m_row.m_source, sizeof(m_row.m_source),
- "%s:%d", base, stage->m_source_line);
- if (m_row.m_source_length > sizeof(m_row.m_source))
- m_row.m_source_length= sizeof(m_row.m_source);
+ if (klass->is_progress())
+ {
+ m_row.m_progress= true;
+ m_row.m_work_completed= stage->m_progress.m_work_completed;
+ m_row.m_work_estimated= stage->m_progress.m_work_estimated;
+ }
+ else
+ {
+ m_row.m_progress= false;
+ }
m_row_exists= true;
return;
@@ -183,8 +193,9 @@ int table_events_stages_common::read_row_values(TABLE *table,
return HA_ERR_RECORD_DELETED;
/* Set the null bits */
- DBUG_ASSERT(table->s->null_bytes == 1);
+ DBUG_ASSERT(table->s->null_bytes == 2);
buf[0]= 0;
+ buf[1]= 0;
for (; (f= *fields) ; fields++)
{
@@ -228,13 +239,25 @@ int table_events_stages_common::read_row_values(TABLE *table,
else
f->set_null();
break;
- case 8: /* NESTING_EVENT_ID */
+ case 8: /* WORK_COMPLETED */
+ if (m_row.m_progress)
+ set_field_ulonglong(f, m_row.m_work_completed);
+ else
+ f->set_null();
+ break;
+ case 9: /* WORK_ESTIMATED */
+ if (m_row.m_progress)
+ set_field_ulonglong(f, m_row.m_work_estimated);
+ else
+ f->set_null();
+ break;
+ case 10: /* NESTING_EVENT_ID */
if (m_row.m_nesting_event_id != 0)
set_field_ulonglong(f, m_row.m_nesting_event_id);
else
f->set_null();
break;
- case 9: /* NESTING_EVENT_TYPE */
+ case 11: /* NESTING_EVENT_TYPE */
if (m_row.m_nesting_event_id != 0)
set_field_enum(f, m_row.m_nesting_event_type);
else
@@ -275,20 +298,12 @@ int table_events_stages_current::rnd_next(void)
PFS_thread *pfs_thread;
PFS_events_stages *stage;
- for (m_pos.set_at(&m_next_pos);
- m_pos.m_index < thread_max;
- m_pos.next())
+ m_pos.set_at(&m_next_pos);
+ PFS_thread_iterator it= global_thread_container.iterate(m_pos.m_index);
+ pfs_thread= it.scan_next(& m_pos.m_index);
+ if (pfs_thread != NULL)
{
- pfs_thread= &thread_array[m_pos.m_index];
-
- if (! pfs_thread->m_lock.is_populated())
- {
- /* This thread does not exist */
- continue;
- }
-
stage= &pfs_thread->m_stage_current;
-
make_row(stage);
m_next_pos.set_after(&m_pos);
return 0;
@@ -303,15 +318,16 @@ int table_events_stages_current::rnd_pos(const void *pos)
PFS_events_stages *stage;
set_position(pos);
- DBUG_ASSERT(m_pos.m_index < thread_max);
- pfs_thread= &thread_array[m_pos.m_index];
- if (! pfs_thread->m_lock.is_populated())
- return HA_ERR_RECORD_DELETED;
+ pfs_thread= global_thread_container.get(m_pos.m_index);
+ if (pfs_thread != NULL)
+ {
+ stage= &pfs_thread->m_stage_current;
+ make_row(stage);
+ return 0;
+ }
- stage= &pfs_thread->m_stage_current;
- make_row(stage);
- return 0;
+ return HA_ERR_RECORD_DELETED;
}
int table_events_stages_current::delete_all_rows(void)
@@ -320,6 +336,12 @@ int table_events_stages_current::delete_all_rows(void)
return 0;
}
+ha_rows
+table_events_stages_current::get_row_count(void)
+{
+ return global_thread_container.get_row_count();
+}
+
PFS_engine_table* table_events_stages_history::create(void)
{
return new table_events_stages_history();
@@ -346,43 +368,40 @@ int table_events_stages_history::rnd_next(void)
{
PFS_thread *pfs_thread;
PFS_events_stages *stage;
+ bool has_more_thread= true;
if (events_stages_history_per_thread == 0)
return HA_ERR_END_OF_FILE;
for (m_pos.set_at(&m_next_pos);
- m_pos.m_index_1 < thread_max;
+ has_more_thread;
m_pos.next_thread())
{
- pfs_thread= &thread_array[m_pos.m_index_1];
-
- if (! pfs_thread->m_lock.is_populated())
- {
- /* This thread does not exist */
- continue;
- }
-
- if (m_pos.m_index_2 >= events_stages_history_per_thread)
+ pfs_thread= global_thread_container.get(m_pos.m_index_1, & has_more_thread);
+ if (pfs_thread != NULL)
{
- /* This thread does not have more (full) history */
- continue;
- }
+ if (m_pos.m_index_2 >= events_stages_history_per_thread)
+ {
+ /* This thread does not have more (full) history */
+ continue;
+ }
- if ( ! pfs_thread->m_stages_history_full &&
- (m_pos.m_index_2 >= pfs_thread->m_stages_history_index))
- {
- /* This thread does not have more (not full) history */
- continue;
- }
+ if ( ! pfs_thread->m_stages_history_full &&
+ (m_pos.m_index_2 >= pfs_thread->m_stages_history_index))
+ {
+ /* This thread does not have more (not full) history */
+ continue;
+ }
- stage= &pfs_thread->m_stages_history[m_pos.m_index_2];
+ stage= &pfs_thread->m_stages_history[m_pos.m_index_2];
- if (stage->m_class != NULL)
- {
- make_row(stage);
- /* Next iteration, look for the next history in this thread */
- m_next_pos.set_after(&m_pos);
- return 0;
+ if (stage->m_class != NULL)
+ {
+ make_row(stage);
+ /* Next iteration, look for the next history in this thread */
+ m_next_pos.set_after(&m_pos);
+ return 0;
+ }
}
}
@@ -396,25 +415,26 @@ int table_events_stages_history::rnd_pos(const void *pos)
DBUG_ASSERT(events_stages_history_per_thread != 0);
set_position(pos);
- DBUG_ASSERT(m_pos.m_index_1 < thread_max);
- pfs_thread= &thread_array[m_pos.m_index_1];
-
- if (! pfs_thread->m_lock.is_populated())
- return HA_ERR_RECORD_DELETED;
DBUG_ASSERT(m_pos.m_index_2 < events_stages_history_per_thread);
- if ( ! pfs_thread->m_stages_history_full &&
- (m_pos.m_index_2 >= pfs_thread->m_stages_history_index))
- return HA_ERR_RECORD_DELETED;
+ pfs_thread= global_thread_container.get(m_pos.m_index_1);
+ if (pfs_thread != NULL)
+ {
+ if ( ! pfs_thread->m_stages_history_full &&
+ (m_pos.m_index_2 >= pfs_thread->m_stages_history_index))
+ return HA_ERR_RECORD_DELETED;
- stage= &pfs_thread->m_stages_history[m_pos.m_index_2];
+ stage= &pfs_thread->m_stages_history[m_pos.m_index_2];
- if (stage->m_class == NULL)
- return HA_ERR_RECORD_DELETED;
+ if (stage->m_class != NULL)
+ {
+ make_row(stage);
+ return 0;
+ }
+ }
- make_row(stage);
- return 0;
+ return HA_ERR_RECORD_DELETED;
}
int table_events_stages_history::delete_all_rows(void)
@@ -423,6 +443,12 @@ int table_events_stages_history::delete_all_rows(void)
return 0;
}
+ha_rows
+table_events_stages_history::get_row_count(void)
+{
+ return events_stages_history_per_thread * global_thread_container.get_row_count();
+}
+
PFS_engine_table* table_events_stages_history_long::create(void)
{
return new table_events_stages_history_long();
@@ -456,7 +482,7 @@ int table_events_stages_history_long::rnd_next(void)
if (events_stages_history_long_full)
limit= events_stages_history_long_size;
else
- limit= events_stages_history_long_index % events_stages_history_long_size;
+ limit= events_stages_history_long_index.m_u32 % events_stages_history_long_size;
for (m_pos.set_at(&m_next_pos); m_pos.m_index < limit; m_pos.next())
{
@@ -487,7 +513,7 @@ int table_events_stages_history_long::rnd_pos(const void *pos)
if (events_stages_history_long_full)
limit= events_stages_history_long_size;
else
- limit= events_stages_history_long_index % events_stages_history_long_size;
+ limit= events_stages_history_long_index.m_u32 % events_stages_history_long_size;
if (m_pos.m_index > limit)
return HA_ERR_RECORD_DELETED;
@@ -507,3 +533,9 @@ int table_events_stages_history_long::delete_all_rows(void)
return 0;
}
+ha_rows
+table_events_stages_history_long::get_row_count(void)
+{
+ return events_stages_history_long_size;
+}
+