Commit 716f7843 authored by Sergei Golubchik's avatar Sergei Golubchik

sane implementation of Key_% status variables.

parent 7c24e8d5
...@@ -107,9 +107,6 @@ typedef ...@@ -107,9 +107,6 @@ typedef
void (*GET_KEY_CACHE_STATISTICS) void (*GET_KEY_CACHE_STATISTICS)
(void *keycache_cb, uint partition_no, (void *keycache_cb, uint partition_no,
KEY_CACHE_STATISTICS *key_cache_stats); KEY_CACHE_STATISTICS *key_cache_stats);
typedef
ulonglong (*GET_KEY_CACHE_STAT_VALUE)
(void *keycache_cb, uint var_no);
/* /*
An object of the type KEY_CACHE_FUNCS contains pointers to all functions An object of the type KEY_CACHE_FUNCS contains pointers to all functions
...@@ -134,7 +131,6 @@ typedef struct st_key_cache_funcs ...@@ -134,7 +131,6 @@ typedef struct st_key_cache_funcs
RESET_KEY_CACHE_COUNTERS reset_counters; RESET_KEY_CACHE_COUNTERS reset_counters;
END_KEY_CACHE end; END_KEY_CACHE end;
GET_KEY_CACHE_STATISTICS get_stats; GET_KEY_CACHE_STATISTICS get_stats;
GET_KEY_CACHE_STAT_VALUE get_stat_val;
} KEY_CACHE_FUNCS; } KEY_CACHE_FUNCS;
...@@ -153,13 +149,6 @@ typedef struct st_key_cache ...@@ -153,13 +149,6 @@ typedef struct st_key_cache
my_bool in_init; /* Set to 1 in MySQL during init/resize */ my_bool in_init; /* Set to 1 in MySQL during init/resize */
uint partitions; /* actual number of partitions */ uint partitions; /* actual number of partitions */
size_t key_cache_mem_size; /* specified size of the cache memory */ size_t key_cache_mem_size; /* specified size of the cache memory */
ulong blocks_used; /* maximum number of concurrently used blocks */
ulong blocks_unused; /* number of currently unused blocks */
ulong global_blocks_changed; /* number of currently dirty blocks */
ulonglong global_cache_w_requests;/* number of write requests (write hits) */
ulonglong global_cache_write; /* number of writes from cache to files */
ulonglong global_cache_r_requests;/* number of read requests (read hits) */
ulonglong global_cache_read; /* number of reads from files to cache */
} KEY_CACHE; } KEY_CACHE;
...@@ -193,7 +182,6 @@ extern void end_key_cache(KEY_CACHE *keycache, my_bool cleanup); ...@@ -193,7 +182,6 @@ extern void end_key_cache(KEY_CACHE *keycache, my_bool cleanup);
extern void get_key_cache_statistics(KEY_CACHE *keycache, extern void get_key_cache_statistics(KEY_CACHE *keycache,
uint partition_no, uint partition_no,
KEY_CACHE_STATISTICS *key_cache_stats); KEY_CACHE_STATISTICS *key_cache_stats);
extern ulonglong get_key_cache_stat_value(KEY_CACHE *keycache, uint var_no);
/* Functions to handle multiple key caches */ /* Functions to handle multiple key caches */
extern my_bool multi_keycache_init(void); extern my_bool multi_keycache_init(void);
......
...@@ -4914,61 +4914,6 @@ void get_simple_key_cache_statistics(SIMPLE_KEY_CACHE_CB *keycache, ...@@ -4914,61 +4914,6 @@ void get_simple_key_cache_statistics(SIMPLE_KEY_CACHE_CB *keycache,
} }
/*
Offsets of the statistical values in the control block for a simple key cache
The first NO_LONG_KEY_CACHE_STAT_VARIABLES=3 are of the ulong type while the
remaining are of the ulonglong type.
*/
static size_t simple_key_cache_stat_var_offsets[]=
{
offsetof(SIMPLE_KEY_CACHE_CB, blocks_used),
offsetof(SIMPLE_KEY_CACHE_CB, blocks_unused),
offsetof(SIMPLE_KEY_CACHE_CB, global_blocks_changed),
offsetof(SIMPLE_KEY_CACHE_CB, global_cache_w_requests),
offsetof(SIMPLE_KEY_CACHE_CB, global_cache_write),
offsetof(SIMPLE_KEY_CACHE_CB, global_cache_r_requests),
offsetof(SIMPLE_KEY_CACHE_CB, global_cache_read)
};
/*
Get the value of a statistical variable for a simple key cache
SYNOPSIS
get_simple_key_cache_stat_value()
keycache pointer to the control block of a simple key cache
var_no the ordered number of a statistical variable
DESCRIPTION
This function is the implementation of the get_simple_key_cache_stat_value
interface function that is employed by simple (non-partitioned) key caches.
The function takes the parameter keycache as a pointer to the
control block structure of the type SIMPLE_KEY_CACHE_CB for a simple key
cache. This function returns the value of the statistical variable var_no
for this key cache. The variables are numbered starting from 0 to 6.
RETURN
The value of the specified statistical variable
*/
static
ulonglong get_simple_key_cache_stat_value(SIMPLE_KEY_CACHE_CB *keycache,
uint var_no)
{
size_t var_ofs= simple_key_cache_stat_var_offsets[var_no];
ulonglong res= 0;
DBUG_ENTER("get_simple_key_cache_stat_value");
if (var_no < 3)
res= (ulonglong) (*(long *) ((char *) keycache + var_ofs));
else
res= *(ulonglong *) ((char *) keycache + var_ofs);
DBUG_RETURN(res);
}
/* /*
The array of pointer to the key cache interface functions used for simple The array of pointer to the key cache interface functions used for simple
key caches. Any simple key cache objects including those incorporated into key caches. Any simple key cache objects including those incorporated into
...@@ -4990,7 +4935,6 @@ static KEY_CACHE_FUNCS simple_key_cache_funcs = ...@@ -4990,7 +4935,6 @@ static KEY_CACHE_FUNCS simple_key_cache_funcs =
(RESET_KEY_CACHE_COUNTERS) reset_simple_key_cache_counters, (RESET_KEY_CACHE_COUNTERS) reset_simple_key_cache_counters,
(END_KEY_CACHE) end_simple_key_cache, (END_KEY_CACHE) end_simple_key_cache,
(GET_KEY_CACHE_STATISTICS) get_simple_key_cache_statistics, (GET_KEY_CACHE_STATISTICS) get_simple_key_cache_statistics,
(GET_KEY_CACHE_STAT_VALUE) get_simple_key_cache_stat_value
}; };
...@@ -5861,61 +5805,6 @@ get_partitioned_key_cache_statistics(PARTITIONED_KEY_CACHE_CB *keycache, ...@@ -5861,61 +5805,6 @@ get_partitioned_key_cache_statistics(PARTITIONED_KEY_CACHE_CB *keycache,
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/*
Get the value of a statistical variable for a partitioned key cache
SYNOPSIS
get_partitioned_key_cache_stat_value()
keycache pointer to the control block of a partitioned key cache
var_no the ordered number of a statistical variable
DESCRIPTION
This function is the implementation of the get_key_cache_stat_value
interface function that is employed by partitioned key caches.
The function takes the parameter keycache as a pointer to the
control block structure of the type PARTITIONED_KEY_CACHE_CB for a
partitioned key cache.
This function returns the value of the statistical variable var_no
for this key cache. The variables are numbered starting from 0 to 6.
The returned value is calculated as the sum of the values of the
statistical variable with number var_no for all simple key caches that
comprise the partitioned key cache.
RETURN
The value of the specified statistical variable
*/
static
ulonglong
get_partitioned_key_cache_stat_value(PARTITIONED_KEY_CACHE_CB *keycache,
uint var_no)
{
uint i;
uint partitions= keycache->partitions;
size_t var_ofs= simple_key_cache_stat_var_offsets[var_no];
ulonglong res= 0;
DBUG_ENTER("get_partitioned_key_cache_stat_value");
if (var_no < NUM_LONG_KEY_CACHE_STAT_VARIABLES)
{
for (i = 0; i < partitions; i++)
{
SIMPLE_KEY_CACHE_CB *partition= keycache->partition_array[i];
res+= (ulonglong) (*(long *) ((char *) partition + var_ofs));
}
}
else
{
for (i = 0; i < partitions; i++)
{
SIMPLE_KEY_CACHE_CB *partition= keycache->partition_array[i];
res+= *(ulonglong *) ((char *) partition + var_ofs);
}
}
DBUG_RETURN(res);
}
/* /*
The array of pointers to the key cache interface functions used by The array of pointers to the key cache interface functions used by
partitioned key caches. Any partitioned key cache object caches exploits partitioned key caches. Any partitioned key cache object caches exploits
...@@ -5938,7 +5827,6 @@ static KEY_CACHE_FUNCS partitioned_key_cache_funcs = ...@@ -5938,7 +5827,6 @@ static KEY_CACHE_FUNCS partitioned_key_cache_funcs =
(RESET_KEY_CACHE_COUNTERS) reset_partitioned_key_cache_counters, (RESET_KEY_CACHE_COUNTERS) reset_partitioned_key_cache_counters,
(END_KEY_CACHE) end_partitioned_key_cache, (END_KEY_CACHE) end_partitioned_key_cache,
(GET_KEY_CACHE_STATISTICS) get_partitioned_key_cache_statistics, (GET_KEY_CACHE_STATISTICS) get_partitioned_key_cache_statistics,
(GET_KEY_CACHE_STAT_VALUE) get_partitioned_key_cache_stat_value
}; };
...@@ -6246,8 +6134,6 @@ uchar *key_cache_read(KEY_CACHE *keycache, ...@@ -6246,8 +6134,6 @@ uchar *key_cache_read(KEY_CACHE *keycache,
block_length, return_buffer); block_length, return_buffer);
/* We can't use mutex here as the key cache may not be initialized */ /* We can't use mutex here as the key cache may not be initialized */
keycache->global_cache_r_requests++;
keycache->global_cache_read++;
if (my_pread(file, (uchar*) buff, length, filepos, MYF(MY_NABP))) if (my_pread(file, (uchar*) buff, length, filepos, MYF(MY_NABP)))
return (uchar *) 0; return (uchar *) 0;
...@@ -6356,8 +6242,6 @@ int key_cache_write(KEY_CACHE *keycache, ...@@ -6356,8 +6242,6 @@ int key_cache_write(KEY_CACHE *keycache,
block_length, force_write); block_length, force_write);
/* We can't use mutex here as the key cache may not be initialized */ /* We can't use mutex here as the key cache may not be initialized */
keycache->global_cache_w_requests++;
keycache->global_cache_write++;
if (my_pwrite(file, buff, length, filepos, MYF(MY_NABP | MY_WAIT_IF_FULL))) if (my_pwrite(file, buff, length, filepos, MYF(MY_NABP | MY_WAIT_IF_FULL)))
return 1; return 1;
...@@ -6474,49 +6358,6 @@ void get_key_cache_statistics(KEY_CACHE *keycache, uint partition_no, ...@@ -6474,49 +6358,6 @@ void get_key_cache_statistics(KEY_CACHE *keycache, uint partition_no,
} }
} }
/*
Get the value of a statistical variable for a key cache
SYNOPSIS
get_key_cache_stat_value()
keycache pointer to the key cache to get statistics for
var_no the ordered number of a statistical variable
DESCRIPTION
This function returns the value of the statistical variable var_no for
the key cache keycache. The variables are numbered starting from 0 to 6.
RETURN
The value of the specified statistical variable.
NOTES
Currently for any key cache the function can return values for the
following 7 statistical variables:
Name Number
blocks_used 0
blocks_unused 1
blocks_changed 2
read_requests 3
reads 4
write_requests 5
writes 6
*/
ulonglong get_key_cache_stat_value(KEY_CACHE *keycache, uint var_no)
{
if (keycache->key_cache_inited)
{
return keycache->interface_funcs->get_stat_val(keycache->keycache_cb,
var_no);
}
else
return 0;
}
/* /*
Repartition a key cache Repartition a key cache
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
that is defined in mysql/plugin.h that is defined in mysql/plugin.h
it has to be before mysql/plugin.h is included. it has to be before mysql/plugin.h is included.
*/ */
#define SHOW_always_last SHOW_KEY_CACHE_LONG, \ #define SHOW_always_last SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, \
SHOW_KEY_CACHE_LONGLONG, SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, \
SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \ SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \
SHOW_LONG_NOFLUSH, SHOW_LONGLONG_STATUS SHOW_LONG_NOFLUSH, SHOW_LONGLONG_STATUS
......
...@@ -7948,6 +7948,45 @@ static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7948,6 +7948,45 @@ static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff)
#endif /* HAVE_OPENSSL */ #endif /* HAVE_OPENSSL */
static int show_default_keycache(THD *thd, SHOW_VAR *var, char *buff)
{
struct st_data {
KEY_CACHE_STATISTICS stats;
SHOW_VAR var[8];
} *data;
SHOW_VAR *v;
data=(st_data *)buff;
v= data->var;
var->type= SHOW_ARRAY;
var->value= (char*)v;
get_key_cache_statistics(dflt_key_cache, 0, &data->stats);
#define set_one_keycache_var(X,Y) \
v->name= X; \
v->type= SHOW_LONGLONG; \
v->value= (char*)&data->stats.Y; \
v++;
set_one_keycache_var("blocks_not_flushed", blocks_changed);
set_one_keycache_var("blocks_unused", blocks_unused);
set_one_keycache_var("blocks_used", blocks_used);
set_one_keycache_var("read_requests", read_requests);
set_one_keycache_var("reads", reads);
set_one_keycache_var("write_requests", write_requests);
set_one_keycache_var("writes", writes);
v->name= 0;
DBUG_ASSERT((char*)(v+1) <= buff + SHOW_VAR_FUNC_BUFF_SIZE);
#undef set_one_keycache_var
return 0;
}
/* /*
Variables shown by SHOW STATUS in alphabetical order Variables shown by SHOW STATUS in alphabetical order
...@@ -7990,13 +8029,7 @@ SHOW_VAR status_vars[]= { ...@@ -7990,13 +8029,7 @@ SHOW_VAR status_vars[]= {
{"Handler_savepoint_rollback",(char*) offsetof(STATUS_VAR, ha_savepoint_rollback_count), SHOW_LONG_STATUS}, {"Handler_savepoint_rollback",(char*) offsetof(STATUS_VAR, ha_savepoint_rollback_count), SHOW_LONG_STATUS},
{"Handler_update", (char*) offsetof(STATUS_VAR, ha_update_count), SHOW_LONG_STATUS}, {"Handler_update", (char*) offsetof(STATUS_VAR, ha_update_count), SHOW_LONG_STATUS},
{"Handler_write", (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS}, {"Handler_write", (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS},
{"Key_blocks_not_flushed", (char*) offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG}, {"Key", (char*) &show_default_keycache, SHOW_FUNC},
{"Key_blocks_unused", (char*) offsetof(KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_LONG},
{"Key_blocks_used", (char*) offsetof(KEY_CACHE, blocks_used), SHOW_KEY_CACHE_LONG},
{"Key_read_requests", (char*) offsetof(KEY_CACHE, global_cache_r_requests), SHOW_KEY_CACHE_LONGLONG},
{"Key_reads", (char*) offsetof(KEY_CACHE, global_cache_read), SHOW_KEY_CACHE_LONGLONG},
{"Key_write_requests", (char*) offsetof(KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
{"Key_writes", (char*) offsetof(KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
{"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS}, {"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
{"Max_used_connections", (char*) &max_used_connections, SHOW_LONG}, {"Max_used_connections", (char*) &max_used_connections, SHOW_LONG},
{"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_NOFLUSH}, {"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_NOFLUSH},
......
...@@ -2292,34 +2292,6 @@ void remove_status_vars(SHOW_VAR *list) ...@@ -2292,34 +2292,6 @@ void remove_status_vars(SHOW_VAR *list)
static void update_key_cache_stat_var(KEY_CACHE *key_cache, size_t ofs)
{
uint var_no;
if (ofs == offsetof(KEY_CACHE, blocks_used) ||
ofs == offsetof(KEY_CACHE, blocks_unused) ||
ofs == offsetof(KEY_CACHE, global_blocks_changed))
{
var_no= (ofs-offsetof(KEY_CACHE, blocks_used))/sizeof(ulong);
*(ulong *)((char *) key_cache + ofs)=
(ulong) get_key_cache_stat_value(key_cache, var_no);
return;
}
if (ofs == offsetof(KEY_CACHE, global_cache_r_requests) ||
ofs == offsetof(KEY_CACHE, global_cache_read) ||
ofs == offsetof(KEY_CACHE, global_cache_w_requests) ||
ofs == offsetof(KEY_CACHE, global_cache_write))
{
var_no= NUM_LONG_KEY_CACHE_STAT_VARIABLES +
(ofs-offsetof(KEY_CACHE, global_cache_w_requests))/
sizeof(ulonglong);
*(ulonglong *)((char *) key_cache + ofs)=
get_key_cache_stat_value(key_cache, var_no);
return;
}
}
static bool show_status_array(THD *thd, const char *wild, static bool show_status_array(THD *thd, const char *wild,
SHOW_VAR *variables, SHOW_VAR *variables,
enum enum_var_type value_type, enum enum_var_type value_type,
...@@ -2451,16 +2423,6 @@ static bool show_status_array(THD *thd, const char *wild, ...@@ -2451,16 +2423,6 @@ static bool show_status_array(THD *thd, const char *wild,
end= strend(pos); end= strend(pos);
break; break;
} }
case SHOW_KEY_CACHE_LONG:
update_key_cache_stat_var(dflt_key_cache, (size_t) value);
value= (char*) dflt_key_cache + (ulong)value;
end= int10_to_str(*(long*) value, buff, 10);
break;
case SHOW_KEY_CACHE_LONGLONG:
update_key_cache_stat_var(dflt_key_cache, (size_t) value);
value= (char*) dflt_key_cache + (ulong)value;
end= longlong10_to_str(*(longlong*) value, buff, 10);
break;
case SHOW_UNDEF: case SHOW_UNDEF:
break; // Return empty string break; // Return empty string
case SHOW_SYS: // Cannot happen case SHOW_SYS: // Cannot happen
......
...@@ -441,6 +441,9 @@ static int print_key_cache_status(const char *name, KEY_CACHE *key_cache) ...@@ -441,6 +441,9 @@ static int print_key_cache_status(const char *name, KEY_CACHE *key_cache)
} }
else else
{ {
KEY_CACHE_STATISTICS stats;
get_key_cache_statistics(key_cache, 0, &stats);
printf("%s\n\ printf("%s\n\
Buffer_size: %10lu\n\ Buffer_size: %10lu\n\
Block_size: %10lu\n\ Block_size: %10lu\n\
...@@ -457,11 +460,12 @@ reads: %10s\n\n", ...@@ -457,11 +460,12 @@ reads: %10s\n\n",
(ulong) key_cache->param_buff_size, key_cache->param_block_size, (ulong) key_cache->param_buff_size, key_cache->param_block_size,
key_cache->param_division_limit, key_cache->param_age_threshold, key_cache->param_division_limit, key_cache->param_age_threshold,
key_cache->param_partitions, key_cache->param_partitions,
key_cache->blocks_used,key_cache->global_blocks_changed, (ulong)stats.blocks_used,
llstr(key_cache->global_cache_w_requests,llbuff1), (ulong)stats.blocks_changed,
llstr(key_cache->global_cache_write,llbuff2), llstr(stats.write_requests,llbuff1),
llstr(key_cache->global_cache_r_requests,llbuff3), llstr(stats.writes,llbuff2),
llstr(key_cache->global_cache_read,llbuff4)); llstr(stats.read_requests,llbuff3),
llstr(stats.reads,llbuff4));
} }
return 0; return 0;
} }
......
...@@ -812,6 +812,8 @@ end: ...@@ -812,6 +812,8 @@ end:
mi_panic(HA_PANIC_CLOSE); /* Should close log */ mi_panic(HA_PANIC_CLOSE); /* Should close log */
if (!silent) if (!silent)
{ {
KEY_CACHE_STATISTICS stats;
printf("\nFollowing test have been made:\n"); printf("\nFollowing test have been made:\n");
printf("Write records: %d\nUpdate records: %d\nSame-key-read: %d\nDelete records: %d\n", write_count,update,dupp_keys,opt_delete); printf("Write records: %d\nUpdate records: %d\nSame-key-read: %d\nDelete records: %d\n", write_count,update,dupp_keys,opt_delete);
if (rec_pointer_size) if (rec_pointer_size)
...@@ -834,6 +836,7 @@ end: ...@@ -834,6 +836,7 @@ end:
puts("Locking used"); puts("Locking used");
if (use_blob) if (use_blob)
puts("blobs used"); puts("blobs used");
get_key_cache_statistics(dflt_key_cache, 0, &stats);
printf("key cache status: \n\ printf("key cache status: \n\
blocks used:%10lu\n\ blocks used:%10lu\n\
not flushed:%10lu\n\ not flushed:%10lu\n\
...@@ -841,12 +844,12 @@ w_requests: %10lu\n\ ...@@ -841,12 +844,12 @@ w_requests: %10lu\n\
writes: %10lu\n\ writes: %10lu\n\
r_requests: %10lu\n\ r_requests: %10lu\n\
reads: %10lu\n", reads: %10lu\n",
dflt_key_cache->blocks_used, (ulong) stats.blocks_used,
dflt_key_cache->global_blocks_changed, (ulong) stats.blocks_changed,
(ulong) dflt_key_cache->global_cache_w_requests, (ulong) stats.write_requests,
(ulong) dflt_key_cache->global_cache_write, (ulong) stats.writes,
(ulong) dflt_key_cache->global_cache_r_requests, (ulong) stats.read_requests,
(ulong) dflt_key_cache->global_cache_read); (ulong) stats.reads);
} }
end_key_cache(dflt_key_cache,1); end_key_cache(dflt_key_cache,1);
if (blob_buffer) if (blob_buffer)
......
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