about summary refs log tree commit diff
path: root/db2/progs
diff options
context:
space:
mode:
Diffstat (limited to 'db2/progs')
-rw-r--r--db2/progs/db_deadlock/db_deadlock.c24
-rw-r--r--db2/progs/db_dump/db_dump.c2
-rw-r--r--db2/progs/db_load/db_load.c8
-rw-r--r--db2/progs/db_recover/db_recover.c4
-rw-r--r--db2/progs/db_stat/db_stat.c182
5 files changed, 158 insertions, 62 deletions
diff --git a/db2/progs/db_deadlock/db_deadlock.c b/db2/progs/db_deadlock/db_deadlock.c
index ec2b53dee7..473e5b9cb2 100644
--- a/db2/progs/db_deadlock/db_deadlock.c
+++ b/db2/progs/db_deadlock/db_deadlock.c
@@ -11,7 +11,7 @@
 static const char copyright[] =
 "@(#) Copyright (c) 1997\n\
 	Sleepycat Software Inc.  All rights reserved.\n";
-static const char sccsid[] = "@(#)db_deadlock.c	10.15 (Sleepycat) 9/4/97";
+static const char sccsid[] = "@(#)db_deadlock.c	10.16 (Sleepycat) 10/14/97";
 #endif
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -53,13 +53,13 @@ main(argc, argv)
 	DB_ENV *dbenv;
 	u_int32_t atype;
 	time_t now;
-	long seconds;
+	long usecs;
 	int ch, flags, verbose;
 	char *home, *logfile;
 
 	atype = DB_LOCK_DEFAULT;
 	home = logfile = NULL;
-	seconds = 0;
+	usecs = 0;
 	flags = verbose = 0;
 	while ((ch = getopt(argc, argv, "a:h:L:t:vw")) != EOF)
 		switch (ch) {
@@ -85,7 +85,8 @@ main(argc, argv)
 			logfile = optarg;
 			break;
 		case 't':
-			get_long(optarg, 1, LONG_MAX, &seconds);
+			get_long(optarg, 1, LONG_MAX, &usecs);
+			usecs *= 1000000;
 			break;
 		case 'v':
 			verbose = 1;
@@ -103,16 +104,17 @@ main(argc, argv)
 	if (argc != 0)
 		usage();
 
-	if (seconds == 0 && !LF_ISSET(DB_LOCK_CONFLICT)) {
+	if (usecs == 0 && !LF_ISSET(DB_LOCK_CONFLICT)) {
 		warnx("at least one of -t and -w must be specified");
 		usage();
 	}
 
 	/*
-	 * We detect every second when we're running in DB_LOCK_CONFLICT mode.
+	 * We detect every 100ms (100000 us) when we're running in
+	 * DB_LOCK_CONFLICT mode.
 	 */
-	if (seconds == 0)
-		seconds = 1;
+	if (usecs == 0)
+		usecs = 100000;
 
 	/* Initialize the deadlock detector by opening the lock manager. */
 	dbenv = db_init(home, verbose);
@@ -125,14 +127,14 @@ main(argc, argv)
 	while (!interrupted) {
 		if (dbenv->db_verbose != 0) {
 			time(&now);
-			__db_err(dbenv, "Running at %s", ctime(&now));
+			__db_err(dbenv, "Running at %.24s", ctime(&now));
 		}
 
 		if ((errno = lock_detect(dbenv->lk_info, flags, atype)) != 0)
 			break;
 
-		/* Make a pass every "seconds" seconds. */
-		(void)__db_sleep(seconds, 0);
+		/* Make a pass every "usecs" usecs. */
+		(void)__db_sleep(0, usecs);
 	}
 
 	if (logfile != NULL)
diff --git a/db2/progs/db_dump/db_dump.c b/db2/progs/db_dump/db_dump.c
index a0f60c69a6..c09719059b 100644
--- a/db2/progs/db_dump/db_dump.c
+++ b/db2/progs/db_dump/db_dump.c
@@ -31,6 +31,8 @@ static const char sccsid[] = "@(#)db_dump.c	10.16 (Sleepycat) 8/27/97";
 #include "hash.h"
 #include "clib_ext.h"
 
+#undef stat
+
 void	configure __P((char *));
 DB_ENV *db_init __P((char *));
 void	dbt_dump __P((DBT *));
diff --git a/db2/progs/db_load/db_load.c b/db2/progs/db_load/db_load.c
index a1ebfa8a11..6597f10e10 100644
--- a/db2/progs/db_load/db_load.c
+++ b/db2/progs/db_load/db_load.c
@@ -11,7 +11,7 @@
 static const char copyright[] =
 "@(#) Copyright (c) 1997\n\
 	Sleepycat Software Inc.  All rights reserved.\n";
-static const char sccsid[] = "@(#)db_load.c	10.13 (Sleepycat) 9/15/97";
+static const char sccsid[] = "@(#)db_load.c	10.14 (Sleepycat) 10/19/97";
 #endif
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -352,7 +352,7 @@ dbt_rprint(dbtp)
 				escape = 1;
 				continue;
 			}
-		if (++len >= dbtp->ulen - 10) {
+		if (len >= dbtp->ulen - 10) {
 			dbtp->ulen *= 2;
 			if ((dbtp->data =
 			    (void *)realloc(dbtp->data, dbtp->ulen)) == NULL) {
@@ -361,6 +361,7 @@ dbt_rprint(dbtp)
 			}
 			p = (u_int8_t *)dbtp->data + len;
 		}
+		++len;
 		*p++ = c1;
 	}
 	dbtp->size = len;
@@ -420,7 +421,7 @@ dbt_rdump(dbtp)
 		}
 		if ((c2 = getchar()) == EOF)
 			err(1, "unexpected end of key/data pair");
