]> git.sur5r.net Git - openldap/blob - libraries/libmdb/mdb_stat.c
21b85585c623e7d2a6d1efea3de53dac3e2beec8
[openldap] / libraries / libmdb / mdb_stat.c
1 /* mdb_stat.c - memory-mapped database status tool */
2 /*
3  * Copyright 2011 Howard Chu, Symas Corp.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted only as authorized by the OpenLDAP
8  * Public License.
9  *
10  * A copy of this license is available in the file LICENSE in the
11  * top-level directory of the distribution or, alternatively, at
12  * <http://www.OpenLDAP.org/license.html>.
13  */
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <time.h>
17 #include "mdb.h"
18
19 int main(int argc,char * argv[])
20 {
21         int rc;
22         MDB_env *env;
23         MDB_txn *txn;
24         MDB_dbi dbi;
25         MDB_stat mst;
26         char *envname = argv[1];
27         char *subname = NULL;
28
29         rc = mdb_env_create(&env);
30
31         if (argc > 2) {
32                 mdb_env_set_maxdbs(env, 4);
33                 subname = argv[2];
34         }
35
36         rc = mdb_env_open(env, envname, MDB_RDONLY, 0);
37         if (rc) {
38                 printf("mdb_env_open failed, error %d\n", rc);
39                 exit(1);
40         }
41         rc = mdb_txn_begin(env, 1, &txn);
42         if (rc) {
43                 printf("mdb_txn_begin failed, error %d\n", rc);
44                 exit(1);
45         }
46         rc = mdb_open(txn, subname, 0, &dbi);
47         if (rc) {
48                 printf("mdb_open failed, error %d\n", rc);
49                 exit(1);
50         }
51    
52         rc = mdb_stat(txn, dbi, &mst);
53         printf("Page size: %u\n", mst.ms_psize);
54         printf("Tree depth: %u\n", mst.ms_depth);
55         printf("Branch pages: %lu\n", mst.ms_branch_pages);
56         printf("Leaf pages: %lu\n", mst.ms_leaf_pages);
57         printf("Overflow pages: %lu\n", mst.ms_overflow_pages);
58         printf("Entries: %lu\n", mst.ms_entries);
59         mdb_close(txn, dbi);
60         mdb_txn_abort(txn);
61         mdb_env_close(env);
62
63         return 0;
64 }