Shows how to access database and table statistics.
#include <test_util.h>
void get_stat(
WT_CURSOR *cursor,
int stat_field, uint64_t *valuep);
static const char *home;
void
{
const char *desc, *pvalue;
uint64_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
{
session, "statistics:", NULL, NULL, &cursor));
print_cursor(cursor);
error_check(cursor->
close(cursor));
}
void
{
session, "statistics:table:access", NULL, NULL, &cursor));
print_cursor(cursor);
error_check(cursor->
close(cursor));
}
void
{
WT_CURSOR *idx_cursor, *join_cursor, *stat_cursor;
session, "index:access:idx", "columns=(v)"));
session, "index:access:idx", NULL, NULL, &idx_cursor));
error_check(idx_cursor->
next(idx_cursor));
session, "join:table:access", NULL, NULL, &join_cursor));
error_check(session->
join(
session, join_cursor, idx_cursor, "compare=gt"));
print_cursor(join_cursor);
"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
{
const char *desc, *pvalue;
uint64_t value;
"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, uint64_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
{
"statistics:table:access", NULL, NULL, &cursor));
{
uint64_t ckpt_size, file_size, percent;
percent = 0;
if (file_size != 0)
percent = 100 * ((file_size - ckpt_size) / file_size);
printf("Table is %" PRIu64 "%% fragmented\n", percent);
}
{
uint64_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(
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)"));
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_overflow_pages(session);
print_derived_stats(session);
error_check(conn->
close(conn, NULL));
return (EXIT_SUCCESS);
}