summaryrefslogtreecommitdiff
path: root/src/env/env_stat.c
blob: 8cfd1416dea3b4c651fca603ec08059ddfc31e2b (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
75
76
77
78
79
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2008-2011 WiredTiger, Inc.
 *	All rights reserved.
 */

#include "wt_internal.h"

/*
 * __wt_connection_stat_print --
 *	Print CONNECTION handle statistics to a stream.
 *
 * XXX this will become a statistics cursor.
 */
int
__wt_connection_stat_print(CONNECTION *conn, FILE *stream)
{
	BTREE *btree;
	SESSION *session;

	session = &conn->default_session;

	fprintf(stream, "Database statistics:\n");
	__wt_stat_print_conn_stats(conn->stats, stream);
	fprintf(stream, "%s\n", conn->sep);

	fprintf(stream, "Database cache statistics:\n");
	__wt_cache_stats_update(conn);
	__wt_stat_print_cache_stats(conn->cache->stats, stream);
	fprintf(stream, "%s\n", conn->sep);

	TAILQ_FOREACH(btree, &conn->dbqh, q) {
		session->btree = btree;
		WT_RET(__wt_btree_stat_print(session, stream));
	}
	return (0);
}

/*
 * __wt_connection_stat_clear --
 *	Clear CONNECTION handle statistics.
 */
int
__wt_connection_stat_clear(CONNECTION *conn)
{
	BTREE *btree;
	int ret;

	ret = 0;

	TAILQ_FOREACH(btree, &conn->dbqh, q)
		WT_TRET(__wt_btree_stat_clear(btree));

	__wt_stat_clear_conn_stats(conn->stats);
	__wt_stat_clear_cache_stats(conn->cache->stats);

	return (ret);
}

/*
 * __wt_stat_print --
 *	Print out a statistics table value.
 */
void
__wt_stat_print(WT_STATS *s, FILE *stream)
{
	if (s->v >= WT_BILLION)
		fprintf(stream, "%lluB\t%s (%llu bytes)\n",
		    (unsigned long long)s->v / WT_BILLION,
		    s->desc, (unsigned long long)s->v);
	else if (s->v >= WT_MILLION)
		fprintf(stream, "%lluM\t%s (%llu bytes)\n",
		    (unsigned long long)s->v / WT_MILLION,
		    s->desc, (unsigned long long)s->v);
	else
		fprintf(stream,
		    "%llu\t%s\n", (unsigned long long)s->v, s->desc);
}