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
{
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;
session, "table:access", "key_format=S,value_format=S");
session, "table:access", NULL, NULL, &cursor);
ret = cursor->
close(cursor);
ret = print_database_stats(session);
ret = print_file_stats(session);
ret = print_overflow_pages(session);
ret = print_derived_stats(session);
return (conn->
close(conn, NULL) == 0 ? ret : EXIT_FAILURE);
}