Shows how to access database and table statistics.
#include <test_util.h>
void get_stat(
WT_CURSOR *cursor,
int stat_field, int64_t *valuep);
static const char *home;
void
{
const char *desc, *pvalue;
int64_t value;
int ret;
while ((ret = cursor->
next(cursor)) == 0) {
error_check(cursor->
get_value(cursor, &desc, &pvalue, &value));
if (value != 0)
printf("%s=%s\n", desc, pvalue);
}
}
void
{
error_check(session->
open_cursor(session,
"statistics:", NULL, NULL, &cursor));
print_cursor(cursor);
error_check(cursor->
close(cursor));
}
void
{
error_check(session->
open_cursor(session,
"statistics:table:access", NULL, NULL, &cursor));
print_cursor(cursor);
error_check(cursor->
close(cursor));
}
void
{
WT_CURSOR *idx_cursor, *join_cursor, *stat_cursor;
error_check(session->
create(session,
"index:access:idx",
"columns=(v)"));
error_check(session->
open_cursor(session,
"index:access:idx", NULL, NULL, &idx_cursor));
error_check(idx_cursor->
next(idx_cursor));
error_check(session->
open_cursor(session,
"join:table:access", NULL, NULL, &join_cursor));
error_check(session->
join(session, join_cursor, idx_cursor,
"compare=gt"));
print_cursor(join_cursor);
error_check(session->
open_cursor(session,
"statistics:join", join_cursor, NULL, &stat_cursor));
print_cursor(stat_cursor);
error_check(stat_cursor->
close(stat_cursor));
error_check(join_cursor->
close(join_cursor));
error_check(idx_cursor->
close(idx_cursor));
}
void
{
error_check(session->
open_cursor(session,
"statistics:session", NULL, NULL, &stat_cursor));
print_cursor(stat_cursor);
error_check(stat_cursor->
close(stat_cursor));
}
void
{
const char *desc, *pvalue;
int64_t value;
error_check(session->
open_cursor(session,
"statistics:table:access", NULL, NULL, &cursor));
error_check(cursor->
search(cursor));
error_check(cursor->
get_value(cursor, &desc, &pvalue, &value));
printf("%s=%s\n", desc, pvalue);
error_check(cursor->
close(cursor));
}
void
get_stat(
WT_CURSOR *cursor,
int stat_field, int64_t *valuep)
{
const char *desc, *pvalue;
cursor->
set_key(cursor, stat_field);
error_check(cursor->
search(cursor));
error_check(cursor->
get_value(cursor, &desc, &pvalue, valuep));
}
void
{
error_check(session->
open_cursor(session,
"statistics:table:access", NULL, NULL, &cursor));
{
int64_t ckpt_size, file_size, percent;
percent = 0;
if (file_size != 0)
percent = 100 * ((file_size - ckpt_size) / file_size);
printf("Table is %" PRId64 "%% fragmented\n", percent);
}
{
int64_t app_insert, app_remove, app_update, fs_writes;
if (app_insert + app_remove + app_update != 0)
printf("Write amplification is %.2lf\n",
(double)fs_writes / (app_insert + app_remove + app_update));
}
error_check(cursor->
close(cursor));
}
int
main(int argc, char *argv[])
{
home = example_setup(argc, argv);
error_check(
wiredtiger_open(home, NULL,
"create,statistics=(all)", &conn));
error_check(conn->
open_session(conn, NULL, NULL, &session));
error_check(
session->
create(session,
"table:access",
"key_format=S,value_format=S,columns=(k,v)"));
error_check(session->
open_cursor(session,
"table:access", NULL, NULL, &cursor));
error_check(cursor->
insert(cursor));
error_check(cursor->
close(cursor));
print_database_stats(session);
print_file_stats(session);
print_join_cursor_stats(session);
print_session_stats(session);
print_overflow_pages(session);
print_derived_stats(session);
error_check(conn->
close(conn, NULL));
return (EXIT_SUCCESS);
}