Skip to content

Commit

Permalink
Merge pull request #2012 from wiredtiger/stat-size
Browse files Browse the repository at this point in the history
Add a "statistics=(size)" mode to statistics cursors
  • Loading branch information
keithbostic committed Jun 6, 2015
2 parents 944ccd1 + 74cea87 commit d4fc69a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 23 deletions.
32 changes: 16 additions & 16 deletions dist/api_data.py
Expand Up @@ -774,22 +774,22 @@ def __cmp__(self, other):
type='boolean', undoc=True),
Config('statistics', '', r'''
Specify the statistics to be gathered. Choosing "all" gathers
statistics regardless of cost and may include traversing
on-disk files; "fast" gathers a subset of relatively
inexpensive statistics. The selection must agree with the
database \c statistics configuration specified to
::wiredtiger_open or WT_CONNECTION::reconfigure. For example,
"all" or "fast" can be configured when the database is
configured with "all", but the cursor open will fail if "all"
is specified when the database is configured with "fast",
and the cursor open will fail in all cases when the database
is configured with "none". If \c statistics is not configured,
the default configuration is the database configuration.
The "clear" configuration resets statistics after gathering
them, where appropriate (for example, a cache size statistic
is not cleared, while the count of cursor insert operations
will be cleared). See @ref statistics for more information''',
type='list', choices=['all', 'fast', 'clear']),
statistics regardless of cost and may include traversing on-disk files;
"fast" gathers a subset of relatively inexpensive statistics. The
selection must agree with the database \c statistics configuration
specified to ::wiredtiger_open or WT_CONNECTION::reconfigure. For
example, "all" or "fast" can be configured when the database is
configured with "all", but the cursor open will fail if "all" is
specified when the database is configured with "fast", and the cursor
open will fail in all cases when the database is configured with
"none". If "size" is configured, only the underlying size of the
object on disk is filled in and the object is not opened. If \c
statistics is not configured, the default configuration is the database
configuration. The "clear" configuration resets statistics after
gathering them, where appropriate (for example, a cache size statistic
is not cleared, while the count of cursor insert operations will be
cleared). See @ref statistics for more information''',
type='list', choices=['all', 'fast', 'clear', 'size']),
Config('target', '', r'''
if non-empty, backup the list of objects; valid only for a
backup data source''',
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_def.c
Expand Up @@ -289,7 +289,7 @@ static const WT_CONFIG_CHECK confchk_WT_SESSION_open_cursor[] = {
{ "readonly", "boolean", NULL, NULL, NULL, 0 },
{ "skip_sort_check", "boolean", NULL, NULL, NULL, 0 },
{ "statistics", "list",
NULL, "choices=[\"all\",\"fast\",\"clear\"]",
NULL, "choices=[\"all\",\"fast\",\"clear\",\"size\"]",
NULL, 0 },
{ "target", "list", NULL, NULL, NULL, 0 },
{ NULL, NULL, NULL, NULL, NULL, 0 }
Expand Down
35 changes: 34 additions & 1 deletion src/cursor/cur_stat.c
Expand Up @@ -373,6 +373,25 @@ __curstat_file_init(WT_SESSION_IMPL *session,
{
WT_DATA_HANDLE *dhandle;
WT_DECL_RET;
wt_off_t filesize;

/*
* If we are only getting the size of the file, we don't need to open
* the tree.
*/
if (F_ISSET(cst, WT_CONN_STAT_SIZE)) {
if (!WT_PREFIX_SKIP(uri, "file:"))
WT_RET_MSG(session, EINVAL,
"incorrect URI %s passed to file-specific call",
uri);

WT_RET(__wt_filesize_name(session, uri, &filesize));

__wt_stat_init_dsrc_stats(&cst->u.dsrc_stats);
cst->u.dsrc_stats.block_size.v = (uint64_t)filesize;
__wt_curstat_dsrc_final(cst);
return (0);
}

WT_RET(__wt_session_get_btree_ckpt(session, uri, cfg, 0));
dhandle = session->dhandle;
Expand Down Expand Up @@ -508,8 +527,22 @@ __wt_curstat_open(WT_SESSION_IMPL *session,
}
WT_ERR_NOTFOUND_OK(ret);
if ((ret = __wt_config_subgets(
session, &cval, "clear", &sval)) == 0 && sval.val != 0)
session, &cval, "size", &sval)) == 0 && sval.val != 0) {
if (F_ISSET(cst, WT_CONN_STAT_FAST | WT_CONN_STAT_ALL))
WT_ERR_MSG(session, EINVAL,
"only one statistics configuration value "
"may be specified");
F_SET(cst, WT_CONN_STAT_SIZE);
}
WT_ERR_NOTFOUND_OK(ret);
if ((ret = __wt_config_subgets(
session, &cval, "clear", &sval)) == 0 && sval.val != 0) {
if (F_ISSET(cst, WT_CONN_STAT_SIZE))
WT_ERR_MSG(session, EINVAL,
"clear is incompatible with size "
"statistics");
F_SET(cst, WT_CONN_STAT_CLEAR);
}
WT_ERR_NOTFOUND_OK(ret);

/* If no configuration, use the connection's configuration. */
Expand Down
1 change: 1 addition & 0 deletions src/include/connection.h
Expand Up @@ -286,6 +286,7 @@ struct __wt_connection_impl {
#define WT_CONN_STAT_FAST 0x04 /* "fast" statistics configured */
#define WT_CONN_STAT_NONE 0x08 /* don't gather statistics */
#define WT_CONN_STAT_ON_CLOSE 0x10 /* output statistics on close */
#define WT_CONN_STAT_SIZE 0x20 /* "size" statistics configured */
uint32_t stat_flags;

WT_CONNECTION_STATS stats; /* Connection statistics */
Expand Down
6 changes: 4 additions & 2 deletions src/include/wiredtiger.in
Expand Up @@ -946,14 +946,16 @@ struct __wt_session {
* configured when the database is configured with "all"\, but the
* cursor open will fail if "all" is specified when the database is
* configured with "fast"\, and the cursor open will fail in all cases
* when the database is configured with "none". If \c statistics is not
* when the database is configured with "none". If "size" is
* configured\, only the underlying size of the object on disk is filled
* in and the object is not opened. If \c statistics is not
* configured\, the default configuration is the database configuration.
* The "clear" configuration resets statistics after gathering them\,
* where appropriate (for example\, a cache size statistic is not
* cleared\, while the count of cursor insert operations will be
* cleared). See @ref statistics for more information., a list\, with
* values chosen from the following options: \c "all"\, \c "fast"\, \c
* "clear"; default empty.}
* "clear"\, \c "size"; default empty.}
* @config{target, if non-empty\, backup the list of objects; valid only
* for a backup data source., a list of strings; default empty.}
* @configend
Expand Down
7 changes: 4 additions & 3 deletions src/lsm/lsm_stat.c
Expand Up @@ -40,11 +40,12 @@ __curstat_lsm_init(
/* Propagate all, fast and/or clear to the cursors we open. */
if (!F_ISSET(cst, WT_CONN_STAT_NONE)) {
(void)snprintf(config, sizeof(config),
"statistics=(%s%s%s)",
F_ISSET(cst, WT_CONN_STAT_CLEAR) ? "clear," : "",
"statistics=(%s%s%s%s)",
F_ISSET(cst, WT_CONN_STAT_ALL) ? "all," : "",
F_ISSET(cst, WT_CONN_STAT_CLEAR) ? "clear," : "",
!F_ISSET(cst, WT_CONN_STAT_ALL) &&
F_ISSET(cst, WT_CONN_STAT_FAST) ? "fast," : "");
F_ISSET(cst, WT_CONN_STAT_FAST) ? "fast," : "",
F_ISSET(cst, WT_CONN_STAT_SIZE) ? "size," : "");
cfg[1] = disk_cfg[1] = config;
}

Expand Down
6 changes: 6 additions & 0 deletions test/suite/test_stat01.py
Expand Up @@ -136,6 +136,12 @@ def test_basic_data_source_stats(self):
self.assertEqual(val, values[2])
cursor.close()

cursor = self.session.open_cursor(
'statistics:' + self.uri, None, "statistics=(size)")
values = cursor[stat.dsrc.block_size]
self.assertNotEqual(values[2], 0)
cursor.close()

# Test simple per-checkpoint statistics.
def test_checkpoint_stats(self):
for name in ('first', 'second', 'third'):
Expand Down

0 comments on commit d4fc69a

Please sign in to comment.