Exclude queries executed by background threads from statistic reports.

This commit is contained in:
Alexey Kopytov
2017-02-02 15:25:54 +03:00
parent 40c14789aa
commit d156b9b21f
4 changed files with 50 additions and 12 deletions

View File

@ -192,10 +192,8 @@ static void db_init(void)
/* Initialize timers if in debug mode */
if (db_globals.debug)
{
exec_timers = (sb_timer_t *) malloc(sb_globals.threads *
sizeof(sb_timer_t));
fetch_timers = (sb_timer_t *) malloc(sb_globals.threads *
sizeof(sb_timer_t));
exec_timers = sb_alloc_per_thread_array(sizeof(sb_timer_t));
fetch_timers = sb_alloc_per_thread_array(sizeof(sb_timer_t));
}
db_reset_stats();

View File

@ -34,10 +34,7 @@ int sb_counters_init(void)
{
SB_COMPILE_TIME_ASSERT(sizeof(sb_counters_t) % CK_MD_CACHELINE == 0);
sb_counters = sb_memalign(sb_globals.threads * sizeof(sb_counters_t),
CK_MD_CACHELINE);
memset(sb_counters, 0, sb_globals.threads * sizeof(sb_counters_t));
sb_counters = sb_alloc_per_thread_array(sizeof(sb_counters_t));
return sb_counters == NULL;
}

View File

@ -85,6 +85,12 @@
/* Wait at most this number of seconds for worker threads to initialize */
#define THREAD_INIT_TIMEOUT 30
/*
Extra thread ID assigned to background threads. This may be used as an index
into per-thread arrays (see comment in sb_alloc_per_thread_array().
*/
#define SB_BACKGROUND_THREAD_ID sb_globals.threads
/* General options */
sb_arg_t general_args[] =
{
@ -892,6 +898,8 @@ static void *eventgen_thread_proc(void *arg)
(void)arg; /* unused */
sb_tls_thread_id = SB_BACKGROUND_THREAD_ID;
/* Initialize thread-local RNG state */
sb_rand_thread_init();
@ -959,6 +967,8 @@ static void *report_thread_proc(void *arg)
(void)arg; /* unused */
sb_tls_thread_id = SB_BACKGROUND_THREAD_ID;
/* Initialize thread-local RNG state */
sb_rand_thread_init();
@ -1007,6 +1017,8 @@ static void *checkpoints_thread_proc(void *arg)
(void)arg; /* unused */
sb_tls_thread_id = SB_BACKGROUND_THREAD_ID;
/* Initialize thread-local RNG state */
sb_rand_thread_init();
@ -1392,10 +1404,9 @@ static int init(void)
}
/* Initialize timers */
timers = sb_memalign(sb_globals.threads * sizeof(sb_timer_t),
CK_MD_CACHELINE);
timers_copy = sb_memalign(sb_globals.threads * sizeof(sb_timer_t),
CK_MD_CACHELINE);
timers = sb_alloc_per_thread_array(sizeof(sb_timer_t));
timers_copy = sb_alloc_per_thread_array(sizeof(sb_timer_t));
if (timers == NULL || timers_copy == NULL)
{
log_text(LOG_FATAL, "Memory allocation failure");
@ -1604,3 +1615,29 @@ void sb_print_test_options(void)
if (current_test != NULL)
sb_print_options(current_test->args);
}
/*
Allocate an array of objects of the specified size for all threads, both
worker and background ones.
*/
void *sb_alloc_per_thread_array(size_t size)
{
/*
We want to exclude queries executed by background threads from statistics
generated for worker threads.
To simplify code, we allocate all timers and counters for all worker threads
+ possible background threads created by sysbench for statistic reports,
etc. When executing requests from background threads, extra array slots will
be used (it depends on the assigned ID for each thread). When aggregating
counters and timers, we only consider slots in the range [0,
sb_globals.threads - 1], i.e. ignore statistics generated by background
threads. Currently we assign the same single thread ID for all background
threads, so they also share the same single slot in each allocated array.
*/
void *ptr = sb_memalign((sb_globals.threads + 1) * size, CK_MD_CACHELINE);
memset(ptr, 0, size);
return ptr;
}

View File

@ -232,4 +232,10 @@ void sb_report_intermediate(sb_stat_t *stat);
/* Default cumulative reports handler */
void sb_report_cumulative(sb_stat_t *stat);
/*
Allocate an array of objects of the specified size for all threads, both
worker and background ones.
*/
void *sb_alloc_per_thread_array(size_t size);
#endif