2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1996-2002
5
* Sleepycat Software. All rights reserved.
11
static const char revid[] = "$Id$";
14
#ifndef NO_SYSTEM_INCLUDES
15
#include <sys/types.h>
21
#include "dbinc/txn.h"
26
* PUBLIC: int __txn_stat __P((DB_ENV *, DB_TXN_STAT **, u_int32_t));
29
__txn_stat(dbenv, statp, flags)
43
ENV_REQUIRES_CONFIG(dbenv, dbenv->tx_handle, "txn_stat", DB_INIT_TXN);
46
if ((ret = __db_fchk(dbenv,
47
"DB_ENV->txn_stat", flags, DB_STAT_CLEAR)) != 0)
50
mgr = dbenv->tx_handle;
51
region = mgr->reginfo.primary;
54
* Allocate for the maximum active transactions -- the DB_TXN_ACTIVE
55
* struct is small and the maximum number of active transactions is
56
* not going to be that large. Don't have to lock anything to look
57
* at the region's maximum active transactions value, it's read-only
58
* and never changes after the region is created.
60
nbytes = sizeof(DB_TXN_STAT) + sizeof(DB_TXN_ACTIVE) * region->maxtxns;
61
if ((ret = __os_umalloc(dbenv, nbytes, &stats)) != 0)
64
R_LOCK(dbenv, &mgr->reginfo);
65
memcpy(stats, ®ion->stat, sizeof(*stats));
66
stats->st_last_txnid = region->last_txnid;
67
stats->st_last_ckp = region->last_ckp;
68
stats->st_time_ckp = region->time_ckp;
69
stats->st_txnarray = (DB_TXN_ACTIVE *)&stats[1];
72
for (txnp = SH_TAILQ_FIRST(®ion->active_txn, __txn_detail);
74
txnp = SH_TAILQ_NEXT(txnp, links, __txn_detail)) {
75
stats->st_txnarray[ndx].txnid = txnp->txnid;
76
if (txnp->parent == INVALID_ROFF)
77
stats->st_txnarray[ndx].parentid = TXN_INVALID;
79
stats->st_txnarray[ndx].parentid =
80
((TXN_DETAIL *)R_ADDR(&mgr->reginfo,
81
txnp->parent))->txnid;
82
stats->st_txnarray[ndx].lsn = txnp->begin_lsn;
86
stats->st_region_wait = mgr->reginfo.rp->mutex.mutex_set_wait;
87
stats->st_region_nowait = mgr->reginfo.rp->mutex.mutex_set_nowait;
88
stats->st_regsize = mgr->reginfo.rp->size;
89
if (LF_ISSET(DB_STAT_CLEAR)) {
90
mgr->reginfo.rp->mutex.mutex_set_wait = 0;
91
mgr->reginfo.rp->mutex.mutex_set_nowait = 0;
92
memset(®ion->stat, 0, sizeof(region->stat));
93
region->stat.st_maxtxns = region->maxtxns;
94
region->stat.st_maxnactive =
95
region->stat.st_nactive = stats->st_nactive;
98
R_UNLOCK(dbenv, &mgr->reginfo);