-		if (++len >= dbtp->ulen - 10) {
+		if (len >= dbtp->ulen - 10) {
 			dbtp->ulen *= 2;
 			if ((dbtp->data =
 			    (void *)realloc(dbtp->data, dbtp->ulen)) == NULL) {
@@ -429,6 +430,7 @@ dbt_rdump(dbtp)
 			}
 			p = (u_int8_t *)dbtp->data + len;
 		}
+		++len;
 		*p++ = digitize(c1) << 4 | digitize(c2);
 	}
 	dbtp->size = len;
diff --git a/db2/progs/db_recover/db_recover.c b/db2/progs/db_recover/db_recover.c
index 55b9b49a79..5a39d320f8 100644
--- a/db2/progs/db_recover/db_recover.c
+++ b/db2/progs/db_recover/db_recover.c
@@ -11,7 +11,7 @@
 static const char copyright[] =
 "@(#) Copyright (c) 1997\n\
 	Sleepycat Software Inc.  All rights reserved.\n";
-static const char sccsid[] = "@(#)db_recover.c	10.15 (Sleepycat) 9/21/97";
+static const char sccsid[] = "@(#)db_recover.c	10.16 (Sleepycat) 10/28/97";
 #endif
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -82,7 +82,7 @@ main(argc, argv)
 		    (u_long)dbenv->tx_info->region->last_ckp.offset);
 	}
 
-	exit (db_appexit(dbenv));
+	return (db_appexit(dbenv));
 }
 
 DB_ENV *
diff --git a/db2/progs/db_stat/db_stat.c b/db2/progs/db_stat/db_stat.c
index 1a989f4df3..b1f1615fa9 100644
--- a/db2/progs/db_stat/db_stat.c
+++ b/db2/progs/db_stat/db_stat.c
@@ -11,7 +11,7 @@
 static const char copyright[] =
 "@(#) Copyright (c) 1997\n\
 	Sleepycat Software Inc.  All rights reserved.\n";
-static const char sccsid[] = "@(#)db_stat.c	8.20 (Sleepycat) 8/27/97";
+static const char sccsid[] = "@(#)db_stat.c	8.26 (Sleepycat) 11/2/97";
 #endif
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -29,18 +29,22 @@ static const char sccsid[] = "@(#)db_stat.c	8.20 (Sleepycat) 8/27/97";
 #include "db_int.h"
 #include "clib_ext.h"
 
+#undef stat
+
+#define	MB	1048576
 #define	DIVIDER	"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
 
-typedef enum { T_NOTSET, T_DB, T_MPOOL, T_TXN } test_t;
+typedef enum { T_NOTSET, T_DB, T_LOG, T_MPOOL, T_TXN } test_t;
 
-void	bstat __P((DB *));
+void	btree_stats __P((DB *));
 DB_ENV *db_init __P((char *, test_t));
-void	hstat __P((DB *));
+void	hash_stats __P((DB *));
 int	main __P((int, char *[]));
