summaryrefslogtreecommitdiff
path: root/src/lock/lock_stat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lock/lock_stat.c')
-rw-r--r--src/lock/lock_stat.c208
1 files changed, 112 insertions, 96 deletions
diff --git a/src/lock/lock_stat.c b/src/lock/lock_stat.c
index 11b934aa..1ce0796a 100644
--- a/src/lock/lock_stat.c
+++ b/src/lock/lock_stat.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -15,8 +15,6 @@
#include "dbinc/db_am.h"
#ifdef HAVE_STATISTICS
-static int __lock_dump_locker
- __P((ENV *, DB_MSGBUF *, DB_LOCKTAB *, DB_LOCKER *));
static int __lock_dump_object __P((DB_LOCKTAB *, DB_MSGBUF *, DB_LOCKOBJ *));
static int __lock_print_all __P((ENV *, u_int32_t));
static int __lock_print_stats __P((ENV *, u_int32_t));
@@ -363,6 +361,11 @@ __lock_print_stats(env, flags)
__db_dl(env, "Maximum number of lockers at any one time",
(u_long)sp->st_maxnlockers);
__db_dl(env,
+ "Number of hits in the thread locker cache",
+ (u_long)sp->st_nlockers_hit);
+ __db_dl(env,
+ "Total number of lockers reused", (u_long)sp->st_nlockers_reused);
+ __db_dl(env,
"Number of current lock objects", (u_long)sp->st_nobjects);
__db_dl(env, "Maximum number of lock objects at any one time",
(u_long)sp->st_maxnobjects);
@@ -463,9 +466,17 @@ __lock_print_all(env, flags)
if (timespecisset(&lrp->next_timeout)) {
#ifdef HAVE_STRFTIME
time_t t = (time_t)lrp->next_timeout.tv_sec;
+ struct tm *tm_p;
char tbuf[64];
+#ifdef HAVE_LOCALTIME_R
+ struct tm tm;
+
+ tm_p = localtime_r(&t, &tm);
+#else
+ tm_p = localtime(&t);
+#endif
if (strftime(tbuf, sizeof(tbuf),
- "%m-%d-%H:%M:%S", localtime(&t)) != 0)
+ "%m-%d-%H:%M:%S", tm_p) != 0)
__db_msg(env, "next_timeout: %s.%09lu",
tbuf, (u_long)lrp->next_timeout.tv_nsec);
else
@@ -519,80 +530,6 @@ __lock_print_all(env, flags)
}
static int
-__lock_dump_locker(env, mbp, lt, lip)
- ENV *env;
- DB_MSGBUF *mbp;
- DB_LOCKTAB *lt;
- DB_LOCKER *lip;
-{
- DB_LOCKREGION *lrp;
- struct __db_lock *lp;
- char buf[DB_THREADID_STRLEN];
- u_int32_t ndx;
-
- lrp = lt->reginfo.primary;
-
- __db_msgadd(env,
- mbp, "%8lx dd=%2ld locks held %-4d write locks %-4d pid/thread %s",
- (u_long)lip->id, (long)lip->dd_id, lip->nlocks, lip->nwrites,
- env->dbenv->thread_id_string(env->dbenv, lip->pid, lip->tid, buf));
- __db_msgadd(env, mbp,
- " flags %-4x priority %-10u", lip->flags, lip->priority);
-
- if (timespecisset(&lip->tx_expire)) {
-#ifdef HAVE_STRFTIME
- time_t t = (time_t)lip->tx_expire.tv_sec;
- char tbuf[64];
- if (strftime(tbuf, sizeof(tbuf),
- "%m-%d-%H:%M:%S", localtime(&t)) != 0)
- __db_msgadd(env, mbp, "expires %s.%09lu",
- tbuf, (u_long)lip->tx_expire.tv_nsec);
- else
-#endif
- __db_msgadd(env, mbp, "expires %lu.%09lu",
- (u_long)lip->tx_expire.tv_sec,
- (u_long)lip->tx_expire.tv_nsec);
- }
- if (F_ISSET(lip, DB_LOCKER_TIMEOUT))
- __db_msgadd(
- env, mbp, " lk timeout %lu", (u_long)lip->lk_timeout);
- if (timespecisset(&lip->lk_expire)) {
-#ifdef HAVE_STRFTIME
- time_t t = (time_t)lip->lk_expire.tv_sec;
- char tbuf[64];
- if (strftime(tbuf,
- sizeof(tbuf), "%m-%d-%H:%M:%S", localtime(&t)) != 0)
- __db_msgadd(env, mbp, " lk expires %s.%09lu",
- tbuf, (u_long)lip->lk_expire.tv_nsec);
- else
-#endif
- __db_msgadd(env, mbp, " lk expires %lu.%09lu",
- (u_long)lip->lk_expire.tv_sec,
- (u_long)lip->lk_expire.tv_nsec);
- }
- DB_MSGBUF_FLUSH(env, mbp);
-
- /*
- * We need some care here since the list may change while we
- * look.
- */
-retry: SH_LIST_FOREACH(lp, &lip->heldby, locker_links, __db_lock) {
- if (!SH_LIST_EMPTY(&lip->heldby) && lp != NULL) {
- ndx = lp->indx;
- OBJECT_LOCK_NDX(lt, lrp, ndx);
- if (lp->indx == ndx)
- __lock_printlock(lt, mbp, lp, 1);
- else {
- OBJECT_UNLOCK(lt, lrp, ndx);
- goto retry;
- }
- OBJECT_UNLOCK(lt, lrp, ndx);
- }
- }
- return (0);
-}
-
-static int
__lock_dump_object(lt, mbp, op)
DB_LOCKTAB *lt;
DB_MSGBUF *mbp;
@@ -619,6 +556,31 @@ __lock_print_header(env)
"Count", "Status", "----------------- Object ---------------");
}
+#else /* !HAVE_STATISTICS */
+
+int
+__lock_stat_pp(dbenv, statp, flags)
+ DB_ENV *dbenv;
+ DB_LOCK_STAT **statp;
+ u_int32_t flags;
+{
+ COMPQUIET(statp, NULL);
+ COMPQUIET(flags, 0);
+
+ return (__db_stat_not_built(dbenv->env));
+}
+
+int
+__lock_stat_print_pp(dbenv, flags)
+ DB_ENV *dbenv;
+ u_int32_t flags;
+{
+ COMPQUIET(flags, 0);
+
+ return (__db_stat_not_built(dbenv->env));
+}
+#endif
+
/*
* __lock_printlock --
*
@@ -744,27 +706,81 @@ __lock_printlock(lt, mbp, lp, ispgno)
DB_MSGBUF_FLUSH(env, mbp);
}
-#else /* !HAVE_STATISTICS */
-
+/*
+ * __lock_dump_locker --
+ * Display the identity and statistics of a locker. This is used during
+ * diagnostic error paths as well as when printing statistics.
+ *
+ * PUBLIC: int __lock_dump_locker
+ * PUBLIC: __P((ENV *, DB_MSGBUF *, DB_LOCKTAB *, DB_LOCKER *));
+ */
int
-__lock_stat_pp(dbenv, statp, flags)
- DB_ENV *dbenv;
- DB_LOCK_STAT **statp;
- u_int32_t flags;
+__lock_dump_locker(env, mbp, lt, lip)
+ ENV *env;
+ DB_MSGBUF *mbp;
+ DB_LOCKTAB *lt;
+ DB_LOCKER *lip;
{
- COMPQUIET(statp, NULL);
- COMPQUIET(flags, 0);
+ DB_LOCKREGION *lrp;
+ struct __db_lock *lp;
+ char buf[DB_THREADID_STRLEN];
+ u_int32_t ndx;
- return (__db_stat_not_built(dbenv->env));
-}
+ lrp = lt->reginfo.primary;
-int
-__lock_stat_print_pp(dbenv, flags)
- DB_ENV *dbenv;
- u_int32_t flags;
-{
- COMPQUIET(flags, 0);
+ __db_msgadd(env,
+ mbp, "%8lx dd=%2ld locks held %-4d write locks %-4d pid/thread %s",
+ (u_long)lip->id, (long)lip->dd_id, lip->nlocks, lip->nwrites,
+ env->dbenv->thread_id_string(env->dbenv, lip->pid, lip->tid, buf));
+ __db_msgadd(env, mbp,
+ " flags %-4x priority %-10u", lip->flags, lip->priority);
- return (__db_stat_not_built(dbenv->env));
-}
+ if (timespecisset(&lip->tx_expire)) {
+#ifdef HAVE_STRFTIME
+ time_t t = (time_t)lip->tx_expire.tv_sec;
+ char tbuf[64];
+ if (strftime(tbuf, sizeof(tbuf),
+ "%m-%d-%H:%M:%S", localtime(&t)) != 0)
+ __db_msgadd(env, mbp, "expires %s.%09lu",
+ tbuf, (u_long)lip->tx_expire.tv_nsec);
+ else
#endif
+ __db_msgadd(env, mbp, "expires %lu.%09lu",
+ (u_long)lip->tx_expire.tv_sec,
+ (u_long)lip->tx_expire.tv_nsec);
+ }
+ if (F_ISSET(lip, DB_LOCKER_TIMEOUT))
+ __db_msgadd(
+ env, mbp, " lk timeout %lu", (u_long)lip->lk_timeout);
+ if (timespecisset(&lip->lk_expire)) {
+#ifdef HAVE_STRFTIME
+ time_t t = (time_t)lip->lk_expire.tv_sec;
+ char tbuf[64];
+ if (strftime(tbuf,
+ sizeof(tbuf), "%m-%d-%H:%M:%S", localtime(&t)) != 0)
+ __db_msgadd(env, mbp, " lk expires %s.%09lu",
+ tbuf, (u_long)lip->lk_expire.tv_nsec);
+ else
+#endif
+ __db_msgadd(env, mbp, " lk expires %lu.%09lu",
+ (u_long)lip->lk_expire.tv_sec,
+ (u_long)lip->lk_expire.tv_nsec);
+ }
+ DB_MSGBUF_FLUSH(env, mbp);
+
+ /* We need some care here since the list may change while we look. */
+retry: SH_LIST_FOREACH(lp, &lip->heldby, locker_links, __db_lock) {
+ if (!SH_LIST_EMPTY(&lip->heldby) && lp != NULL) {
+ ndx = lp->indx;
+ OBJECT_LOCK_NDX(lt, lrp, ndx);
+ if (lp->indx == ndx)
+ __lock_printlock(lt, mbp, lp, 1);
+ else {
+ OBJECT_UNLOCK(lt, lrp, ndx);
+ goto retry;
+ }
+ OBJECT_UNLOCK(lt, lrp, ndx);
+ }
+ }
+ return (0);
+}