summaryrefslogtreecommitdiff
path: root/db/db_stat.c
blob: b9534c53ac383033a2fff162e3fec2d2ae34177b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2008-2010 WiredTiger, Inc.
 *	All rights reserved.
 *
 * $Id$
 */

#include "wt_internal.h"

/*
 * __wt_db_stat_print --
 *	Print DB handle statistics to a stream.
 */
int
__wt_db_stat_print(WT_TOC *toc, FILE *stream)
{
	DB *db;
	ENV *env;
	IDB *idb;

	db = toc->db;
	env = toc->env;
	idb = db->idb;

	fprintf(stream, "Database handle statistics: %s\n", idb->name);
	__wt_stat_print(env, idb->stats, stream);

	/* Clear the database stats, then call Btree stat to fill them in. */
	__wt_stat_clear_database_stats(idb->dstats);
	WT_STAT_SET(
	    idb->dstats, TREE_LEVEL, idb->root_page->hdr->level);
	WT_RET(__wt_bt_stat_desc(toc));

	/*
	 * Note we do not have a hazard reference for the root page, and that's
	 * safe -- root pages are pinned into memory when a database is opened,
	 * and never re-written until the database is closed.
	 */
	WT_RET(__wt_bt_tree_walk(
	    toc, idb->root_addr, idb->root_size, __wt_bt_stat_page, NULL));

	fprintf(stream, "Database statistics: %s\n", idb->name);
	__wt_stat_print(env, idb->dstats, stream);

	/* Underlying file handle statistics. */
	if (idb->fh != NULL) {
		fprintf(stream,
		    "Underlying file I/O statistics: %s\n", idb->name);
		__wt_stat_print(env, idb->fh->stats, stream);
	}

	return (0);
}

/*
 * __wt_db_stat_clear --
 *	Clear DB handle statistics.
 */
int
__wt_db_stat_clear(DB *db)
{
	IDB *idb;

	idb = db->idb;

	__wt_stat_clear_db_stats(idb->stats);
	__wt_stat_clear_database_stats(idb->dstats);
	if (idb->fh != NULL)
		__wt_stat_clear_fh_stats(idb->fh->stats);

	return (0);
}