]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/timing.c
Elimination of entry- and cache-level locking in back-bdb2.
[openldap] / servers / slapd / back-bdb2 / timing.c
1 /* timing.c - timing bdb2 backend */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6 #include <sys/time.h>
7 #include <unistd.h>
8
9 #include <ac/string.h>
10
11 #include "slap.h"
12 #include "back-bdb2.h"
13
14
15 char *
16 bdb2i_elapsed( struct timeval firsttime,  struct timeval secondtime )
17 {
18     long int elapsedmicrosec, elapsedsec;
19     char elapsed_string[BUFSIZ];
20     
21     elapsedsec = secondtime.tv_sec - firsttime.tv_sec;
22     elapsedmicrosec = secondtime.tv_usec - firsttime.tv_usec;
23     if(elapsedmicrosec < 0) {
24         elapsedmicrosec += 1000000;
25         elapsedsec -= 1;
26     }
27
28     sprintf( elapsed_string, "%ld.%.6ld", elapsedsec, elapsedmicrosec );
29     return( strdup( elapsed_string ));
30 }
31
32
33 void
34 bdb2i_start_timing(
35         BackendInfo     *bi,
36         struct timeval  *time1
37 )
38 {
39         if ( with_timing( bi )) gettimeofday( time1, NULL );
40 }
41
42
43 void
44 bdb2i_stop_timing(
45         BackendInfo     *bi,
46         struct timeval  time1,
47         char            *func,
48         Connection      *conn,
49         Operation       *op
50 )
51 {
52         if ( with_timing( bi )) {
53                 struct timeval  time2;
54                 char            *elapsed_time;
55                 char            buf[BUFSIZ];
56
57                 *buf = '\0';
58
59                 gettimeofday( &time2, NULL);
60                 elapsed_time = bdb2i_elapsed( time1, time2 );
61
62                 if ( conn != NULL ) sprintf( buf, "conn=%d ", conn->c_connid );
63                 if ( op != NULL )   sprintf( buf, "%sop=%d ", buf, op->o_opid );
64
65                 Debug( LDAP_DEBUG_ANY, "%s%s elapsed=%s\n", buf, func, elapsed_time );
66
67                 free( elapsed_time );
68
69         }
70 }
71
72