-void	mstat __P((DB_ENV *));
+void	log_stats __P((DB_ENV *));
+void	mpool_stats __P((DB_ENV *));
 void	onint __P((int));
 void	prflags __P((u_int32_t, const FN *));
-void	tstat __P((DB_ENV *));
+void	txn_stats __P((DB_ENV *));
 int	txn_compare __P((const void *, const void *));
 void	usage __P((void));
 
@@ -63,7 +67,7 @@ main(argc, argv)
 
 	ttype = T_NOTSET;
 	db = home = NULL;
-	while ((ch = getopt(argc, argv, "d:h:mt")) != EOF)
+	while ((ch = getopt(argc, argv, "d:h:lmt")) != EOF)
 		switch (ch) {
 		case 'd':
 			db = optarg;
@@ -72,6 +76,9 @@ main(argc, argv)
 		case 'h':
 			home = optarg;
 			break;
+		case 'l':
+			ttype = T_LOG;
+			break;
 		case 'm':
 			ttype = T_MPOOL;
 			break;
@@ -100,10 +107,10 @@ main(argc, argv)
 		switch (dbp->type) {
 		case DB_BTREE:
 		case DB_RECNO:
-			bstat(dbp);
+			btree_stats(dbp);
 			break;
 		case DB_HASH:
-			hstat(dbp);
+			hash_stats(dbp);
 			break;
 		case DB_UNKNOWN:
 			abort();		/* Impossible. */
@@ -111,11 +118,14 @@ main(argc, argv)
 		}
 		(void)dbp->close(dbp, 0);
 		break;
+	case T_LOG:
+		log_stats(dbenv);
+		break;
 	case T_MPOOL:
-		mstat(dbenv);
+		mpool_stats(dbenv);
 		break;
 	case T_TXN:
-		tstat(dbenv);
+		txn_stats(dbenv);
 		break;
 	case T_NOTSET:
 		abort();			/* Impossible. */
@@ -133,11 +143,11 @@ main(argc, argv)
 }
 
 /*
- * bstat --
+ * btree_stats --
  *	Display btree/recno statistics.
  */
 void
