summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/schema/schema_stat.c
blob: dea797f823de59b79925cda2f15949ca48397c0c (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*-
 * Copyright (c) 2014-2015 MongoDB, Inc.
 * Copyright (c) 2008-2014 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#include "wt_internal.h"

/*
 * __wt_curstat_colgroup_init --
 *	Initialize the statistics for a column group.
 */
int
__wt_curstat_colgroup_init(WT_SESSION_IMPL *session,
    const char *uri, const char *cfg[], WT_CURSOR_STAT *cst)
{
	WT_COLGROUP *colgroup;
	WT_DECL_ITEM(buf);
	WT_DECL_RET;

	WT_RET(__wt_schema_get_colgroup(session, uri, 0, NULL, &colgroup));

	WT_RET(__wt_scr_alloc(session, 0, &buf));
	WT_ERR(__wt_buf_fmt(session, buf, "statistics:%s", colgroup->source));
	ret = __wt_curstat_init(session, buf->data, cfg, cst);

err:	__wt_scr_free(session, &buf);
	return (ret);
}

/*
 * __wt_curstat_index_init --
 *	Initialize the statistics for an index.
 */
int
__wt_curstat_index_init(WT_SESSION_IMPL *session,
    const char *uri, const char *cfg[], WT_CURSOR_STAT *cst)
{
	WT_DECL_ITEM(buf);
	WT_DECL_RET;
	WT_INDEX *idx;

	WT_RET(__wt_schema_get_index(session, uri, 0, NULL, &idx));

	WT_RET(__wt_scr_alloc(session, 0, &buf));
	WT_ERR(__wt_buf_fmt(session, buf, "statistics:%s", idx->source));
	ret = __wt_curstat_init(session, buf->data, cfg, cst);

err:	__wt_scr_free(session, &buf);
	return (ret);
}

/*
 * __wt_curstat_table_init --
 *	Initialize the statistics for a table.
 */
int
__wt_curstat_table_init(WT_SESSION_IMPL *session,
    const char *uri, const char *cfg[], WT_CURSOR_STAT *cst)
{
	WT_CURSOR *stat_cursor;
	WT_DECL_ITEM(buf);
	WT_DECL_RET;
	WT_DSRC_STATS *new, *stats;
	WT_TABLE *table;
	u_int i;
	const char *name;

	name = uri + strlen("table:");
	WT_RET(__wt_schema_get_table(session, name, strlen(name), 0, &table));

	WT_ERR(__wt_scr_alloc(session, 0, &buf));

	/*
	 * Process the column groups.
	 *
	 * Set the cursor to reference the data source statistics; we don't
	 * initialize it, instead we copy (rather than aggregate), the first
	 * column's statistics, which has the same effect.
	 */
	stats = &cst->u.dsrc_stats;
	for (i = 0; i < WT_COLGROUPS(table); i++) {
		WT_ERR(__wt_buf_fmt(
		    session, buf, "statistics:%s", table->cgroups[i]->name));
		WT_ERR(__wt_curstat_open(
		    session, buf->data, cfg, &stat_cursor));
		new = (WT_DSRC_STATS *)WT_CURSOR_STATS(stat_cursor);
		if (i == 0)
			*stats = *new;
		else
			__wt_stat_aggregate_dsrc_stats(new, stats);
		WT_ERR(stat_cursor->close(stat_cursor));
	}

	/* Process the indices. */
	WT_ERR(__wt_schema_open_indices(session, table));
	for (i = 0; i < table->nindices; i++) {
		WT_ERR(__wt_buf_fmt(
		    session, buf, "statistics:%s", table->indices[i]->name));
		WT_ERR(__wt_curstat_open(
		    session, buf->data, cfg, &stat_cursor));
		new = (WT_DSRC_STATS *)WT_CURSOR_STATS(stat_cursor);
		__wt_stat_aggregate_dsrc_stats(new, stats);
		WT_ERR(stat_cursor->close(stat_cursor));
	}

	__wt_curstat_dsrc_final(cst);

err:	__wt_schema_release_table(session, table);

	__wt_scr_free(session, &buf);
	return (ret);
}