Commit c4fadc88 authored by Tatuya JINMEI 神明達哉's avatar Tatuya JINMEI 神明達哉
Browse files

2356. [bug] Builtin mutex profiler was not scalable enough.

			[RT #17436]

(I plan to merge this to 9.[345])
parent e062b72f
2356. [bug] Builtin mutex profiler was not scalable enough.
[RT #17436]
2355. [func] Extend the number statistics counters available. 2355. [func] Extend the number statistics counters available.
[RT #17590] [RT #17590]
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: mutex.c,v 1.14 2007/06/19 23:47:18 tbox Exp $ */ /* $Id: mutex.c,v 1.15 2008/04/04 01:49:09 jinmei Exp $ */
/*! \file */ /*! \file */
...@@ -77,8 +77,11 @@ struct isc_mutexstats { ...@@ -77,8 +77,11 @@ struct isc_mutexstats {
isc_mutexlocker_t lockers[ISC_MUTEX_MAX_LOCKERS]; isc_mutexlocker_t lockers[ISC_MUTEX_MAX_LOCKERS];
}; };
#define TABLESIZE (8 * 1024) #ifndef ISC_MUTEX_PROFTABLESIZE
static isc_mutexstats_t stats[TABLESIZE]; #define ISC_MUTEX_PROFTABLESIZE (16 * 1024)
#endif
static isc_mutexstats_t stats[ISC_MUTEX_PROFTABLESIZE];
static int stats_next = 0;
static isc_boolean_t stats_init = ISC_FALSE; static isc_boolean_t stats_init = ISC_FALSE;
static pthread_mutex_t statslock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t statslock = PTHREAD_MUTEX_INITIALIZER;
...@@ -95,21 +98,19 @@ isc_mutex_init_profile(isc_mutex_t *mp, const char *file, int line) { ...@@ -95,21 +98,19 @@ isc_mutex_init_profile(isc_mutex_t *mp, const char *file, int line) {
RUNTIME_CHECK(pthread_mutex_lock(&statslock) == 0); RUNTIME_CHECK(pthread_mutex_lock(&statslock) == 0);
if (stats_init == ISC_FALSE) { if (stats_init == ISC_FALSE)
for (i = 0; i < TABLESIZE; i++) {
stats[i].file = NULL;
}
stats_init = ISC_TRUE; stats_init = ISC_TRUE;
}
mp->stats = NULL; /*
for (i = 0; i < TABLESIZE; i++) { * If all statistics entries have been used, give up and trigger an
if (stats[i].file == NULL) { * assertion failure. There would be no other way to deal with this
mp->stats = &stats[i]; * because we'd like to keep record of all locks for the purpose of
break; * debugging and the number of necessary locks is unpredictable.
} * If this failure is triggered while debugging, named should be
} * rebuilt with an increased ISC_MUTEX_PROFTABLESIZE.
RUNTIME_CHECK(mp->stats != NULL); */
RUNTIME_CHECK(stats_next < ISC_MUTEX_PROFTABLESIZE);
mp->stats = &stats[stats_next++];
RUNTIME_CHECK(pthread_mutex_unlock(&statslock) == 0); RUNTIME_CHECK(pthread_mutex_unlock(&statslock) == 0);
...@@ -196,10 +197,9 @@ void ...@@ -196,10 +197,9 @@ void
isc_mutex_statsprofile(FILE *fp) { isc_mutex_statsprofile(FILE *fp) {
isc_mutexlocker_t *locker; isc_mutexlocker_t *locker;
int i, j; int i, j;
fprintf(fp, "Mutex stats (in us)\n"); fprintf(fp, "Mutex stats (in us)\n");
for (i = 0; i < TABLESIZE; i++) { for (i = 0; i < stats_next; i++) {
if (stats[i].file == NULL)
continue;
fprintf(fp, "%-12s %4d: %10u %lu.%06lu %lu.%06lu\n", fprintf(fp, "%-12s %4d: %10u %lu.%06lu %lu.%06lu\n",
stats[i].file, stats[i].line, stats[i].count, stats[i].file, stats[i].line, stats[i].count,
stats[i].locked_total.tv_sec, stats[i].locked_total.tv_sec,
...@@ -251,6 +251,7 @@ pthread_mutexattr_t isc__mutex_attrs = { ...@@ -251,6 +251,7 @@ pthread_mutexattr_t isc__mutex_attrs = {
}; };
#endif #endif
#if !(ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK)) && !ISC_MUTEX_PROFILE
isc_result_t isc_result_t
isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) { isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) {
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
...@@ -268,3 +269,4 @@ isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) { ...@@ -268,3 +269,4 @@ isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) {
} }
return (result); return (result);
} }
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment