This commit is contained in:
Sergei Golubchik 2016-07-28 15:52:12 +02:00
commit 15f60c1a73
976 changed files with 148317 additions and 35653 deletions

View file

@ -27,21 +27,13 @@
#include "pfs_host.h"
#include "pfs_global.h"
#include "pfs_instr_class.h"
#include "pfs_buffer_container.h"
/**
@addtogroup Performance_schema_buffers
@{
*/
ulong host_max;
ulong host_lost;
PFS_host *host_array= NULL;
static PFS_single_stat *host_instr_class_waits_array= NULL;
static PFS_stage_stat *host_instr_class_stages_array= NULL;
static PFS_statement_stat *host_instr_class_statements_array= NULL;
LF_HASH host_hash;
static bool host_hash_inited= false;
@ -52,59 +44,8 @@ static bool host_hash_inited= false;
*/
int init_host(const PFS_global_param *param)
{
uint index;
host_max= param->m_host_sizing;
host_array= NULL;
host_instr_class_waits_array= NULL;
host_instr_class_stages_array= NULL;
host_instr_class_statements_array= NULL;
uint waits_sizing= host_max * wait_class_max;
uint stages_sizing= host_max * stage_class_max;
uint statements_sizing= host_max * statement_class_max;
if (host_max > 0)
{
host_array= PFS_MALLOC_ARRAY(host_max, sizeof(PFS_host), PFS_host,
MYF(MY_ZEROFILL));
if (unlikely(host_array == NULL))
return 1;
}
if (waits_sizing > 0)
{
host_instr_class_waits_array=
PFS_connection_slice::alloc_waits_slice(waits_sizing);
if (unlikely(host_instr_class_waits_array == NULL))
return 1;
}
if (stages_sizing > 0)
{
host_instr_class_stages_array=
PFS_connection_slice::alloc_stages_slice(stages_sizing);
if (unlikely(host_instr_class_stages_array == NULL))
return 1;
}
if (statements_sizing > 0)
{
host_instr_class_statements_array=
PFS_connection_slice::alloc_statements_slice(statements_sizing);
if (unlikely(host_instr_class_statements_array == NULL))
return 1;
}
for (index= 0; index < host_max; index++)
{
host_array[index].m_instr_class_waits_stats=
&host_instr_class_waits_array[index * wait_class_max];
host_array[index].m_instr_class_stages_stats=
&host_instr_class_stages_array[index * stage_class_max];
host_array[index].m_instr_class_statements_stats=
&host_instr_class_statements_array[index * statement_class_max];
}
if (global_host_container.init(param->m_host_sizing))
return 1;
return 0;
}
@ -112,15 +53,7 @@ int init_host(const PFS_global_param *param)
/** Cleanup all the host buffers. */
void cleanup_host(void)
{
pfs_free(host_array);
host_array= NULL;
pfs_free(host_instr_class_waits_array);
host_instr_class_waits_array= NULL;
pfs_free(host_instr_class_stages_array);
host_instr_class_stages_array= NULL;
pfs_free(host_instr_class_statements_array);
host_instr_class_statements_array= NULL;
host_max= 0;
global_host_container.cleanup();
}
C_MODE_START
@ -144,13 +77,12 @@ C_MODE_END
Initialize the host hash.
@return 0 on success
*/
int init_host_hash(void)
int init_host_hash(const PFS_global_param *param)
{
if ((! host_hash_inited) && (host_max > 0))
if ((! host_hash_inited) && (param->m_host_sizing != 0))
{
lf_hash_init(&host_hash, sizeof(PFS_host*), LF_HASH_UNIQUE,
0, 0, host_hash_get_key, &my_charset_bin);
host_hash.size= host_max;
host_hash_inited= true;
}
return 0;
@ -196,16 +128,12 @@ static void set_host_key(PFS_host_key *key,
PFS_host *find_or_create_host(PFS_thread *thread,
const char *hostname, uint hostname_length)
{
if (host_max == 0)
{
host_lost++;
return NULL;
}
static PFS_ALIGNED PFS_cacheline_uint32 monotonic;
LF_PINS *pins= get_host_hash_pins(thread);
if (unlikely(pins == NULL))
{
host_lost++;
global_host_container.m_lost++;
return NULL;
}
@ -213,8 +141,10 @@ PFS_host *find_or_create_host(PFS_thread *thread,
set_host_key(&key, hostname, hostname_length);
PFS_host **entry;
PFS_host *pfs;
uint retry_count= 0;
const uint retry_max= 3;
pfs_dirty_state dirty_state;
search:
entry= reinterpret_cast<PFS_host**>
@ -231,68 +161,55 @@ search:
lf_hash_search_unpin(pins);
PFS_scan scan;
uint random= randomized_index(hostname, host_max);
for (scan.init(random, host_max);
scan.has_pass();
scan.next_pass())
pfs= global_host_container.allocate(& dirty_state);
if (pfs != NULL)
{
PFS_host *pfs= host_array + scan.first();
PFS_host *pfs_last= host_array + scan.last();
for ( ; pfs < pfs_last; pfs++)
pfs->m_key= key;
if (hostname_length > 0)
pfs->m_hostname= &pfs->m_key.m_hash_key[0];
else
pfs->m_hostname= NULL;
pfs->m_hostname_length= hostname_length;
pfs->init_refcount();
pfs->reset_stats();
pfs->m_disconnected_count= 0;
int res;
pfs->m_lock.dirty_to_allocated(& dirty_state);
res= lf_hash_insert(&host_hash, pins, &pfs);
if (likely(res == 0))
{
if (pfs->m_lock.is_free())
{
if (pfs->m_lock.free_to_dirty())
{
pfs->m_key= key;
if (hostname_length > 0)
pfs->m_hostname= &pfs->m_key.m_hash_key[0];
else
pfs->m_hostname= NULL;
pfs->m_hostname_length= hostname_length;
pfs->init_refcount();
pfs->reset_stats();
pfs->m_disconnected_count= 0;
int res;
res= lf_hash_insert(&host_hash, pins, &pfs);
if (likely(res == 0))
{
pfs->m_lock.dirty_to_allocated();
return pfs;
}
pfs->m_lock.dirty_to_free();
if (res > 0)
{
if (++retry_count > retry_max)
{
host_lost++;
return NULL;
}
goto search;
}
host_lost++;
return NULL;
}
}
return pfs;
}
global_host_container.deallocate(pfs);
if (res > 0)
{
if (++retry_count > retry_max)
{
global_host_container.m_lost++;
return NULL;
}
goto search;
}
global_host_container.m_lost++;
return NULL;
}
host_lost++;
return NULL;
}
void PFS_host::aggregate()
void PFS_host::aggregate(bool alive)
{
aggregate_waits();
aggregate_stages();
aggregate_statements();
aggregate_transactions();
aggregate_memory(alive);
aggregate_status();
aggregate_stats();
}
@ -304,24 +221,67 @@ void PFS_host::aggregate_waits()
void PFS_host::aggregate_stages()
{
if (read_instr_class_stages_stats() == NULL)
return;
/*
Aggregate EVENTS_STAGES_SUMMARY_BY_HOST_BY_EVENT_NAME to:
- EVENTS_STAGES_SUMMARY_GLOBAL_BY_EVENT_NAME
*/
aggregate_all_stages(m_instr_class_stages_stats,
aggregate_all_stages(write_instr_class_stages_stats(),
global_instr_class_stages_array);
}
void PFS_host::aggregate_statements()
{
if (read_instr_class_statements_stats() == NULL)
return;
/*
Aggregate EVENTS_STATEMENTS_SUMMARY_BY_HOST_BY_EVENT_NAME to:
- EVENTS_STATEMENTS_SUMMARY_GLOBAL_BY_EVENT_NAME
*/
aggregate_all_statements(m_instr_class_statements_stats,
aggregate_all_statements(write_instr_class_statements_stats(),
global_instr_class_statements_array);
}
void PFS_host::aggregate_transactions()
{
if (read_instr_class_transactions_stats() == NULL)
return;
/*
Aggregate EVENTS_TRANSACTIONS_SUMMARY_BY_HOST_BY_EVENT_NAME to:
- EVENTS_TRANSACTIONS_SUMMARY_GLOBAL_BY_EVENT_NAME
*/
aggregate_all_transactions(write_instr_class_transactions_stats(),
&global_transaction_stat);
}
void PFS_host::aggregate_memory(bool alive)
{
if (read_instr_class_memory_stats() == NULL)
return;
/*
Aggregate MEMORY_SUMMARY_BY_HOST_BY_EVENT_NAME to:
- MEMORY_SUMMARY_GLOBAL_BY_EVENT_NAME
*/
aggregate_all_memory(alive,
write_instr_class_memory_stats(),
global_instr_class_memory_array);
}
void PFS_host::aggregate_status()
{
/*
Aggregate STATUS_BY_HOST to:
- GLOBAL_STATUS
*/
m_status_stats.aggregate_to(& global_status_var);
m_status_stats.reset();
}
void PFS_host::aggregate_stats()
{
/* No parent to aggregate to, clean the stats */
@ -333,12 +293,24 @@ void PFS_host::release()
dec_refcount();
}
void PFS_host::carry_memory_stat_delta(PFS_memory_stat_delta *delta, uint index)
{
PFS_memory_stat *event_name_array;
PFS_memory_stat *stat;
PFS_memory_stat_delta delta_buffer;
PFS_memory_stat_delta *remaining_delta;
event_name_array= write_instr_class_memory_stats();
stat= & event_name_array[index];
remaining_delta= stat->apply_delta(delta, &delta_buffer);
if (remaining_delta != NULL)
carry_global_memory_stat_delta(remaining_delta, index);
}
PFS_host *sanitize_host(PFS_host *unsafe)
{
if ((&host_array[0] <= unsafe) &&
(unsafe < &host_array[host_max]))
return unsafe;
return NULL;
return global_host_container.sanitize(unsafe);
}
void purge_host(PFS_thread *thread, PFS_host *host)
@ -358,13 +330,33 @@ void purge_host(PFS_thread *thread, PFS_host *host)
{
lf_hash_delete(&host_hash, pins,
host->m_key.m_hash_key, host->m_key.m_key_length);
host->m_lock.allocated_to_free();
host->aggregate(false);
global_host_container.deallocate(host);
}
}
lf_hash_search_unpin(pins);
}
class Proc_purge_host
: public PFS_buffer_processor<PFS_host>
{
public:
Proc_purge_host(PFS_thread *thread)
: m_thread(thread)
{}
virtual void operator()(PFS_host *pfs)
{
pfs->aggregate(true);
if (pfs->get_refcount() == 0)
purge_host(m_thread, pfs);
}
private:
PFS_thread *m_thread;
};
/** Purge non connected hosts, reset stats of connected hosts. */
void purge_all_host(void)
{
@ -372,18 +364,8 @@ void purge_all_host(void)
if (unlikely(thread == NULL))
return;
PFS_host *pfs= host_array;
PFS_host *pfs_last= host_array + host_max;
for ( ; pfs < pfs_last; pfs++)
{
if (pfs->m_lock.is_populated())
{
pfs->aggregate();
if (pfs->get_refcount() == 0)
purge_host(thread, pfs);
}
}
Proc_purge_host proc(thread);
global_host_container.apply(proc);
}
/** @} */