Shows how to access database and table statistics.
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wiredtiger.h>
int get_stat(
WT_CURSOR *cursor,
int stat_field, uint64_t *valuep);
static const char *home;
int
{
const char *desc, *pvalue;
uint64_t value;
int ret;
while ((ret = cursor->
next(cursor)) == 0 &&
(ret = cursor->
get_value(cursor, &desc, &pvalue, &value)) == 0)
if (value != 0)
printf("%s=%s\n", desc, pvalue);
}
int
{
int ret;
"statistics:", NULL, NULL, &cursor)) != 0)
return (ret);
ret = print_cursor(cursor);
ret = cursor->
close(cursor);
return (ret);
}
int
{
int ret;
"statistics:table:access", NULL, NULL, &cursor)) != 0)
return (ret);
ret = print_cursor(cursor);
ret = cursor->
close(cursor);
return (ret);
}
int
{
WT_CURSOR *idx_cursor, *join_cursor, *stat_cursor;
int ret;
session, "index:access:idx", "columns=(v)");
session, "index:access:idx", NULL, NULL, &idx_cursor);
ret = idx_cursor->
next(idx_cursor);
session, "join:table:access", NULL, NULL, &join_cursor);
ret = session->
join(session, join_cursor, idx_cursor,
"compare=gt");
ret = join_cursor->
next(join_cursor);
"statistics:join", join_cursor, NULL, &stat_cursor)) != 0)
return (ret);
ret = print_cursor(stat_cursor);
ret = stat_cursor->
close(stat_cursor);
ret = join_cursor->
close(join_cursor);
ret = idx_cursor->
close(idx_cursor);
return (ret);
}
int
{
const char *desc, *pvalue;
uint64_t value;
int ret;
"statistics:table:access", NULL, NULL, &cursor)) != 0)
return (ret);
ret = cursor->
get_value(cursor, &desc, &pvalue, &value);
printf("%s=%s\n", desc, pvalue);
ret = cursor->
close(cursor);
return (ret);
}
int
get_stat(
WT_CURSOR *cursor,
int stat_field, uint64_t *valuep)
{
const char *desc, *pvalue;
int ret;
cursor->
set_key(cursor, stat_field);
if ((ret = cursor->
search(cursor)) != 0)
return (ret);
return (cursor->
get_value(cursor, &desc, &pvalue, valuep));
}
int
{
int ret;
"statistics:table:access", NULL, NULL, &cursor)) != 0)
return (ret);
{
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));
}
ret = cursor->
close(cursor);
return (ret);
}
int
main(void)
{
int ret;
if (getenv("WIREDTIGER_HOME") == NULL) {
home = "WT_HOME";
ret = system("rm -rf WT_HOME && mkdir WT_HOME");
} else
home = NULL;
ret = session->
create(session,
"table:access", "key_format=S,value_format=S,columns=(k,v)");
session, "table:access", NULL, NULL, &cursor);
ret = cursor->
close(cursor);
ret = print_database_stats(session);
ret = print_file_stats(session);
ret = print_join_cursor_stats(session);
ret = print_overflow_pages(session);
ret = print_derived_stats(session);
ret = conn->
close(conn, NULL);
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}