2011-08-09 16:13:55 +08:00
|
|
|
/* mdb_stat.c - memory-mapped database status tool */
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Howard Chu, Symas Corp.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
2011-06-28 15:16:05 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "mdb.h"
|
|
|
|
|
|
|
|
int main(int argc,char * argv[])
|
|
|
|
{
|
2011-06-30 03:12:08 +08:00
|
|
|
int rc;
|
2011-06-28 15:16:05 +08:00
|
|
|
MDB_env *env;
|
2011-08-03 16:41:54 +08:00
|
|
|
MDB_txn *txn;
|
|
|
|
MDB_dbi dbi;
|
2011-07-03 19:22:10 +08:00
|
|
|
MDB_stat mst;
|
2011-06-28 15:16:05 +08:00
|
|
|
char *envname = argv[1];
|
|
|
|
char *subname = NULL;
|
|
|
|
|
2011-08-12 12:14:29 +08:00
|
|
|
rc = mdb_env_create(&env);
|
2011-08-11 18:23:22 +08:00
|
|
|
|
|
|
|
if (argc > 2) {
|
2011-08-12 12:14:29 +08:00
|
|
|
mdb_env_set_maxdbs(env, 4);
|
2011-08-11 18:23:22 +08:00
|
|
|
subname = argv[2];
|
|
|
|
}
|
|
|
|
|
2011-08-12 12:14:29 +08:00
|
|
|
rc = mdb_env_open(env, envname, MDB_RDONLY, 0);
|
2011-06-28 15:16:05 +08:00
|
|
|
if (rc) {
|
2011-08-12 12:14:29 +08:00
|
|
|
printf("mdb_env_open failed, error %d\n", rc);
|
2011-06-28 15:16:05 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2011-09-21 03:57:05 +08:00
|
|
|
rc = mdb_txn_begin(env, NULL, 1, &txn);
|
2011-08-03 16:41:54 +08:00
|
|
|
if (rc) {
|
|
|
|
printf("mdb_txn_begin failed, error %d\n", rc);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
rc = mdb_open(txn, subname, 0, &dbi);
|
2011-06-28 15:16:05 +08:00
|
|
|
if (rc) {
|
|
|
|
printf("mdb_open failed, error %d\n", rc);
|
2012-08-24 20:23:55 +08:00
|
|
|
mdb_txn_abort(txn);
|
2011-06-28 15:16:05 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-08-03 16:41:54 +08:00
|
|
|
rc = mdb_stat(txn, dbi, &mst);
|
2011-07-03 19:22:10 +08:00
|
|
|
printf("Page size: %u\n", mst.ms_psize);
|
|
|
|
printf("Tree depth: %u\n", mst.ms_depth);
|
2011-09-11 02:01:07 +08:00
|
|
|
printf("Branch pages: %zu\n", mst.ms_branch_pages);
|
|
|
|
printf("Leaf pages: %zu\n", mst.ms_leaf_pages);
|
|
|
|
printf("Overflow pages: %zu\n", mst.ms_overflow_pages);
|
|
|
|
printf("Entries: %zu\n", mst.ms_entries);
|
2011-09-19 01:38:08 +08:00
|
|
|
mdb_close(env, dbi);
|
2011-08-03 16:41:54 +08:00
|
|
|
mdb_txn_abort(txn);
|
2011-08-12 12:14:29 +08:00
|
|
|
mdb_env_close(env);
|
2011-06-28 15:16:05 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|