summaryrefslogtreecommitdiff
path: root/src/utilities/util_stat.c
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2011-04-25 13:54:49 +1000
committerMichael Cahill <michael.cahill@wiredtiger.com>2011-04-25 13:54:49 +1000
commitb9eb1bbb21ff0109b3e28045ca9e86d59ea1ce62 (patch)
tree54c34370693cbca68a7230a516858773a80d8705 /src/utilities/util_stat.c
parentfade055c508735bff9b3d99c7a634289ec0bb5fc (diff)
downloadmongo-b9eb1bbb21ff0109b3e28045ca9e86d59ea1ce62.tar.gz
Remove the internal API, move automatically generated code to the public API.
refs #28 --HG-- rename : dist/api_class.py => dist/api_data.py
Diffstat (limited to 'src/utilities/util_stat.c')
-rw-r--r--src/utilities/util_stat.c67
1 files changed, 50 insertions, 17 deletions
diff --git a/src/utilities/util_stat.c b/src/utilities/util_stat.c
index 1123fd0e728..765126960de 100644
--- a/src/utilities/util_stat.c
+++ b/src/utilities/util_stat.c
@@ -15,14 +15,28 @@ int usage(void);
int
main(int argc, char *argv[])
{
- BTREE *btree;
- int ch, ret, tret, verbose;
+ WT_CONNECTION *conn;
+ WT_SESSION *session;
+ WT_CURSOR *cursor;
+ WT_ITEM key, value;
+ const char *home, *srcname;
+ char cursor_config[100], datasrc[100];
+ int ch, debug, ret, tret, verbose;
WT_UTILITY_INTRO(progname, argv);
- verbose = 0;
- while ((ch = getopt(argc, argv, "Vv")) != EOF)
+ conn = NULL;
+ home = NULL;
+ debug = verbose = 0;
+
+ while ((ch = getopt(argc, argv, "dh:Vv")) != EOF)
switch (ch) {
+ case 'd':
+ debug = 1;
+ break;
+ case 'h': /* home directory */
+ home = optarg;
+ break;
case 'V': /* version */
printf("%s\n", wiredtiger_version(NULL, NULL, NULL));
return (EXIT_SUCCESS);
@@ -39,25 +53,44 @@ main(int argc, char *argv[])
/* The remaining argument is the file name. */
if (argc != 1)
return (usage());
+ srcname = *argv;
- if ((ret = wiredtiger_simple_setup(progname, verbose ?
- __wt_event_handler_verbose : NULL, NULL, &btree)) == 0) {
- if ((ret = btree->open(btree, NULL, *argv, 0, 0)) != 0) {
- fprintf(stderr, "%s: db.open(%s): %s\n",
- progname, *argv, wiredtiger_strerror(ret));
- goto err;
- }
- if ((ret = btree->stat_print(btree, stdout, 0)) != 0) {
- fprintf(stderr, "%s: db.stat(%s): %s\n",
- progname, *argv, wiredtiger_strerror(ret));
- goto err;
- }
+ if ((ret = wiredtiger_open(home, verbose ?
+ __wt_event_handler_verbose : NULL, NULL, &conn)) != 0 ||
+ (ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
+ goto err;
+
+ snprintf(datasrc, sizeof(datasrc), "stat:%s", srcname);
+ snprintf(cursor_config, sizeof(cursor_config), "dump=print%s",
+ debug ? ",debug" : "");
+
+
+ if ((ret = session->open_cursor(session, datasrc, NULL,
+ cursor_config, &cursor)) != 0) {
+ fprintf(stderr, "%s: cursor open(%s) failed: %s\n",
+ progname, datasrc, wiredtiger_strerror(ret));
+ goto err;
+ }
+
+ while ((ret = cursor->next(cursor)) == 0) {
+ cursor->get_key(cursor, &key);
+ fwrite(key.data, key.size, 1, stdout);
+ fwrite("\n", 1, 1, stdout);
+ cursor->get_value(cursor, &value);
+ fwrite(value.data, value.size, 1, stdout);
+ fwrite("\n", 1, 1, stdout);
+ }
+
+ if (ret != WT_NOTFOUND) {
+ fprintf(stderr, "%s: cursor get(%s) failed: %s\n",
+ progname, datasrc, wiredtiger_strerror(ret));
+ goto err;
}
if (0) {
err: ret = 1;
}
- if ((tret = wiredtiger_simple_teardown(progname, btree)) != 0 && ret == 0)
+ if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0)
ret = tret;
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}