From 2cf83d84ee84ca04f1818cd81e71746b4d35bceb Mon Sep 17 00:00:00 2001 From: Kurt Spanier Date: Fri, 12 Feb 1999 14:36:16 +0000 Subject: [PATCH] Server timing as a private feature of the bdb2 backend. --- servers/slapd/back-bdb2/abandon.c | 23 ++---- servers/slapd/back-bdb2/add.c | 31 +++---- servers/slapd/back-bdb2/back-bdb2.h | 3 + servers/slapd/back-bdb2/bind.c | 20 ++--- servers/slapd/back-bdb2/close.c | 17 +--- servers/slapd/back-bdb2/compare.c | 22 ++--- servers/slapd/back-bdb2/config.c | 35 ++------ servers/slapd/back-bdb2/dbcache.c | 93 ++++++++++++--------- servers/slapd/back-bdb2/delete.c | 22 ++--- servers/slapd/back-bdb2/group.c | 21 ++--- servers/slapd/back-bdb2/init.c | 21 ++--- servers/slapd/back-bdb2/modify.c | 31 +++---- servers/slapd/back-bdb2/modrdn.c | 21 ++--- servers/slapd/back-bdb2/porter.c | 98 +++++++++++++---------- servers/slapd/back-bdb2/proto-back-bdb2.h | 3 + servers/slapd/back-bdb2/search.c | 21 ++--- servers/slapd/back-bdb2/startup.c | 72 ++++------------- servers/slapd/back-bdb2/timing.c | 43 +++++++++- servers/slapd/back-bdb2/unbind.c | 18 +---- servers/slapd/init.c | 53 ++++++------ servers/slapd/main.c | 17 ++-- servers/slapd/slap.h | 7 +- 22 files changed, 300 insertions(+), 392 deletions(-) diff --git a/servers/slapd/back-bdb2/abandon.c b/servers/slapd/back-bdb2/abandon.c index b91ce4419b..bd12160f05 100644 --- a/servers/slapd/back-bdb2/abandon.c +++ b/servers/slapd/back-bdb2/abandon.c @@ -27,27 +27,18 @@ bdb2i_back_abandon_internal( int bdb2_back_abandon( BackendDB *be, - Connection *c, - Operation *o, + Connection *conn, + Operation *op, int msgid ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; - - gettimeofday( &time1, NULL ); - - ret = bdb2i_back_abandon_internal( be, c, o, msgid ); + struct timeval time1; + int ret; - if ( bdb2i_do_timing ) { + bdb2i_start_timing( be->be_private, &time1 ); - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "ABND elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); + ret = bdb2i_back_abandon_internal( be, conn, op, msgid ); - } + bdb2i_stop_timing( be->be_private, time1, "ABND", conn, op ); return( ret ); } diff --git a/servers/slapd/back-bdb2/add.c b/servers/slapd/back-bdb2/add.c index 50125c6ab7..c96fd025de 100644 --- a/servers/slapd/back-bdb2/add.c +++ b/servers/slapd/back-bdb2/add.c @@ -234,14 +234,12 @@ bdb2_back_add( Entry *e ) { - DB_LOCK lock; + DB_LOCK lock; struct ldbminfo *li = (struct ldbminfo *) be->be_private; + struct timeval time1; + int ret; - struct timeval time1, time2; - char *elapsed_time; - int ret; - - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { @@ -252,22 +250,17 @@ bdb2_back_add( /* check, if a new default attribute index will be created, in which case we have to open the index file BEFORE TP */ - if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) - bdb2i_check_default_attr_index_add( li, e ); + switch ( slapMode ) { + case SLAP_SERVER_MODE: + case SLAP_TIMEDSERVER_MODE: + case SLAP_TOOL_MODE: + bdb2i_check_default_attr_index_add( li, e ); + break; + } ret = bdb2i_back_add_internal( be, conn, op, e ); - (void) bdb2i_leave_backend( get_dbenv( be ), lock ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "conn=%d op=%d ADD elapsed=%s\n", - conn->c_connid, op->o_opid, elapsed_time ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "ADD", conn, op ); return( ret ); } diff --git a/servers/slapd/back-bdb2/back-bdb2.h b/servers/slapd/back-bdb2/back-bdb2.h index 3179819fb2..f3c0ec0d68 100644 --- a/servers/slapd/back-bdb2/back-bdb2.h +++ b/servers/slapd/back-bdb2/back-bdb2.h @@ -160,12 +160,15 @@ typedef struct _bdb2_txn_head { struct ldbtype { char *lty_dbhome; size_t lty_mpsize; + int lty_betiming; /* XXX do we need a private DB_ENV for all DB2 backend types ? */ DB_ENV *lty_dbenv; }; #define get_dbenv(be) ((struct ldbtype *) (be)->bd_info->bi_private)->lty_dbenv +#define with_timing(bi) (((struct ldbtype *) \ + (bi)->bi_private)->lty_betiming == 1) /* the private description of a database */ diff --git a/servers/slapd/back-bdb2/bind.c b/servers/slapd/back-bdb2/bind.c index 9dfc181b40..47270e37b5 100644 --- a/servers/slapd/back-bdb2/bind.c +++ b/servers/slapd/back-bdb2/bind.c @@ -226,14 +226,12 @@ bdb2_back_bind( char** edn ) { - DB_LOCK lock; + DB_LOCK lock; struct ldbminfo *li = (struct ldbminfo *) be->be_private; + struct timeval time1; + int ret; - struct timeval time1, time2; - char *elapsed_time; - int ret; - - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { @@ -246,15 +244,7 @@ bdb2_back_bind( (void) bdb2i_leave_backend( get_dbenv( be ), lock ); - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "conn=%d op=%d BIND elapsed=%s\n", - conn->c_connid, op->o_opid, elapsed_time ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "BIND", conn, op ); return( ret ); } diff --git a/servers/slapd/back-bdb2/close.c b/servers/slapd/back-bdb2/close.c index 647ba757ba..c956d1513c 100644 --- a/servers/slapd/back-bdb2/close.c +++ b/servers/slapd/back-bdb2/close.c @@ -29,23 +29,14 @@ bdb2i_back_db_close_internal( BackendDB *be ) int bdb2_back_db_close( BackendDB *be ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); ret = bdb2i_back_db_close_internal( be ); - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "CLOSE elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "CLOSE", NULL, NULL ); return( ret ); } diff --git a/servers/slapd/back-bdb2/compare.c b/servers/slapd/back-bdb2/compare.c index 27a555182d..b0337db606 100644 --- a/servers/slapd/back-bdb2/compare.c +++ b/servers/slapd/back-bdb2/compare.c @@ -71,14 +71,12 @@ bdb2_back_compare( Ava *ava ) { - DB_LOCK lock; + DB_LOCK lock; struct ldbminfo *li = (struct ldbminfo *) be->be_private; + struct timeval time1; + int ret; - struct timeval time1, time2; - char *elapsed_time; - int ret; - - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { @@ -88,18 +86,8 @@ bdb2_back_compare( } ret = bdb2i_back_compare_internal( be, conn, op, dn, ava ); - (void) bdb2i_leave_backend( get_dbenv( be ), lock ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "conn=%d op=%d CMP elapsed=%s\n", - conn->c_connid, op->o_opid, elapsed_time ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "CMP", conn, op ); return( ret ); } diff --git a/servers/slapd/back-bdb2/config.c b/servers/slapd/back-bdb2/config.c index 7fb2399def..d67ea0f62b 100644 --- a/servers/slapd/back-bdb2/config.c +++ b/servers/slapd/back-bdb2/config.c @@ -70,23 +70,13 @@ bdb2_back_config( char **argv ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( bi, &time1 ); ret = bdb2i_back_config_internal( bi, fname, lineno, argc, argv ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_TRACE, "BE-CONFIG elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( bi, time1, "BE-CONFIG", NULL, NULL ); return( ret ); } @@ -196,23 +186,14 @@ bdb2_back_db_config( char **argv ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); ret = bdb2i_back_db_config_internal( be, fname, lineno, argc, argv ); - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "DB-CONFIG elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "DB-CONFIG", NULL, NULL ); return( ret ); } diff --git a/servers/slapd/back-bdb2/dbcache.c b/servers/slapd/back-bdb2/dbcache.c index 5044fbb860..1b13f48dbb 100644 --- a/servers/slapd/back-bdb2/dbcache.c +++ b/servers/slapd/back-bdb2/dbcache.c @@ -28,74 +28,91 @@ bdb2i_cache_open( ) { /* all files are open, so return handle from file cache */ - if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) { - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - char buf[MAXPATHLEN]; + switch ( slapMode ) { - /* use short name */ - sprintf( buf, "%s%s", name, suffix ); - return( bdb2i_get_db_file_cache( li, buf )); + case SLAP_SERVER_MODE: + case SLAP_TIMEDSERVER_MODE: + case SLAP_TOOL_MODE: + { + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + char buf[MAXPATHLEN]; - } + /* use short name */ + sprintf( buf, "%s%s", name, suffix ); + return( bdb2i_get_db_file_cache( li, buf )); - /* if not SERVER or TOOL, who else would ask? - NO ONE, so return error */ + } + break; - Debug( LDAP_DEBUG_ANY, - "bdb2i_cache_open: database user (%d) unknown -- cannot open \"%s%s\".\n", - slapMode, name, suffix ); + default: + /* if not SERVER or TOOL, who else would ask? + NO ONE, so return error */ - return( NULL ); + Debug( LDAP_DEBUG_ANY, + "bdb2i_cache_open: database user (%d) unknown -- cannot open \"%s%s\".\n", + slapMode, name, suffix ); + return( NULL ); + } } void bdb2i_cache_close( BackendDB *be, struct dbcache *db ) { /* all files stay open until SERVER or TOOL shut down */ - if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) - return; + switch ( slapMode ) { - /* if unknown user, complain */ - Debug( LDAP_DEBUG_ANY, - "bdb2i_cache_close: database user (%d) unknown -- ignored.\n", - slapMode, 0, 0 ); + case SLAP_SERVER_MODE: + case SLAP_TIMEDSERVER_MODE: + case SLAP_TOOL_MODE: + return; - return; + default: + /* if unknown user, complain */ + Debug( LDAP_DEBUG_ANY, + "bdb2i_cache_close: database user (%d) unknown -- ignored.\n", + slapMode, 0, 0 ); + return; + } } void bdb2i_cache_really_close( BackendDB *be, struct dbcache *db ) { - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - /* all files stay open until SERVER or TOOL shut down */ - if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) + switch ( slapMode ) { + + case SLAP_SERVER_MODE: + case SLAP_TIMEDSERVER_MODE: + case SLAP_TOOL_MODE: return; - /* if unknown user, complain */ - Debug( LDAP_DEBUG_ANY, + default: + /* if unknown user, complain */ + Debug( LDAP_DEBUG_ANY, "bdb2i_cache_really_close: database user (%d) unknown -- ignored.\n", - slapMode, 0, 0 ); - - return; + slapMode, 0, 0 ); + return; + } } void bdb2i_cache_flush_all( BackendDB *be ) { - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - int i; - /* if SERVER or TOOL, syncing is done by TP, or during shutdown */ - if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) - return; + switch ( slapMode ) { - /* if unknown user, complain */ - Debug( LDAP_DEBUG_ANY, - "bdb2i_cache_really_close: database user (%d) unknown -- ignored.\n", - slapMode, 0, 0 ); + case SLAP_SERVER_MODE: + case SLAP_TIMEDSERVER_MODE: + case SLAP_TOOL_MODE: + return; - return; + default: + /* if unknown user, complain */ + Debug( LDAP_DEBUG_ANY, + "bdb2i_cache_flush_all: database user (%d) unknown -- ignored.\n", + slapMode, 0, 0 ); + return; + } } Datum diff --git a/servers/slapd/back-bdb2/delete.c b/servers/slapd/back-bdb2/delete.c index 9b5335b149..ad00966788 100644 --- a/servers/slapd/back-bdb2/delete.c +++ b/servers/slapd/back-bdb2/delete.c @@ -158,14 +158,12 @@ bdb2_back_delete( char *dn ) { - DB_LOCK lock; + DB_LOCK lock; struct ldbminfo *li = (struct ldbminfo *) be->be_private; + struct timeval time1; + int ret; - struct timeval time1, time2; - char *elapsed_time; - int ret; - - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { @@ -175,18 +173,8 @@ bdb2_back_delete( } ret = bdb2i_back_delete_internal( be, conn, op, dn ); - (void) bdb2i_leave_backend( get_dbenv( be ), lock ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "conn=%d op=%d DEL elapsed=%s\n", - conn->c_connid, op->o_opid, elapsed_time ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "DEL", conn, op ); return( ret ); } diff --git a/servers/slapd/back-bdb2/group.c b/servers/slapd/back-bdb2/group.c index a5d5fd65d4..a8f9d9c0ad 100644 --- a/servers/slapd/back-bdb2/group.c +++ b/servers/slapd/back-bdb2/group.c @@ -134,14 +134,12 @@ bdb2_back_group( char *groupattrName ) { - DB_LOCK lock; + DB_LOCK lock; struct ldbminfo *li = (struct ldbminfo *) be->be_private; + struct timeval time1; + int ret; - struct timeval time1, time2; - char *elapsed_time; - int ret; - - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { @@ -153,16 +151,7 @@ bdb2_back_group( objectclassValue, groupattrName ); (void) bdb2i_leave_backend( get_dbenv( be ), lock ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "GRP elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "GRP", NULL, NULL ); return( ret ); } diff --git a/servers/slapd/back-bdb2/init.c b/servers/slapd/back-bdb2/init.c index 1bdbda54b2..2fd558cab5 100644 --- a/servers/slapd/back-bdb2/init.c +++ b/servers/slapd/back-bdb2/init.c @@ -25,6 +25,9 @@ bdb2i_back_init_private( bt->lty_mpsize = DEFAULT_DBCACHE_SIZE; bt->lty_dbenv = &ldbm_Env; + if ( slapMode == SLAP_TIMEDSERVER_MODE ) + bt->lty_betiming = 1; + bi->bi_private = bt; return 0; @@ -192,23 +195,13 @@ bdb2_back_db_init( BackendDB *be ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); ret = bdb2i_back_db_init_internal( be ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "DB-INIT elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "DB-INIT", NULL, NULL ); return( ret ); } diff --git a/servers/slapd/back-bdb2/modify.c b/servers/slapd/back-bdb2/modify.c index 86f319fd86..4e602ef147 100644 --- a/servers/slapd/back-bdb2/modify.c +++ b/servers/slapd/back-bdb2/modify.c @@ -124,14 +124,12 @@ bdb2_back_modify( LDAPModList *modlist ) { - DB_LOCK lock; + DB_LOCK lock; struct ldbminfo *li = (struct ldbminfo *) be->be_private; + struct timeval time1; + int ret; - struct timeval time1, time2; - char *elapsed_time; - int ret; - - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { @@ -142,22 +140,17 @@ bdb2_back_modify( /* check, if a new default attribute index will be created, in which case we have to open the index file BEFORE TP */ - if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) - bdb2i_check_default_attr_index_mod( li, modlist ); + switch ( slapMode ) { + case SLAP_SERVER_MODE: + case SLAP_TIMEDSERVER_MODE: + case SLAP_TOOL_MODE: + bdb2i_check_default_attr_index_mod( li, modlist ); + break; + } ret = bdb2i_back_modify_internal( be, conn, op, dn, modlist ); - (void) bdb2i_leave_backend( get_dbenv( be ), lock ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "conn=%d op=%d MOD elapsed=%s\n", - conn->c_connid, op->o_opid, elapsed_time ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "MOD", conn, op ); return( ret ); } diff --git a/servers/slapd/back-bdb2/modrdn.c b/servers/slapd/back-bdb2/modrdn.c index d310ca0c7a..28c764e8dd 100644 --- a/servers/slapd/back-bdb2/modrdn.c +++ b/servers/slapd/back-bdb2/modrdn.c @@ -201,14 +201,12 @@ bdb2_back_modrdn( int deleteoldrdn ) { - DB_LOCK lock; + DB_LOCK lock; struct ldbminfo *li = (struct ldbminfo *) be->be_private; + struct timeval time1; + int ret; - struct timeval time1, time2; - char *elapsed_time; - int ret; - - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { @@ -221,16 +219,7 @@ bdb2_back_modrdn( newrdn, deleteoldrdn ); (void) bdb2i_leave_backend( get_dbenv( be ), lock ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "conn=%d op=%d MODRDN elapsed=%s\n", - conn->c_connid, op->o_opid, elapsed_time ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "MODRDN", conn, op ); return( ret ); } diff --git a/servers/slapd/back-bdb2/porter.c b/servers/slapd/back-bdb2/porter.c index 42e2cf9d16..4ee72b9977 100644 --- a/servers/slapd/back-bdb2/porter.c +++ b/servers/slapd/back-bdb2/porter.c @@ -19,51 +19,56 @@ bdb2i_enter_backend( DB_ENV *dbEnv, DB_LOCK *lock, int writer ) u_int32_t locker; db_lockmode_t lock_type; DBT lock_dbt; - int ret; + int ret = 0; - if ( ( slapMode != SLAP_SERVER_MODE ) && ( slapMode != SLAP_TOOL_MODE ) ) - return( 0 ); + switch ( slapMode ) { - if ( ( ret = lock_id( dbEnv->lk_info, &locker )) != 0 ) { + case SLAP_SERVER_MODE: + case SLAP_TIMEDSERVER_MODE: + case SLAP_TOOL_MODE: + if ( ( ret = lock_id( dbEnv->lk_info, &locker )) != 0 ) { - Debug( LDAP_DEBUG_ANY, - "bdb2i_enter_backend(): unable to get locker id -- %s\n", - strerror( ret ), 0, 0 ); - return( ret ); + Debug( LDAP_DEBUG_ANY, + "bdb2i_enter_backend(): unable to get locker id -- %s\n", + strerror( ret ), 0, 0 ); + return( ret ); - } + } - lock_type = writer ? DB_LOCK_WRITE : DB_LOCK_READ; - lock_dbt.data = PORTER_OBJ; - lock_dbt.size = strlen( PORTER_OBJ ); + lock_type = writer ? DB_LOCK_WRITE : DB_LOCK_READ; + lock_dbt.data = PORTER_OBJ; + lock_dbt.size = strlen( PORTER_OBJ ); - switch ( ( ret = lock_get( dbEnv->lk_info, locker, 0, &lock_dbt, - lock_type, lock ))) { + switch ( ( ret = lock_get( dbEnv->lk_info, locker, 0, &lock_dbt, + lock_type, lock ))) { - case 0: - Debug( LDAP_DEBUG_TRACE, "bdb2i_enter_backend() -- %s lock granted\n", + case 0: + Debug( LDAP_DEBUG_TRACE, + "bdb2i_enter_backend() -- %s lock granted\n", writer ? "write" : "read", 0, 0 ); - break; + break; - case DB_LOCK_NOTGRANTED: - Debug( LDAP_DEBUG_ANY, + case DB_LOCK_NOTGRANTED: + Debug( LDAP_DEBUG_ANY, "bdb2i_enter_backend() -- %s lock NOT granted\n", writer ? "write" : "read", 0, 0 ); - break; + break; - case DB_LOCK_DEADLOCK: - Debug( LDAP_DEBUG_ANY, + case DB_LOCK_DEADLOCK: + Debug( LDAP_DEBUG_ANY, "bdb2i_enter_backend() -- %s lock returned DEADLOCK\n", writer ? "write" : "read", 0, 0 ); - break; + break; - default: - Debug( LDAP_DEBUG_ANY, + default: + Debug( LDAP_DEBUG_ANY, "bdb2i_enter_backend() -- %s lock returned ERROR: %s\n", writer ? "write" : "read", strerror( errno ), 0 ); - ret = errno; + ret = errno; + break; + + } break; - } return( ret ); @@ -87,37 +92,42 @@ bdb2i_enter_backend_w( DB_ENV *dbEnv, DB_LOCK *lock ) int bdb2i_leave_backend( DB_ENV *dbEnv, DB_LOCK lock ) { - int ret; + int ret = 0; - if ( ( slapMode != SLAP_SERVER_MODE ) && ( slapMode != SLAP_TOOL_MODE ) ) - return( 0 ); + switch ( slapMode ) { - switch( ( ret = lock_put( dbEnv->lk_info, lock ))) { + case SLAP_SERVER_MODE: + case SLAP_TIMEDSERVER_MODE: + case SLAP_TOOL_MODE: + switch( ( ret = lock_put( dbEnv->lk_info, lock ))) { - case 0: - Debug( LDAP_DEBUG_TRACE, "bdb2i_leave_backend() -- lock released\n", + case 0: + Debug( LDAP_DEBUG_TRACE, + "bdb2i_leave_backend() -- lock released\n", 0, 0, 0 ); - break; + break; - case DB_LOCK_NOTHELD: - Debug( LDAP_DEBUG_ANY, + case DB_LOCK_NOTHELD: + Debug( LDAP_DEBUG_ANY, "bdb2i_leave_backend() -- lock NOT held\n", 0, 0, 0 ); - break; + break; - case DB_LOCK_DEADLOCK: - Debug( LDAP_DEBUG_ANY, + case DB_LOCK_DEADLOCK: + Debug( LDAP_DEBUG_ANY, "bdb2i_leave_backend() -- lock returned DEADLOCK\n", 0, 0, 0 ); - break; + break; - default: - Debug( LDAP_DEBUG_ANY, + default: + Debug( LDAP_DEBUG_ANY, "bdb2i_leave_backend() -- lock returned ERROR: %s\n", strerror( errno ), 0, 0 ); - ret = errno; - break; + ret = errno; + break; + } + break; } return( ret ); diff --git a/servers/slapd/back-bdb2/proto-back-bdb2.h b/servers/slapd/back-bdb2/proto-back-bdb2.h index d66cf1826d..d964894389 100644 --- a/servers/slapd/back-bdb2/proto-back-bdb2.h +++ b/servers/slapd/back-bdb2/proto-back-bdb2.h @@ -155,6 +155,9 @@ int bdb2i_back_db_shutdown LDAP_P(( BackendDB *be )); char *bdb2i_elapsed LDAP_P(( struct timeval firsttime, struct timeval secondtime )); +void bdb2i_start_timing LDAP_P(( BackendInfo *bi, struct timeval *time1 )); +void bdb2i_stop_timing LDAP_P(( BackendInfo *bi, struct timeval time1, + char *func, Connection *conn, Operation *op )); /* * porter.c diff --git a/servers/slapd/back-bdb2/search.c b/servers/slapd/back-bdb2/search.c index 5358d74f56..cee22b9082 100644 --- a/servers/slapd/back-bdb2/search.c +++ b/servers/slapd/back-bdb2/search.c @@ -330,14 +330,12 @@ bdb2_back_search( int attrsonly ) { - DB_LOCK lock; + DB_LOCK lock; struct ldbminfo *li = (struct ldbminfo *) be->be_private; + struct timeval time1; + int ret; - struct timeval time1, time2; - char *elapsed_time; - int ret; - - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { @@ -350,16 +348,7 @@ bdb2_back_search( slimit, tlimit, filter, filterstr, attrs, attrsonly ); (void) bdb2i_leave_backend( get_dbenv( be ), lock ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "conn=%d op=%d SRCH elapsed=%s\n", - conn->c_connid, op->o_opid, elapsed_time ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "SRCH", conn, op ); return( ret ); } diff --git a/servers/slapd/back-bdb2/startup.c b/servers/slapd/back-bdb2/startup.c index 6e526ab88d..3c7b6ecb7e 100644 --- a/servers/slapd/back-bdb2/startup.c +++ b/servers/slapd/back-bdb2/startup.c @@ -112,23 +112,13 @@ bdb2i_back_startup( BackendInfo *bi ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( bi, &time1 ); ret = bdb2i_back_startup_internal( bi ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "BE-START elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( bi, time1, "BE-START", NULL, NULL ); return( ret ); } @@ -139,23 +129,13 @@ bdb2i_back_shutdown( BackendInfo *bi ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( bi, &time1 ); ret = bdb2i_back_shutdown_internal( bi ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "BE-SHUTDOWN elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( bi, time1, "BE-SHUTDOWN", NULL, NULL ); return( ret ); } @@ -208,23 +188,13 @@ bdb2_back_db_startup( BackendDB *be ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); ret = bdb2i_back_db_startup_internal( be ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "DB-START elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "DB-START", NULL, NULL ); return( ret ); } @@ -235,23 +205,13 @@ bdb2_back_db_shutdown( BackendDB *be ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); ret = bdb2i_back_db_shutdown_internal( be ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "DB-SHUTDOWN elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "DB-SHUTDOWN", NULL, NULL ); return( ret ); } diff --git a/servers/slapd/back-bdb2/timing.c b/servers/slapd/back-bdb2/timing.c index a8f6cfcb7d..fd08a4f63b 100644 --- a/servers/slapd/back-bdb2/timing.c +++ b/servers/slapd/back-bdb2/timing.c @@ -12,9 +12,6 @@ #include "back-bdb2.h" -int bdb2i_do_timing = 0; - - char * bdb2i_elapsed( struct timeval firsttime, struct timeval secondtime ) { @@ -33,3 +30,43 @@ bdb2i_elapsed( struct timeval firsttime, struct timeval secondtime ) } +void +bdb2i_start_timing( + BackendInfo *bi, + struct timeval *time1 +) +{ + if ( with_timing( bi )) gettimeofday( time1, NULL ); +} + + +void +bdb2i_stop_timing( + BackendInfo *bi, + struct timeval time1, + char *func, + Connection *conn, + Operation *op +) +{ + if ( with_timing( bi )) { + struct timeval time2; + char *elapsed_time; + char buf[BUFSIZ]; + + *buf = '\0'; + + gettimeofday( &time2, NULL); + elapsed_time = bdb2i_elapsed( time1, time2 ); + + if ( conn != NULL ) sprintf( buf, "conn=%d ", conn->c_connid ); + if ( op != NULL ) sprintf( buf, "%sop=%d ", buf, op->o_opid ); + + Debug( LDAP_DEBUG_ANY, "%s%s elapsed=%s\n", buf, func, elapsed_time ); + + free( elapsed_time ); + + } +} + + diff --git a/servers/slapd/back-bdb2/unbind.c b/servers/slapd/back-bdb2/unbind.c index 6d74cbb87b..f4aa508fda 100644 --- a/servers/slapd/back-bdb2/unbind.c +++ b/servers/slapd/back-bdb2/unbind.c @@ -26,23 +26,13 @@ bdb2_back_unbind( Operation *op ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->be_private, &time1 ); ret = bdb2i_back_unbind_internal( be, conn, op ); - - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "conn=%d op=%d UNBIND elapsed=%s\n", - conn->c_connid, op->o_opid, elapsed_time ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->be_private, time1, "UNBIND", conn, op ); return( ret ); } diff --git a/servers/slapd/init.c b/servers/slapd/init.c index f90cb6ba58..43af8d0a14 100644 --- a/servers/slapd/init.c +++ b/servers/slapd/init.c @@ -78,37 +78,44 @@ slap_init( int mode, char *name ) slapMode = mode; - if( ( slapMode != SLAP_SERVER_MODE ) && ( slapMode != SLAP_TOOL_MODE ) ) { - Debug( LDAP_DEBUG_ANY, - "%s init: undefined mode (%d).\n", - name, mode, 0 ); - return 1; - } + switch ( slapMode ) { - Debug( LDAP_DEBUG_TRACE, - "%s init: initiated %s.\n", - name, - mode == SLAP_SERVER_MODE ? "server" : "tool", - 0 ); + case SLAP_SERVER_MODE: + case SLAP_TOOL_MODE: +#ifdef SLAPD_BDB2 + case SLAP_TIMEDSERVER_MODE: +#endif + + Debug( LDAP_DEBUG_TRACE, + "%s init: initiated %s.\n", + name, mode == SLAP_TOOL_MODE ? "tool" : "server", 0 ); - slap_name = name; + slap_name = name; - (void) ldap_pvt_thread_initialize(); + (void) ldap_pvt_thread_initialize(); - ldap_pvt_thread_mutex_init( &active_threads_mutex ); - ldap_pvt_thread_cond_init( &active_threads_cond ); + ldap_pvt_thread_mutex_init( &active_threads_mutex ); + ldap_pvt_thread_cond_init( &active_threads_cond ); - ldap_pvt_thread_mutex_init( &new_conn_mutex ); - ldap_pvt_thread_mutex_init( ¤ttime_mutex ); - ldap_pvt_thread_mutex_init( &entry2str_mutex ); - ldap_pvt_thread_mutex_init( &replog_mutex ); - ldap_pvt_thread_mutex_init( &ops_mutex ); - ldap_pvt_thread_mutex_init( &num_sent_mutex ); + ldap_pvt_thread_mutex_init( &new_conn_mutex ); + ldap_pvt_thread_mutex_init( ¤ttime_mutex ); + ldap_pvt_thread_mutex_init( &entry2str_mutex ); + ldap_pvt_thread_mutex_init( &replog_mutex ); + ldap_pvt_thread_mutex_init( &ops_mutex ); + ldap_pvt_thread_mutex_init( &num_sent_mutex ); #ifdef SLAPD_CRYPT - ldap_pvt_thread_mutex_init( &crypt_mutex ); + ldap_pvt_thread_mutex_init( &crypt_mutex ); #endif - rc = backend_init(); + rc = backend_init(); + break; + + default: + Debug( LDAP_DEBUG_ANY, + "%s init: undefined mode (%d).\n", name, mode, 0 ); + rc = 1; + break; + } return rc; } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index eb320394b8..3d67f85a98 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -69,13 +69,18 @@ main( int argc, char **argv ) #endif char *configfile; char *serverName; + int serverMode = SLAP_SERVER_MODE; configfile = SLAPD_DEFAULT_CONFIGFILE; port = LDAP_PORT; g_argc = argc; g_argv = argv; +#ifdef SLAPD_BDB2 + while ( (i = getopt( argc, argv, "d:f:ip:s:ut" )) != EOF ) { +#else while ( (i = getopt( argc, argv, "d:f:ip:s:u" )) != EOF ) { +#endif switch ( i ) { #ifdef LDAP_DEBUG case 'd': /* turn on debugging */ @@ -148,6 +153,12 @@ main( int argc, char **argv ) udp = 1; break; +#ifdef SLAPD_BDB2 + case 't': /* timed server */ + serverMode = SLAP_TIMEDSERVER_MODE; + break; +#endif + default: usage( argv[0] ); exit( 1 ); @@ -172,11 +183,7 @@ main( int argc, char **argv ) openlog( serverName, OPENLOG_OPTIONS ); #endif -#ifdef SLAPD_BDB2 - bdb2i_do_timing = 1; -#endif - - if ( slap_init( SLAP_SERVER_MODE, serverName ) != 0 ) { + if ( slap_init( serverMode, serverName ) != 0 ) { rc = 1; goto destroy; } diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 786702b2e4..e478f2b95d 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -22,10 +22,6 @@ #define ldap_debug slap_debug #endif -#ifdef SLAPD_BDB2 -extern int bdb2i_do_timing; -#endif - #include "ldap_log.h" @@ -234,6 +230,9 @@ extern int slapMode; #define SLAP_UNDEFINED_MODE 0 #define SLAP_SERVER_MODE 1 #define SLAP_TOOL_MODE 2 +#ifdef SLAPD_BDB2 +# define SLAP_TIMEDSERVER_MODE 3 +#endif /* temporary aliases */ typedef BackendDB Backend; -- 2.39.5