diff options
author | Alexander Barkov <bar@mariadb.org> | 2014-08-11 05:45:45 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2014-08-11 05:45:45 +0400 |
commit | 22a64047d14d1199ced885f63bcccd39459681d6 (patch) | |
tree | 8087b8b89fe8602f43355f88ce91c8ce1e34b55b /mysys | |
parent | 4105cbf4a230c82ea7dee31d4d2262b798fad9f4 (diff) | |
download | mariadb-git-22a64047d14d1199ced885f63bcccd39459681d6.tar.gz |
MDEV-6274 Collation usage statistics
Adding collation usage statistics into the feedback plugin I_S table.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/charset.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/mysys/charset.c b/mysys/charset.c index b7e535136a5..ad3eb78ae0e 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -483,6 +483,50 @@ void add_compiled_collation(struct charset_info_st *cs) static my_pthread_once_t charsets_initialized= MY_PTHREAD_ONCE_INIT; static my_pthread_once_t charsets_template= MY_PTHREAD_ONCE_INIT; +typedef struct +{ + ulonglong use_count; +} MY_COLLATION_STATISTICS; + + +static MY_COLLATION_STATISTICS my_collation_statistics[MY_ALL_CHARSETS_SIZE]; + + +my_bool my_collation_is_known_id(uint id) +{ + return id > 0 && id < array_elements(all_charsets) && all_charsets[id] ? + TRUE : FALSE; +} + + +/* + Collation use statistics functions do not lock + counters to avoid mutex contention. This can lose + some counter increments with high thread concurrency. + But this should be Ok, as we don't need exact numbers. +*/ +static inline void my_collation_statistics_inc_use_count(uint id) +{ + DBUG_ASSERT(my_collation_is_known_id(id)); + my_collation_statistics[id].use_count++; +} + + +ulonglong my_collation_statistics_get_use_count(uint id) +{ + DBUG_ASSERT(my_collation_is_known_id(id)); + return my_collation_statistics[id].use_count; +} + + +const char *my_collation_get_tailoring(uint id) +{ + /* all_charsets[id]->tailoring is never changed after server startup. */ + DBUG_ASSERT(my_collation_is_known_id(id)); + return all_charsets[id]->tailoring; +} + + static void init_available_charsets(void) { char fname[FN_REFLEN + sizeof(MY_CHARSET_INDEX)]; @@ -490,6 +534,7 @@ static void init_available_charsets(void) MY_CHARSET_LOADER loader; bzero((char*) &all_charsets,sizeof(all_charsets)); + bzero((char*) &my_collation_statistics, sizeof(my_collation_statistics)); init_compiled_charsets(MYF(0)); /* Copy compiled charsets */ @@ -608,7 +653,10 @@ get_internal_charset(MY_CHARSET_LOADER *loader, uint cs_number, myf flags) if ((cs= (struct charset_info_st*) all_charsets[cs_number])) { if (cs->state & MY_CS_READY) /* if CS is already initialized */ - return cs; + { + my_collation_statistics_inc_use_count(cs_number); + return cs; + } /* To make things thread safe we are not allowing other threads to interfere @@ -636,6 +684,7 @@ get_internal_charset(MY_CHARSET_LOADER *loader, uint cs_number, myf flags) else cs->state|= MY_CS_READY; } + my_collation_statistics_inc_use_count(cs_number); } else cs= NULL; |