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
149
150
151
152
|
/*-
* Copyright (c) 2014-2018 MongoDB, Inc.
* Copyright (c) 2008-2014 WiredTiger, Inc.
* All rights reserved.
*
* See the file LICENSE for redistribution information.
*/
#include "wt_internal.h"
/*
* __evict_stat_walk --
* Walk all the pages in cache for a dhandle gathering stats information
*/
static void
__evict_stat_walk(WT_SESSION_IMPL *session)
{
WT_BTREE *btree;
WT_CACHE *cache;
WT_PAGE *page;
WT_REF *next_walk;
uint64_t dsk_size, gen_gap, gen_gap_max, gen_gap_sum, max_pagesize;
uint64_t min_written_size, num_memory, num_not_queueable, num_queued;
uint64_t num_smaller_allocsz, pages_clean, pages_dirty, pages_internal;
uint64_t pages_leaf, seen_count, size, visited_count;
uint64_t visited_age_gap_sum, unvisited_count, unvisited_age_gap_sum;
uint64_t walk_count, written_size_cnt, written_size_sum;
btree = S2BT(session);
cache = S2C(session)->cache;
next_walk = NULL;
gen_gap_max = gen_gap_sum = max_pagesize = 0;
num_memory = num_not_queueable = num_queued = 0;
num_smaller_allocsz = pages_clean = pages_dirty = pages_internal = 0;
pages_leaf = seen_count = size = visited_count = 0;
visited_age_gap_sum = unvisited_count = unvisited_age_gap_sum = 0;
walk_count = written_size_cnt = written_size_sum = 0;
min_written_size = UINT64_MAX;
while (__wt_tree_walk_count(session, &next_walk, &walk_count,
WT_READ_CACHE | WT_READ_NO_EVICT |
WT_READ_NO_GEN | WT_READ_NO_WAIT) == 0 &&
next_walk != NULL) {
++seen_count;
page = next_walk->page;
size = page->memory_footprint;
if (__wt_page_is_modified(page))
++pages_dirty;
else
++pages_clean;
if (!__wt_ref_is_root(next_walk) &&
!__wt_page_can_evict(session, next_walk, NULL))
++num_not_queueable;
if (F_ISSET_ATOMIC(page, WT_PAGE_EVICT_LRU))
++num_queued;
if (size > max_pagesize)
max_pagesize = size;
dsk_size = page->dsk != NULL ? page->dsk->mem_size : 0;
if (dsk_size != 0) {
if (dsk_size < btree->allocsize)
++num_smaller_allocsz;
if (dsk_size < min_written_size)
min_written_size = dsk_size;
++written_size_cnt;
written_size_sum += dsk_size;
} else
++num_memory;
if (WT_PAGE_IS_INTERNAL(page))
++pages_internal;
else
++pages_leaf;
/* Skip root pages since they are never considered */
if (__wt_ref_is_root(next_walk))
continue;
if (page->evict_pass_gen == 0) {
unvisited_age_gap_sum +=
(cache->evict_pass_gen - page->cache_create_gen);
++unvisited_count;
} else {
visited_age_gap_sum +=
(cache->evict_pass_gen - page->cache_create_gen);
gen_gap = cache->evict_pass_gen - page->evict_pass_gen;
if (gen_gap > gen_gap_max)
gen_gap_max = gen_gap;
gen_gap_sum += gen_gap;
++visited_count;
}
}
WT_STAT_DATA_SET(session, cache_state_gen_avg_gap,
visited_count == 0 ? 0 : gen_gap_sum / visited_count);
WT_STAT_DATA_SET(session, cache_state_avg_unvisited_age,
unvisited_count == 0 ? 0 : unvisited_age_gap_sum / unvisited_count);
WT_STAT_DATA_SET(session, cache_state_avg_visited_age,
visited_count == 0 ? 0 : visited_age_gap_sum / visited_count);
WT_STAT_DATA_SET(session, cache_state_avg_written_size,
written_size_cnt == 0 ? 0 : written_size_sum / written_size_cnt);
WT_STAT_DATA_SET(session, cache_state_gen_max_gap, gen_gap_max);
WT_STAT_DATA_SET(session, cache_state_max_pagesize, max_pagesize);
WT_STAT_DATA_SET(session,
cache_state_min_written_size, min_written_size);
WT_STAT_DATA_SET(session, cache_state_memory, num_memory);
WT_STAT_DATA_SET(session, cache_state_queued, num_queued);
WT_STAT_DATA_SET(session, cache_state_not_queueable, num_not_queueable);
WT_STAT_DATA_SET(session, cache_state_pages, walk_count);
WT_STAT_DATA_SET(session, cache_state_pages_clean, pages_clean);
WT_STAT_DATA_SET(session, cache_state_pages_dirty, pages_dirty);
WT_STAT_DATA_SET(session, cache_state_pages_internal, pages_internal);
WT_STAT_DATA_SET(session, cache_state_pages_leaf, pages_leaf);
WT_STAT_DATA_SET(session,
cache_state_refs_skipped, walk_count - seen_count);
WT_STAT_DATA_SET(session,
cache_state_smaller_alloc_size, num_smaller_allocsz);
WT_STAT_DATA_SET(session,
cache_state_unvisited_count, unvisited_count);
}
/*
* __wt_curstat_cache_walk --
* Initialize the statistics for a cache cache_walk pass.
*/
void
__wt_curstat_cache_walk(WT_SESSION_IMPL *session)
{
WT_BTREE *btree;
WT_CONNECTION_IMPL *conn;
WT_PAGE_INDEX *root_idx;
btree = S2BT(session);
conn = S2C(session);
/* Set statistics that don't require walking the cache. */
WT_STAT_DATA_SET(session,
cache_state_gen_current, conn->cache->evict_pass_gen);
/* Root page statistics */
root_idx = WT_INTL_INDEX_GET_SAFE(btree->root.page);
WT_STAT_DATA_SET(session,
cache_state_root_entries, root_idx->entries);
WT_STAT_DATA_SET(session,
cache_state_root_size, btree->root.page->memory_footprint);
__evict_stat_walk(session);
}
|