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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*-
* Copyright (c) 2008-2012 WiredTiger, Inc.
* All rights reserved.
*
* See the file LICENSE for redistribution information.
*/
#include "wt_internal.h"
/*
* __wt_lsm_stat_init --
* Initialize a LSM statistics structure.
*/
int
__wt_lsm_stat_init(
WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree, uint32_t flags)
{
WT_CURSOR *stat_cursor;
WT_DECL_ITEM(uribuf);
WT_DECL_RET;
WT_LSM_CHUNK *chunk;
const char *cfg[] = API_CONF_DEFAULTS(
session, open_cursor, "statistics_fast=on");
const char *disk_cfg[] = API_CONF_DEFAULTS(session,
open_cursor, "checkpoint=WiredTigerCheckpoint,statistics_fast=on");
const char *desc, *pvalue;
int i;
uint64_t value;
WT_UNUSED(flags);
WT_ERR(__wt_scr_alloc(session, 0, &uribuf));
/*
* TODO: Make a copy of the stat fields so the stat cursor gets a
* consistent view? If so should the copy belong to the stat cursor?
*/
/* Clear the statistics we are about to recalculate. */
WT_STAT_SET(lsm_tree->stats, bloom_page_read, 0);
WT_STAT_SET(lsm_tree->stats, bloom_page_evict, 0);
WT_STAT_SET(lsm_tree->stats, bloom_count, 0);
WT_STAT_SET(lsm_tree->stats, bloom_size, 0);
WT_STAT_SET(lsm_tree->stats, page_evict, 0);
WT_STAT_SET(lsm_tree->stats, page_evict_fail, 0);
WT_STAT_SET(lsm_tree->stats, page_read, 0);
WT_STAT_SET(lsm_tree->stats, page_write, 0);
WT_STAT_SET(lsm_tree->stats, lsm_generation_max, 0);
/* Hold the LSM lock so that we can safely walk through the chunks. */
__wt_readlock(session, lsm_tree->rwlock);
/* Set the stats for this run. */
WT_STAT_SET(lsm_tree->stats, lsm_chunk_count, lsm_tree->nchunks);
for (i = 0; i < lsm_tree->nchunks; i++) {
chunk = lsm_tree->chunk[i];
if (chunk->generation >
(uint32_t)WT_STAT(lsm_tree->stats, lsm_generation_max))
WT_STAT_SET(lsm_tree->stats,
lsm_generation_max, chunk->generation);
/*
* LSM chunk reads happen from a checkpoint, so get the
* statistics for a checkpoint if one exists.
*/
WT_ERR(__wt_buf_fmt(
session, uribuf, "statistics:%s", chunk->uri));
ret = __wt_curstat_open(session, uribuf->data,
F_ISSET(chunk, WT_LSM_CHUNK_ONDISK) ? disk_cfg : cfg,
&stat_cursor);
/*
* XXX kludge: we may have an empty chunk where no checkpoint
* was written. If so, try to open the ordinary handle on that
* chunk instead.
*/
if (ret == WT_NOTFOUND && F_ISSET(chunk, WT_LSM_CHUNK_ONDISK))
ret = __wt_curstat_open(
session, uribuf->data, cfg, &stat_cursor);
WT_ERR(ret);
stat_cursor->set_key(stat_cursor, WT_STAT_DSRC_PAGE_EVICT_FAIL);
WT_ERR(stat_cursor->search(stat_cursor));
WT_ERR(stat_cursor->get_value(
stat_cursor, &desc, &pvalue, &value));
WT_STAT_INCRV(lsm_tree->stats, page_evict_fail, value);
stat_cursor->set_key(stat_cursor, WT_STAT_DSRC_PAGE_EVICT);
WT_ERR(stat_cursor->search(stat_cursor));
WT_ERR(stat_cursor->get_value(
stat_cursor, &desc, &pvalue, &value));
WT_STAT_INCRV(lsm_tree->stats, page_evict, value);
stat_cursor->set_key(stat_cursor, WT_STAT_DSRC_PAGE_READ);
WT_ERR(stat_cursor->search(stat_cursor));
WT_ERR(stat_cursor->get_value(
stat_cursor, &desc, &pvalue, &value));
WT_STAT_INCRV(lsm_tree->stats, page_read, value);
stat_cursor->set_key(stat_cursor, WT_STAT_DSRC_PAGE_WRITE);
WT_ERR(stat_cursor->search(stat_cursor));
WT_ERR(stat_cursor->get_value(
stat_cursor, &desc, &pvalue, &value));
WT_STAT_INCRV(lsm_tree->stats, page_write, value);
WT_ERR(stat_cursor->close(stat_cursor));
if (!F_ISSET(chunk, WT_LSM_CHUNK_BLOOM))
continue;
WT_STAT_INCR(lsm_tree->stats, bloom_count);
WT_STAT_INCRV(lsm_tree->stats, bloom_size,
(chunk->count * lsm_tree->bloom_bit_count) / 8);
WT_ERR(__wt_buf_fmt(
session, uribuf, "statistics:%s", chunk->bloom_uri));
WT_ERR(__wt_curstat_open(session, uribuf->data,
cfg, &stat_cursor));
stat_cursor->set_key(stat_cursor, WT_STAT_DSRC_PAGE_EVICT);
WT_ERR(stat_cursor->search(stat_cursor));
WT_ERR(stat_cursor->get_value(
stat_cursor, &desc, &pvalue, &value));
WT_STAT_INCRV(lsm_tree->stats, page_evict, value);
WT_STAT_INCRV(lsm_tree->stats, bloom_page_evict, value);
stat_cursor->set_key(stat_cursor, WT_STAT_DSRC_PAGE_EVICT_FAIL);
WT_ERR(stat_cursor->search(stat_cursor));
WT_ERR(stat_cursor->get_value(
stat_cursor, &desc, &pvalue, &value));
WT_STAT_INCRV(lsm_tree->stats, page_evict_fail, value);
stat_cursor->set_key(stat_cursor, WT_STAT_DSRC_PAGE_READ);
WT_ERR(stat_cursor->search(stat_cursor));
WT_ERR(stat_cursor->get_value(
stat_cursor, &desc, &pvalue, &value));
WT_STAT_INCRV(lsm_tree->stats, page_read, value);
WT_STAT_INCRV(lsm_tree->stats, bloom_page_read, value);
stat_cursor->set_key(stat_cursor, WT_STAT_DSRC_PAGE_WRITE);
WT_ERR(stat_cursor->search(stat_cursor));
WT_ERR(stat_cursor->get_value(
stat_cursor, &desc, &pvalue, &value));
WT_STAT_INCRV(lsm_tree->stats, page_write, value);
WT_ERR(stat_cursor->close(stat_cursor));
}
err: __wt_rwunlock(session, lsm_tree->rwlock);
__wt_scr_free(&uribuf);
return (ret);
}
|