-bstat(dbp)
+btree_stats(dbp)
 	DB *dbp;
 {
 	static const FN fn[] = {
@@ -156,6 +166,8 @@ bstat(dbp)
     (t == 0 ? 0 :							\
     (((double)((t * sp->bt_pagesize) - f) / (t * sp->bt_pagesize)) * 100))
 
+	printf("%#lx\tBtree magic number.\n", (u_long)sp->bt_magic);
+	printf("%lu\tBtree version number.\n", (u_long)sp->bt_version);
 	prflags(sp->bt_flags, fn);
 	if (dbp->type == DB_BTREE) {
 #ifdef NOT_IMPLEMENTED
@@ -213,22 +225,56 @@ printf("%lu\tNumber of bytes free in tree overflow pages (%.0f%% ff).\n",
 }
 
 /*
- * hstat --
+ * hash_stats --
  *	Display hash statistics.
  */
 void
-hstat(dbp)
+hash_stats(dbp)
 	DB *dbp;
 {
 	return;
 }
 
 /*
- * mstat --
+ * log_stats --
+ *	Display log statistics.
+ */
+void
+log_stats(dbenv)
+	DB_ENV *dbenv;
+{
+	DB_LOG_STAT *sp;
+
+	if (log_stat(dbenv->lg_info, &sp, NULL))
+		err(1, NULL);
+
+	printf("%#lx\tLog magic number.\n", (u_long)sp->st_magic);
+	printf("%lu\tLog version number.\n", (u_long)sp->st_version);
+	printf("%#o\tLog file mode.\n", sp->st_mode);
+	if (sp->st_lg_max % MB == 0)
+		printf("%luMb\tLog file size.\n", (u_long)sp->st_lg_max / MB);
+	else if (sp->st_lg_max % 1024 == 0)
+		printf("%luKb\tLog file size.\n", (u_long)sp->st_lg_max / 1024);
+	else
+		printf("%lu\tLog file size.\n", (u_long)sp->st_lg_max);
+	printf("%luMb\tLog bytes written (+%lu bytes).\n",
+	    (u_long)sp->st_w_mbytes, (u_long)sp->st_w_bytes);
+	printf("%luMb\tLog bytes written since last checkpoint (+%lu bytes).\n",
+	    (u_long)sp->st_wc_mbytes, (u_long)sp->st_wc_bytes);
+	printf("%lu\tTotal log file writes.\n", (u_long)sp->st_wcount);
+	printf("%lu\tTotal log file flushes.\n", (u_long)sp->st_scount);
+	printf("%lu\tThe number of region locks granted without waiting.\n",
+	    (u_long)sp->st_region_nowait);
+	printf("%lu\tThe number of region locks granted after waiting.\n",
+	    (u_long)sp->st_region_wait);
+}
+
+/*
+ * mpool_stats --
  *	Display mpool statistics.
  */
 void
-mstat(dbenv)
+mpool_stats(dbenv)
 	DB_ENV *dbenv;
 {
 	DB_MPOOL_FSTAT **fsp;
@@ -239,62 +285,75 @@ mstat(dbenv)
 
 	printf("%lu\tCache size (%luK).\n",
 	    (u_long)gsp->st_cachesize, (u_long)gsp->st_cachesize / 1024);
-	printf("%lu\tRequested pages found in the cache", gsp->st_cache_hit);
+	printf("%lu\tRequested pages found in the cache",
+	    (u_long)gsp->st_cache_hit);
 	if (gsp->st_cache_hit + gsp->st_cache_miss != 0)
 		printf(" (%.0f%%)", ((double)gsp->st_cache_hit /
 		    (gsp->st_cache_hit + gsp->st_cache_miss)) * 100);
 	printf(".\n");
 	printf("%lu\tRequested pages mapped into the process' address space.\n",
-	    gsp->st_map);
+	    (u_long)gsp->st_map);
 	printf("%lu\tRequested pages not found in the cache.\n",
-	    gsp->st_cache_miss);
-	printf("%lu\tPages created in the cache.\n", gsp->st_page_create);
-	printf("%lu\tPages read into the cache.\n", gsp->st_page_in);
+	    (u_long)gsp->st_cache_miss);
+	printf("%lu\tPages created in the cache.\n",
+	    (u_long)gsp->st_page_create);
+	printf("%lu\tPages read into the cache.\n", (u_long)gsp->st_page_in);
 	printf("%lu\tPages written from the cache to the backing file.\n",
-	    gsp->st_page_out);
-	printf("%lu\tRead-only pages forced from the cache.\n",
-	    gsp->st_ro_evict);
-	printf("%lu\tRead-write pages forced from the cache.\n",
-	    gsp->st_rw_evict);
+	    (u_long)gsp->st_page_out);
+	printf("%lu\tClean pages forced from the cache.\n",
+	    (u_long)gsp->st_ro_evict);
+	printf("%lu\tDirty pages forced from the cache.\n",
+	    (u_long)gsp->st_rw_evict);
+	printf("%lu\tDirty buffers written by trickle-sync thread.\n",
+	    (u_long)gsp->st_page_trickle);
+	printf("%lu\tCurrent clean buffer count.\n",
+	    (u_long)gsp->st_page_clean);
+	printf("%lu\tCurrent dirty buffer count.\n",
+	    (u_long)gsp->st_page_dirty);
 	printf("%lu\tNumber of hash buckets used for page location.\n",
-	    gsp->st_hash_buckets);
+	    (u_long)gsp->st_hash_buckets);
 	printf("%lu\tTotal number of times hash chains searched for a page.\n",
-	    gsp->st_hash_searches);
+	    (u_long)gsp->st_hash_searches);
 	printf("%lu\tThe longest hash chain searched for a page.\n",
-	    gsp->st_hash_longest);
+	    (u_long)gsp->st_hash_longest);
 	printf(
 	    "%lu\tTotal number of hash buckets examined for page location.\n",
-	    gsp->st_hash_examined);
+	    (u_long)gsp->st_hash_examined);
+	printf("%lu\tThe number of region locks granted without waiting.\n",
+	    (u_long)gsp->st_region_nowait);
+	printf("%lu\tThe number of region locks granted after waiting.\n",
+	    (u_long)gsp->st_region_wait);
 
 	for (; fsp != NULL && *fsp != NULL; ++fsp) {
 		printf("%s\n", DIVIDER);
 		printf("%s\n", (*fsp)->file_name);
 		printf("%lu\tPage size.\n", (u_long)(*fsp)->st_pagesize);
 		printf("%lu\tRequested pages found in the cache",
-		    (*fsp)->st_cache_hit);
+		    (u_long)(*fsp)->st_cache_hit);
 		if ((*fsp)->st_cache_hit + (*fsp)->st_cache_miss != 0)
 			printf(" (%.0f%%)", ((double)(*fsp)->st_cache_hit /
 			    ((*fsp)->st_cache_hit + (*fsp)->st_cache_miss)) *
 			    100);
 		printf(".\n");
 	printf("%lu\tRequested pages mapped into the process' address space.\n",
-		    (*fsp)->st_map);
+		    (u_long)(*fsp)->st_map);
 		printf("%lu\tRequested pages not found in the cache.\n",
-		    (*fsp)->st_cache_miss);
+		    (u_long)(*fsp)->st_cache_miss);
 		printf("%lu\tPages created in the cache.\n",
-		    (*fsp)->st_page_create);
-		printf("%lu\tPages read into the cache.\n", (*fsp)->st_page_in);
+		    (u_long)(*fsp)->st_page_create);
+		printf("%lu\tPages read into the cache.\n",
+		    (u_long)(*fsp)->st_page_in);
 	printf("%lu\tPages written from the cache to the backing file.\n",
-		    (*fsp)->st_page_out);
+		    (u_long)(*fsp)->st_page_out);
 	}
 }
 
 /*
- * tstat --
+ * txn_stats --
  *	Display transaction statistics.
  */
 void
