ATLAS Offline Software
RegSelTimer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /**************************************************************************
6  **
7  ** File: RegSelTimer.cxx
8  **
9  ** Description:
10  **
11  **
12  **
13  ** Author: M.Sutton
14  **
15  ** Created: Fri Jun 29 18:59:11 BST 2001
16  ** Modified:
17  **
18  **
19  **
20  **************************************************************************/
21 
22 #include <stdlib.h>
23 #include <pthread.h>
24 #include "RegSelLUT/RegSelTimer.h"
25 
26 
27 // pthread_mutex_t time_lock = PTHREAD_MUTEX_INITIALIZER;
28 // static pthread_key_t time_key;
29 
30 
31 typedef struct {
32  struct timeval start_time;
33  struct timeval stop_time;
34  struct timeval since_time;
35  struct timeval diff_time;
36 } __gtttimer;
37 
38 
39 
40 #define _timersub Timersub
41 
42 
43 int Timersub(struct timeval* , struct timeval* , struct timeval* );
44 
45 
46 
48 void __free_timer(void* t) { if ( t!=nullptr ) free((__gtttimer*)t); }
49 
51 // void gtttimer_initkey(void) { pthread_key_create(&time_key, (void*)__free_timer); }
52 // void gtttimer_initkey(void) { pthread_key_create(&time_key, __free_timer); }
53 // void gtttimer_initkey(void) { pthread_key_create(&time_key, __free_timer); }
54 
55 
57 // __gtttimer* init_gtttimer(void)
58 // {
59 // __gtttimer* t = (__gtttimer*) malloc(1*sizeof(__gtttimer));
60 // pthread_setspecific(time_key, (void*)t);
61 // return t;
62 // }
63 
64 
65 
70 void __gtt_gettime(struct timeval* t)
71 {
72  // pthread_mutex_lock(&time_lock);
73  gettimeofday (t, nullptr);
74  // pthread_mutex_unlock(&time_lock);
75 }
76 
77 
78 #if 0
79 
84 double gtttimer(int flag)
85 {
86  double time = 0;
87  __gtttimer* t = (__gtttimer*)pthread_getspecific(time_key);
88 
89  if (flag==GTT_TIMER_START) {
90  if (t==NULL) t = init_gtttimer();
91  __gtt_gettime (&(t->start_time));
92  t->since_time = t->start_time;
93  }
94  if (flag==GTT_TIMER_STOP) {
95  if (t==NULL) return -1;
96  __gtt_gettime (&(t->stop_time));
97  t->since_time = t->stop_time;
98  _timersub( &(t->stop_time), &(t->start_time), &(t->diff_time) );
99  time = (t->diff_time.tv_sec*1000.0) + (t->diff_time.tv_usec/1000.0);
100  }
101  if (flag==GTT_TIMER_SINCE) {
102  if (t==NULL) return -1;
103  __gtt_gettime (&(t->stop_time));
104  _timersub( &(t->stop_time), &(t->since_time), &(t->diff_time) );
105  t->since_time = t->stop_time;
106  time = (t->diff_time.tv_sec*1000.0) + (t->diff_time.tv_usec/1000.0);
107  }
108 
109  return time;
110 }
111 
112 #endif
113 
118 struct timeval gtttimer_start(void)
119 {
120  struct timeval start_time;
121  __gtt_gettime (&start_time);
122  return start_time;
123 }
124 
125 
126 double gttd(struct timeval time) { return (time.tv_sec*1000.0) + (time.tv_usec/1000.0); }
127 
128 double gtttimer_stop(struct timeval start_time)
129 {
130  double time = 0;
131  struct timeval stop_time;
132  struct timeval diff_time;
133  // double diff;
134 
135  __gtt_gettime (&stop_time);
136  // pthread_mutex_lock(&time_lock);
137  _timersub( &stop_time, &start_time, &diff_time );
138  // printf("diff: %d\n", _timersub( &stop_time, &start_time, &diff_time ) );
139  // diff = gttd(stop_time)-gttd(start_time);
140  // printf("timer: %12.5f %12.5f %12.5f %12.5f\n", gttd(stop_time), gttd(start_time), gttd(diff_time), diff );
141  // pthread_mutex_unlock(&time_lock);
142  time = (diff_time.tv_sec*1000.0) + (diff_time.tv_usec/1000.0);
143  return time;
144 }
145 
146 
147 int Timersub(struct timeval* stop_time, struct timeval* start_time, struct timeval* diff_time)
148 {
149  diff_time->tv_sec = stop_time->tv_sec - start_time->tv_sec;
150  diff_time->tv_usec = stop_time->tv_usec - start_time->tv_usec;
151  return 0;
152 }
153 
154 
155 
156 
157 
158 
159 
160 
161 
__free_timer
void __free_timer(void *t)
destructor
Definition: RegSelTimer.cxx:48
__gtttimer
Definition: RegSelTimer.cxx:31
gtttimer
double gtttimer(int)
_timersub
#define _timersub
Definition: RegSelTimer.cxx:40
RegSelTimer.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
__gtt_gettime
void __gtt_gettime(struct timeval *t)
initialiser
Definition: RegSelTimer.cxx:70
gtttimer_stop
double gtttimer_stop(struct timeval start_time)
Definition: RegSelTimer.cxx:128
GTT_TIMER_SINCE
#define GTT_TIMER_SINCE
Definition: RegSelTimer.h:31
master.flag
bool flag
Definition: master.py:29
gtttimer_start
struct timeval gtttimer_start(void)
significantly (0.02ms) faster and simpler timer start/stop functions
Definition: RegSelTimer.cxx:118
Timersub
int Timersub(struct timeval *, struct timeval *, struct timeval *)
Definition: RegSelTimer.cxx:147
GTT_TIMER_STOP
#define GTT_TIMER_STOP
Definition: RegSelTimer.h:30
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
GTT_TIMER_START
#define GTT_TIMER_START
Definition: RegSelTimer.h:29
gttd
double gttd(struct timeval time)
Definition: RegSelTimer.cxx:126