-
Notifications
You must be signed in to change notification settings - Fork 1
/
time_toolbox.c
67 lines (34 loc) · 1.45 KB
/
time_toolbox.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include "header.h"
/* Flag to establish if a RUFT server instance is using default timeout interval or adaptive one. */
char ADAPTIVE;
struct timespec beat = { 0, 3000000 };
long TIMEOUT_INTERVAL = (long) 5000000;
long EstimatedRTT = 0;
long DevRTT = 0;
int current_timestamp( struct timespec* time ) {
if( clock_gettime( CLOCK_MONOTONIC , time ) == -1 ) {
printf("Error in function : clock_gettime() : current_timestamp");
return -1;
}
return 0;
}
void print_elapsed( struct timespec *start, struct timespec *stop ) {
struct timespec *result = malloc( sizeof( struct timespec ) );
if ((stop->tv_nsec - start->tv_nsec) < 0) {
result->tv_sec = stop->tv_sec - start->tv_sec - 1;
result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000;
} else {
result->tv_sec = stop->tv_sec - start->tv_sec;
result->tv_nsec = stop->tv_nsec - start->tv_nsec;
}
printf("\n \n TRANSACTION TIME : %.5f seconds", ( (double) result -> tv_sec + 1.0e-9 * result -> tv_nsec ) );
free( result );
return;
}
long nanodifftime ( struct timespec *time1, struct timespec *time2 ){
long time_1 = ( time1 -> tv_nsec ) + ( (1.0e9) * ( time1 -> tv_sec ) );
long time_2 = ( time2 -> tv_nsec ) + ( (1.0e9) * ( time2 -> tv_sec ) );
long nanodiff = time_1 - time_2;
return nanodiff;
}