-tstat(dbenv)
+txn_stats(dbenv)
 	DB_ENV *dbenv;
 {
 	DB_TXN_STAT *tstat;
@@ -311,7 +370,7 @@ tstat(dbenv)
 	p = tstat->st_pending_ckp.file == 0 ?
 	    "No pending checkpoint LSN." :
 	    "File/offset for last pending checkpoint LSN.";
-	printf("%lu/%lu\t%s.\n",
+	printf("%lu/%lu\t%s\n",
 	    (u_long)tstat->st_pending_ckp.file,
 	    (u_long)tstat->st_pending_ckp.offset, p);
 	if (tstat->st_time_ckp == 0)
@@ -391,27 +450,58 @@ db_init(home, ttype)
 	DB_ENV *dbenv;
 	int flags;
 
+	if ((dbenv = (DB_ENV *)malloc(sizeof(DB_ENV))) == NULL) {
+		errno = ENOMEM;
+		err(1, NULL);
+	}
+
+	/*
+	 * Try and use the shared regions when reporting statistics on the
+	 * DB databases, so our information is as up-to-date as possible,
+	 * even if the mpool cache hasn't been flushed.  If that fails, we
+	 * turn off the DB_INIT_MPOOL flag and try again.
+	 */
 	flags = DB_USE_ENVIRON;
 	switch (ttype) {
+	case T_DB:
 	case T_MPOOL:
 		flags |= DB_INIT_MPOOL;
 		break;
+	case T_LOG:
+		flags |= DB_INIT_LOG;
+		break;
 	case T_TXN:
 		flags |= DB_INIT_TXN;
 		break;
-	default:
-		break;
+	case T_NOTSET:
+		abort();
+		/* NOTREACHED */
 	}
 
-	if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) {
-		errno = ENOMEM;
-		err(1, NULL);
+	/*
+	 * If it works, we're done.  Set the error output options so that
+	 * future errors are correctly reported.
+	 */
+	memset(dbenv, 0, sizeof(*dbenv));
+	if ((errno = db_appinit(home, NULL, dbenv, flags)) == 0) {
+		dbenv->db_errfile = stderr;
+		dbenv->db_errpfx = progname;
+		return (dbenv);
 	}
+
+	/* Turn off the DB_INIT_MPOOL flag if it's a database. */
+	if (ttype == T_DB)
+		flags &= ~DB_INIT_MPOOL;
+
+	/* Set the error output options -- this time we want a message. */
+	memset(dbenv, 0, sizeof(*dbenv));
 	dbenv->db_errfile = stderr;
 	dbenv->db_errpfx = progname;
 
+	/* Try again, and it's fatal if we fail. */
 	if ((errno = db_appinit(home, NULL, dbenv, flags)) != 0)
 		err(1, "db_appinit");
+
 	return (dbenv);
 }
 
@@ -430,6 +520,6 @@ onint(signo)
 void
 usage()
 {
-	fprintf(stderr, "usage: db_stat [-mt] [-d file] [-h home]\n");
+	fprintf(stderr, "usage: db_stat [-mlt] [-d file] [-h home]\n");
 	exit (1);
 }