]> git.sur5r.net Git - openldap/blob - libraries/libmdb/mdb_stat.c
Add some legalese
[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         if (argc > 2)
30                 subname = argv[2];
31    
32         rc = mdbenv_create(&env);
33         rc = mdbenv_open(env, envname, MDB_RDONLY, 0);
34         if (rc) {
35                 printf("mdbenv_open failed, error %d\n", rc);
36                 exit(1);
37         }
38         rc = mdb_txn_begin(env, 1, &txn);
39         if (rc) {
40                 printf("mdb_txn_begin failed, error %d\n", rc);
41                 exit(1);
42         }
43         rc = mdb_open(txn, subname, 0, &dbi);
44         if (rc) {
45                 printf("mdb_open failed, error %d\n", rc);
46                 exit(1);
47         }
48    
49         rc = mdb_stat(txn, dbi, &mst);
50         printf("Page size: %u\n", mst.ms_psize);
51         printf("Tree depth: %u\n", mst.ms_depth);
52         printf("Branch pages: %lu\n", mst.ms_branch_pages);
53         printf("Leaf pages: %lu\n", mst.ms_leaf_pages);
54         printf("Overflow pages: %lu\n", mst.ms_overflow_pages);
55         printf("Entries: %lu\n", mst.ms_entries);
56         mdb_close(txn, dbi);
57         mdb_txn_abort(txn);
58         mdbenv_close(env);
59
60         return 0;
61 }