1 /* mdb_stat.c - memory-mapped database status tool */
3 * Copyright 2011 Howard Chu, Symas Corp.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted only as authorized by the OpenLDAP
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>.
19 int main(int argc,char * argv[])
28 char *envname = argv[1];
30 rc = mdb_env_create(&env);
32 mdb_env_set_maxdbs(env, 4);
34 rc = mdb_env_open(env, envname, MDB_RDONLY, 0);
36 printf("mdb_env_open failed, error %d\n", rc);
39 rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
41 printf("mdb_txn_begin failed, error %d\n", rc);
44 rc = mdb_open(txn, NULL, 0, &dbi);
46 printf("mdb_open failed, error %d\n", rc);
50 rc = mdb_stat(txn, dbi, &mst);
51 printf("Page size: %u\n", mst.ms_psize);
52 printf("Tree depth: %u\n", mst.ms_depth);
53 printf("Branch pages: %zu\n", mst.ms_branch_pages);
54 printf("Leaf pages: %zu\n", mst.ms_leaf_pages);
55 printf("Overflow pages: %zu\n", mst.ms_overflow_pages);
56 printf("Entries: %zu\n", mst.ms_entries);
58 rc = mdb_cursor_open(txn, dbi, &cursor);
59 while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT)) == 0) {
60 char *str = malloc(key.mv_size+1);
62 memcpy(str, key.mv_data, key.mv_size);
63 str[key.mv_size] = '\0';
64 printf("\n%s\n", str);
65 rc = mdb_open(txn, str, 0, &db2);
68 rc = mdb_stat(txn, db2, &mst);
69 printf("Tree depth: %u\n", mst.ms_depth);
70 printf("Branch pages: %zu\n", mst.ms_branch_pages);
71 printf("Leaf pages: %zu\n", mst.ms_leaf_pages);
72 printf("Overflow pages: %zu\n", mst.ms_overflow_pages);
73 printf("Entries: %zu\n", mst.ms_entries);
76 mdb_cursor_close(cursor);
83 return rc ? EXIT_FAILURE : EXIT_SUCCESS;