]> git.sur5r.net Git - openldap/commitdiff
Server timing as a private feature of the bdb2 backend.
authorKurt Spanier <ksp@openldap.org>
Fri, 12 Feb 1999 14:36:16 +0000 (14:36 +0000)
committerKurt Spanier <ksp@openldap.org>
Fri, 12 Feb 1999 14:36:16 +0000 (14:36 +0000)
22 files changed:
servers/slapd/back-bdb2/abandon.c
servers/slapd/back-bdb2/add.c
servers/slapd/back-bdb2/back-bdb2.h
servers/slapd/back-bdb2/bind.c
servers/slapd/back-bdb2/close.c
servers/slapd/back-bdb2/compare.c
servers/slapd/back-bdb2/config.c
servers/slapd/back-bdb2/dbcache.c
servers/slapd/back-bdb2/delete.c
servers/slapd/back-bdb2/group.c
servers/slapd/back-bdb2/init.c
servers/slapd/back-bdb2/modify.c
servers/slapd/back-bdb2/modrdn.c
servers/slapd/back-bdb2/porter.c
servers/slapd/back-bdb2/proto-back-bdb2.h
servers/slapd/back-bdb2/search.c
servers/slapd/back-bdb2/startup.c
servers/slapd/back-bdb2/timing.c
servers/slapd/back-bdb2/unbind.c
servers/slapd/init.c
servers/slapd/main.c
servers/slapd/slap.h

index b91ce4419bb867ff3c50ff9365a28ee2ca4e0a95..bd12160f059669a6e04de350b189f2e70bf334f2 100644 (file)
@@ -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 );
 }
index 50125c6ab76d6d4ce037f62b002baab2e03fb424..c96fd025ded574423b3caa82aa13daf26d79029d 100644 (file)
@@ -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 );
 }
index 3179819fb2cffb53873112e6185cf6eb060696e3..f3c0ec0d688a362219c98e9f32c969e3fe1e3243 100644 (file)
@@ -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  */
index 9dfc181b409168a60c95272ca029a6384b586838..47270e37b5793d43d43f2b603ab5a2cba502af76 100644 (file)
@@ -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 );
 }
index 647ba757ba4280fe2185b840c9dfb35a0fb61924..c956d1513cb377cfd7ca801c9e8e944716126464 100644 (file)
@@ -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 );
 }
index 27a555182d4c8464717935acd035180fbd20f95b..b0337db6065c1fd9d050544f48ab73a9fe94778e 100644 (file)
@@ -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 );
 }
index 7fb2399def8c033f5afbde9d55c2a40b5e375db5..d67ea0f62b9430962a65f9b09ba0ecab56e00330 100644 (file)
@@ -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 );
 }
index 5044fbb860c9d25c75ceafc4667ff3f89ea78fc2..1b13f48dbb66a2ed2ce7a6434b757bdf20d3e0ee 100644 (file)
@@ -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
index 9b5335b149032225cc03fae99658698a546f8e69..ad009667884434b124208853ab0b149d48aadcca 100644 (file)
@@ -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 );
 }
index a5d5fd65d43a0e5cd8e4129d733f4500b4c73065..a8f9d9c0ad17db3ddd966ca656a22a8bcb80fcbe 100644 (file)
@@ -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 );
 }
index 1bdbda54b2dd82a6f5340b735cc3210c4afa1877..2fd558cab52e4289809e9b5825d3bc93bb759c0a 100644 (file)
@@ -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 );
 }
index 86f319fd867bb17ff471b73b5fbf97cb98ea90e2..4e602ef147d797c31fae82035252e1164333b0e6 100644 (file)
@@ -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 );
 }
index d310ca0c7a35346054794cd374fa9d13b749d658..28c764e8ddd1549f5f9e4e6293afb027349c12e8 100644 (file)
@@ -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 );
 }
index 42e2cf9d16135c2697c6060bd0b112ab31c2750d..4ee72b99779435c270f1192839505933891be0c1 100644 (file)
@@ -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 );
index d66cf1826d091790dcf445017012465e0283814c..d964894389d539c2a7c37630b579ea21284b2f7e 100644 (file)
@@ -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
index 5358d74f5610ad9b0bc25487609dc285a4357a8a..cee22b908225271275168340d3e4ac889fd4dede 100644 (file)
@@ -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 );
 }
index 6e526ab88d1754f570639fb8ff276373c4df4801..3c7b6ecb7ede5e32830d4bf614093579b205a9a5 100644 (file)
@@ -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 );
 }
index a8f6cfcb7d3fbb8169a604b3c9ee06a8a0f6b865..fd08a4f63b6a060f930e901e2fa5a0a127474bc5 100644 (file)
@@ -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 );
+
+       }
+}
+
+
index 6d74cbb87b7966a280b6dd4c887e25b99c6603f4..f4aa508fda777884d77afe350d544ac76fbe3e42 100644 (file)
@@ -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 );
 }
index f90cb6ba589c5970113f21efd9b226a0ee3d75b4..43af8d0a14d7f7b825a51f78ccc3315a874a012d 100644 (file)
@@ -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( &currenttime_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( &currenttime_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;
 }
index eb320394b85f2243d0cc169d19c7d7015bb855ba..3d67f85a98c6629b7bb3cb1425da7893f0eb0ba7 100644 (file)
@@ -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;
        }
index 786702b2e4590cf4b33eb5926b3d610f30114d24..e478f2b95d0aec2e381c192b2f1c488970ba86d7 100644 (file)
 #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;