diff options
Diffstat (limited to 'db2/progs/db_stat/db_stat.c')
-rw-r--r-- | db2/progs/db_stat/db_stat.c | 182 |
1 files changed, 136 insertions, 46 deletions
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); } |