Back to index

openldap  2.4.31
mdb_stat.c
Go to the documentation of this file.
00001 /* mdb_stat.c - memory-mapped database status tool */
00002 /*
00003  * Copyright 2011 Howard Chu, Symas Corp.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted only as authorized by the OpenLDAP
00008  * Public License.
00009  *
00010  * A copy of this license is available in the file LICENSE in the
00011  * top-level directory of the distribution or, alternatively, at
00012  * <http://www.OpenLDAP.org/license.html>.
00013  */
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <time.h>
00017 #include "mdb.h"
00018 
00019 int main(int argc,char * argv[])
00020 {
00021        int rc;
00022        MDB_env *env;
00023        MDB_txn *txn;
00024        MDB_dbi dbi;
00025        MDB_stat mst;
00026        char *envname = argv[1];
00027        char *subname = NULL;
00028 
00029        rc = mdb_env_create(&env);
00030 
00031        if (argc > 2) {
00032               mdb_env_set_maxdbs(env, 4);
00033               subname = argv[2];
00034        }
00035 
00036        rc = mdb_env_open(env, envname, MDB_RDONLY, 0);
00037        if (rc) {
00038               printf("mdb_env_open failed, error %d\n", rc);
00039               exit(1);
00040        }
00041        rc = mdb_txn_begin(env, NULL, 1, &txn);
00042        if (rc) {
00043               printf("mdb_txn_begin failed, error %d\n", rc);
00044               exit(1);
00045        }
00046        rc = mdb_open(txn, subname, 0, &dbi);
00047        if (rc) {
00048               printf("mdb_open failed, error %d\n", rc);
00049               exit(1);
00050        }
00051    
00052        rc = mdb_stat(txn, dbi, &mst);
00053        printf("Page size: %u\n", mst.ms_psize);
00054        printf("Tree depth: %u\n", mst.ms_depth);
00055        printf("Branch pages: %zu\n", mst.ms_branch_pages);
00056        printf("Leaf pages: %zu\n", mst.ms_leaf_pages);
00057        printf("Overflow pages: %zu\n", mst.ms_overflow_pages);
00058        printf("Entries: %zu\n", mst.ms_entries);
00059        mdb_close(env, dbi);
00060        mdb_txn_abort(txn);
00061        mdb_env_close(env);
00062 
00063        return 0;
00064 }