dbreg_stat.c 2.82 KB
Newer Older
unknown's avatar
unknown committed
1 2 3
/*-
 * See the file LICENSE for redistribution information.
 *
unknown's avatar
unknown committed
4
 * Copyright (c) 1997-2005
unknown's avatar
unknown committed
5 6
 *	Sleepycat Software.  All rights reserved.
 *
unknown's avatar
unknown committed
7
 * $Id: dbreg_stat.c,v 12.5 2005/10/12 15:01:47 margo Exp $
unknown's avatar
unknown committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 */

#include "db_config.h"

#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <string.h>
#endif

#include "db_int.h"
#include "dbinc/db_page.h"
#include "dbinc/db_am.h"
#include "dbinc/log.h"
#include "dbinc/txn.h"

#ifdef HAVE_STATISTICS
unknown's avatar
unknown committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
static int __dbreg_print_dblist __P((DB_ENV *, u_int32_t));

/*
 * __dbreg_stat_print --
 *	Print the dbreg statistics.
 *
 * PUBLIC: int __dbreg_stat_print __P((DB_ENV *, u_int32_t));
 */
int
__dbreg_stat_print(dbenv, flags)
	DB_ENV *dbenv;
	u_int32_t flags;
{
	int ret;

	if (LF_ISSET(DB_STAT_ALL) &&
	    (ret = __dbreg_print_dblist(dbenv, flags)) != 0)
		return (ret);

	return (0);
}

unknown's avatar
unknown committed
46 47 48 49 50 51 52 53 54 55 56
/*
 * __dbreg_print_fname --
 *	Display the contents of an FNAME structure.
 *
 * PUBLIC: void __dbreg_print_fname __P((DB_ENV *, FNAME *));
 */
void
__dbreg_print_fname(dbenv, fnp)
	DB_ENV *dbenv;
	FNAME *fnp;
{
unknown's avatar
unknown committed
57 58 59 60 61 62
	static const FN fn[] = {
		{ DB_FNAME_DURABLE,	"DB_FNAME_DURABLE" },
		{ DB_FNAME_NOTLOGGED,	"DB_FNAME_NOTLOGGED" },
		{ 0,			NULL }
	};

unknown's avatar
unknown committed
63 64 65 66 67 68
	__db_msg(dbenv, "%s", DB_GLOBAL(db_line));
	__db_msg(dbenv, "DB handle FNAME contents:");
	STAT_LONG("log ID", fnp->id);
	STAT_ULONG("Meta pgno", fnp->meta_pgno);
	__db_print_fileid(dbenv, fnp->ufid, "\tFile ID");
	STAT_ULONG("create txn", fnp->create_txnid);
unknown's avatar
unknown committed
69
	__db_prflags(dbenv, NULL, fnp->flags, fn, NULL, "\tFlags");
unknown's avatar
unknown committed
70 71 72 73 74 75
}

/*
 * __dbreg_print_dblist --
 *	Display the DB_ENV's list of files.
 */
unknown's avatar
unknown committed
76
static int
unknown's avatar
unknown committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
__dbreg_print_dblist(dbenv, flags)
	DB_ENV *dbenv;
	u_int32_t flags;
{
	DB *dbp;
	DB_LOG *dblp;
	FNAME *fnp;
	LOG *lp;
	int del, first;
	char *name;

	dblp = dbenv->lg_handle;
	lp = dblp->reginfo.primary;

	__db_msg(dbenv, "%s", DB_GLOBAL(db_line));
	__db_msg(dbenv, "LOG FNAME list:");
unknown's avatar
unknown committed
93 94
	__mutex_print_debug_single(
	    dbenv, "File name mutex", lp->mtx_filelist, flags);
unknown's avatar
unknown committed
95 96 97

	STAT_LONG("Fid max", lp->fid_max);

unknown's avatar
unknown committed
98
	MUTEX_LOCK(dbenv, lp->mtx_filelist);
unknown's avatar
unknown committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
	for (first = 1, fnp = SH_TAILQ_FIRST(&lp->fq, __fname);
	    fnp != NULL; fnp = SH_TAILQ_NEXT(fnp, q, __fname)) {
		if (first) {
			first = 0;
			__db_msg(dbenv,
			    "ID\tName\tType\tPgno\tTxnid\tDBP-info");
		}
		if (fnp->name_off == INVALID_ROFF)
			name = "";
		else
			name = R_ADDR(&dblp->reginfo, fnp->name_off);

		dbp = fnp->id >= dblp->dbentry_cnt ? NULL :
		    dblp->dbentry[fnp->id].dbp;
		del = fnp->id >= dblp->dbentry_cnt ? 0 :
		    dblp->dbentry[fnp->id].deleted;
		__db_msg(dbenv, "%ld\t%s\t%s\t%lu\t%lx\t%s %d %lx %lx",
		    (long)fnp->id, name,
		    __db_dbtype_to_string(fnp->s_type),
		    (u_long)fnp->meta_pgno, (u_long)fnp->create_txnid,
		    dbp == NULL ? "No DBP" : "DBP", del, P_TO_ULONG(dbp),
		    (u_long)(dbp == NULL ? 0 : dbp->flags));
	}
unknown's avatar
unknown committed
122 123 124
	MUTEX_UNLOCK(dbenv, lp->mtx_filelist);

	return (0);
unknown's avatar
unknown committed
125 126
}
#endif