mdbx-tools: add support of page operations stat to mdbx_stat.

This commit is contained in:
Leonid Yuriev 2021-05-12 14:41:09 +03:00
parent 16d686bc42
commit c5268f1da7
3 changed files with 62 additions and 21 deletions

3
mdbx.h
View File

@ -2284,7 +2284,8 @@ struct MDBX_envinfo {
/** Statistics of page operations. /** Statistics of page operations.
* \details Overall statistics of page operations of all (running, completed * \details Overall statistics of page operations of all (running, completed
* and aborted) transactions in the current multi-process session (since the * and aborted) transactions in the current multi-process session (since the
* first process opened the database). */ * first process opened the database after everyone had previously closed it).
*/
struct { struct {
uint64_t newly; /**< Quantity of a new pages added */ uint64_t newly; /**< Quantity of a new pages added */
uint64_t cow; /**< Quantity of pages copied for update */ uint64_t cow; /**< Quantity of pages copied for update */

View File

@ -12,6 +12,8 @@ mdbx_stat \- MDBX environment status tool
[\c [\c
.BR \-q ] .BR \-q ]
[\c [\c
.BR \-p ]
[\c
.BR \-e ] .BR \-e ]
[\c [\c
.BR \-f [ f [ f ]]] .BR \-f [ f [ f ]]]
@ -35,13 +37,18 @@ Write the library version number to the standard output, and exit.
.BR \-q .BR \-q
Be quiet. Be quiet.
.TP .TP
.BR \-p
Display overall statistics of page operations of all (running, completed
and aborted) transactions in the current multi-process session (since the
first process opened the database after everyone had previously closed it).
.TP
.BR \-e .BR \-e
Display information about the database environment. Display information about the database environment.
.TP .TP
.BR \-f .BR \-f
Display information about the environment freelist. Display information about the environment GC.
If \fB\-ff\fP is given, summarize each freelist entry. If \fB\-ff\fP is given, summarize each GC/freelist entry.
If \fB\-fff\fP is given, display the full list of page IDs in the freelist. If \fB\-fff\fP is given, display the full list of page IDs in the GC/freelist.
.TP .TP
.BR \-r .BR \-r
Display information about the environment reader table. Display information about the environment reader table.

View File

@ -57,6 +57,7 @@ static void usage(const char *prog) {
"usage: %s [-V] [-q] [-e] [-f[f[f]]] [-r[r]] [-a|-s name] dbpath\n" "usage: %s [-V] [-q] [-e] [-f[f[f]]] [-r[r]] [-a|-s name] dbpath\n"
" -V\t\tprint version and exit\n" " -V\t\tprint version and exit\n"
" -q\t\tbe quiet\n" " -q\t\tbe quiet\n"
" -p\t\tshow statistics of page operations for current session\n"
" -e\t\tshow whole DB info\n" " -e\t\tshow whole DB info\n"
" -f\t\tshow GC info\n" " -f\t\tshow GC info\n"
" -r\t\tshow readers\n" " -r\t\tshow readers\n"
@ -97,7 +98,7 @@ static void error(const char *func, int rc) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int o, rc; int opt, rc;
MDBX_env *env; MDBX_env *env;
MDBX_txn *txn; MDBX_txn *txn;
MDBX_dbi dbi; MDBX_dbi dbi;
@ -105,21 +106,23 @@ int main(int argc, char *argv[]) {
prog = argv[0]; prog = argv[0];
char *envname; char *envname;
char *subname = nullptr; char *subname = nullptr;
int alldbs = 0, envinfo = 0, envflags = 0, freinfo = 0, rdrinfo = 0; bool alldbs = false, envinfo = false, envflags = false, pgop = false;
int freinfo = 0, rdrinfo = 0;
if (argc < 2) if (argc < 2)
usage(prog); usage(prog);
while ((o = getopt(argc, argv, while ((opt = getopt(argc, argv,
"V" "V"
"q" "q"
"p"
"a" "a"
"e" "e"
"f" "f"
"n" "n"
"r" "r"
"s:")) != EOF) { "s:")) != EOF) {
switch (o) { switch (opt) {
case 'V': case 'V':
printf("mdbx_stat version %d.%d.%d.%d\n" printf("mdbx_stat version %d.%d.%d.%d\n"
" - source: %s %s, commit %s, tree %s\n" " - source: %s %s, commit %s, tree %s\n"
@ -137,22 +140,25 @@ int main(int argc, char *argv[]) {
case 'q': case 'q':
quiet = true; quiet = true;
break; break;
case 'p':
pgop = true;
break;
case 'a': case 'a':
if (subname) if (subname)
usage(prog); usage(prog);
alldbs++; alldbs = true;
break; break;
case 'e': case 'e':
envinfo++; envinfo = true;
break; break;
case 'f': case 'f':
freinfo++; freinfo += 1;
break; break;
case 'n': case 'n':
envflags |= MDBX_NOSUBDIR; envflags |= MDBX_NOSUBDIR;
break; break;
case 'r': case 'r':
rdrinfo++; rdrinfo += 1;
break; break;
case 's': case 's':
if (alldbs) if (alldbs)
@ -215,7 +221,7 @@ int main(int argc, char *argv[]) {
goto txn_abort; goto txn_abort;
} }
if (envinfo || freinfo) { if (envinfo || freinfo || pgop) {
rc = mdbx_env_info_ex(env, txn, &mei, sizeof(mei)); rc = mdbx_env_info_ex(env, txn, &mei, sizeof(mei));
if (unlikely(rc != MDBX_SUCCESS)) { if (unlikely(rc != MDBX_SUCCESS)) {
error("mdbx_env_info_ex", rc); error("mdbx_env_info_ex", rc);
@ -226,6 +232,33 @@ int main(int argc, char *argv[]) {
memset(&mei, 0, sizeof(mei)); memset(&mei, 0, sizeof(mei));
} }
if (pgop) {
printf("Page Operations (for current session):\n");
printf(" New: %8" PRIu64 "\t// quantity of a new pages added\n",
mei.mi_pgop_stat.newly);
printf(" CoW: %8" PRIu64
"\t// quantity of pages copied for altering\n",
mei.mi_pgop_stat.cow);
printf(" Clone: %8" PRIu64 "\t// quantity of parent's dirty pages "
"clones for nested transactions\n",
mei.mi_pgop_stat.clone);
printf(" Split: %8" PRIu64
"\t// page splits during insertions or updates\n",
mei.mi_pgop_stat.split);
printf(" Merge: %8" PRIu64
"\t// page merges during deletions or updates\n",
mei.mi_pgop_stat.merge);
printf(" Spill: %8" PRIu64 "\t// quantity of spilled/ousted `dirty` "
"pages during large transactions\n",
mei.mi_pgop_stat.spill);
printf(" Unspill: %8" PRIu64 "\t// quantity of unspilled/redone `dirty` "
"pages during large transactions\n",
mei.mi_pgop_stat.unspill);
printf(" WOP: %8" PRIu64
"\t// number of explicit write operations (not a pages) to a disk\n",
mei.mi_pgop_stat.wops);
}
if (envinfo) { if (envinfo) {
printf("Environment Info\n"); printf("Environment Info\n");
printf(" Pagesize: %u\n", mei.mi_dxb_pagesize); printf(" Pagesize: %u\n", mei.mi_dxb_pagesize);