mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-09 07:12:11 -04:00
ISC_MUTEX_PROFILE can be set to enable basic mutex profiling. Running named
with -s prints the results.
This commit is contained in:
parent
253ab81bf2
commit
3f160155da
7 changed files with 132 additions and 10 deletions
|
|
@ -15,7 +15,7 @@
|
|||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: main.c,v 1.97 2000/12/12 23:05:54 bwelling Exp $ */
|
||||
/* $Id: main.c,v 1.98 2000/12/29 01:29:51 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
@ -572,8 +572,10 @@ main(int argc, char *argv[]) {
|
|||
|
||||
cleanup();
|
||||
|
||||
if (want_stats)
|
||||
if (want_stats) {
|
||||
isc_mem_stats(ns_g_mctx, stdout);
|
||||
isc_mutex_stats(stdout);
|
||||
}
|
||||
isc_mem_destroy(&ns_g_mctx);
|
||||
|
||||
isc_app_finish();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.68 2000/11/14 23:43:36 tale Exp $
|
||||
# $Id: Makefile.in,v 1.69 2000/12/29 01:29:52 bwelling Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
|
@ -41,7 +41,8 @@ UNIXOBJS = @ISC_ISCIPV6_O@ \
|
|||
|
||||
NLSOBJS = nls/msgcat.@O@
|
||||
|
||||
THREADOBJS = @ISC_THREAD_DIR@/condition.@O@ @ISC_THREAD_DIR@/thread.@O@
|
||||
THREADOBJS = @ISC_THREAD_DIR@/condition.@O@ @ISC_THREAD_DIR@/mutex.@O@ \
|
||||
@ISC_THREAD_DIR@/thread.@O@
|
||||
|
||||
WIN32OBJS = win32/condition.@O@ win32/dir.@O@ win32/file.@O@ \
|
||||
win32/fsaccess.@O@ win32/once.@O@ win32/stdtime.@O@ \
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.2 2000/08/29 19:22:34 bwelling Exp $
|
||||
# $Id: Makefile.in,v 1.3 2000/12/29 01:29:53 bwelling Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
|
@ -28,9 +28,9 @@ CINCLUDES = -I${srcdir}/include \
|
|||
CDEFINES =
|
||||
CWARNINGS =
|
||||
|
||||
OBJS = condition.@O@ thread.@O@
|
||||
OBJS = condition.@O@ mutex.@O@ thread.@O@
|
||||
|
||||
SRCS = condition.c thread.c
|
||||
SRCS = condition.c mutex.c thread.c
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS = ${OBJS}
|
||||
|
|
|
|||
20
lib/isc/nothreads/mutex.c
Normal file
20
lib/isc/nothreads/mutex.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (C) 2000 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: mutex.c,v 1.1 2000/12/29 01:29:54 bwelling Exp $ */
|
||||
|
||||
/* This file intentionally left blank. */
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.14 2000/08/01 01:30:59 tale Exp $
|
||||
# $Id: Makefile.in,v 1.15 2000/12/29 01:29:55 bwelling Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
|
@ -28,9 +28,9 @@ CINCLUDES = -I${srcdir}/include \
|
|||
CDEFINES =
|
||||
CWARNINGS =
|
||||
|
||||
OBJS = condition.@O@ thread.@O@
|
||||
OBJS = condition.@O@ mutex.@O@ thread.@O@
|
||||
|
||||
SRCS = condition.c thread.c
|
||||
SRCS = condition.c mutex.c thread.c
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS = ${OBJS}
|
||||
|
|
|
|||
97
lib/isc/pthreads/mutex.c
Normal file
97
lib/isc/pthreads/mutex.c
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (C) 2000 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: mutex.c,v 1.1 2000/12/29 01:29:56 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <isc/mutex.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#if ISC_MUTEX_PROFILE
|
||||
|
||||
struct mutexstats {
|
||||
const char *file;
|
||||
int line;
|
||||
isc_uint64_t us;
|
||||
isc_uint32_t count;
|
||||
};
|
||||
|
||||
#define TABLESIZE (8 * 1024)
|
||||
static struct mutexstats stats[TABLESIZE];
|
||||
static pthread_mutex_t statslock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
#define tvdiff(tv2, tv1) \
|
||||
((((tv2).tv_sec - (tv1).tv_sec) * 1000000) + \
|
||||
(tv2).tv_usec - (tv1).tv_usec)
|
||||
|
||||
|
||||
isc_result_t
|
||||
isc_mutex_lockprofile(isc_mutex_t *mp, const char * file, int line) {
|
||||
struct timeval tv1, tv2;
|
||||
int ret;
|
||||
int realline;
|
||||
unsigned int diff;
|
||||
|
||||
UNUSED(file);
|
||||
|
||||
gettimeofday(&tv1, NULL);
|
||||
ret = pthread_mutex_lock(mp);
|
||||
gettimeofday(&tv2, NULL);
|
||||
if (ret != 0)
|
||||
return (ISC_R_UNEXPECTED);
|
||||
diff = tvdiff(tv2, tv1);
|
||||
if (diff == 0)
|
||||
return (ISC_R_SUCCESS);
|
||||
RUNTIME_CHECK(pthread_mutex_lock(&statslock) == 0);
|
||||
INSIST(line >= 0 && line < TABLESIZE);
|
||||
realline = line;
|
||||
while (stats[line].file != NULL && stats[line].file != file) {
|
||||
line++;
|
||||
INSIST(line < TABLESIZE);
|
||||
}
|
||||
if (stats[line].file == NULL) {
|
||||
stats[line].file = file;
|
||||
stats[line].line = realline;
|
||||
stats[line].us = 0;
|
||||
stats[line].count = 0;
|
||||
}
|
||||
stats[line].us += diff;
|
||||
stats[line].count++;
|
||||
RUNTIME_CHECK(pthread_mutex_unlock(&statslock) == 0);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
isc_mutex_statsprofile(FILE *fp) {
|
||||
int i;
|
||||
fprintf(fp, "Mutex stats (in us)\n");
|
||||
for (i = 0; i < TABLESIZE; i++) {
|
||||
if (stats[i].file == NULL)
|
||||
continue;
|
||||
fprintf(fp, "%14s %6d: %10lluus %10u %10llu\n",
|
||||
stats[i].file, stats[i].line, stats[i].us,
|
||||
stats[i].count, stats[i].us / stats[i].count);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ISC_MUTEX_PROFILE */
|
||||
|
|
@ -1259,6 +1259,7 @@
|
|||
./lib/isc/nothreads/include/isc/mutex.h C 2000
|
||||
./lib/isc/nothreads/include/isc/once.h C 2000
|
||||
./lib/isc/nothreads/include/isc/thread.h C 2000
|
||||
./lib/isc/nothreads/mutex.c C 2000
|
||||
./lib/isc/nothreads/thread.c C 2000
|
||||
./lib/isc/ondestroy.c C 2000
|
||||
./lib/isc/print.c C 1999,2000
|
||||
|
|
@ -1273,6 +1274,7 @@
|
|||
./lib/isc/pthreads/include/isc/mutex.h C 1998,1999,2000
|
||||
./lib/isc/pthreads/include/isc/once.h C 1999,2000
|
||||
./lib/isc/pthreads/include/isc/thread.h C 1998,1999,2000
|
||||
./lib/isc/pthreads/mutex.c C 2000
|
||||
./lib/isc/pthreads/thread.c C 2000
|
||||
./lib/isc/quota.c C 2000
|
||||
./lib/isc/random.c C 1999,2000
|
||||
|
|
|
|||
Loading…
Reference in a new issue