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