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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
// $Id$
#define ACE_BUILD_DLL
#include "ace/Profile_Timer.h"
#if !defined (__ACE_INLINE__)
# include "ace/Profile_Timer.i"
#endif /* __ACE_INLINE__ */
ACE_RCSID(ace, Profile_Timer, "$Id$")
ACE_ALLOC_HOOK_DEFINE(ACE_Profile_Timer)
#if (defined (ACE_HAS_PRUSAGE_T) || defined (ACE_HAS_GETRUSAGE)) && !defined (ACE_WIN32)
void
ACE_Profile_Timer::dump (void) const
{
ACE_TRACE ("ACE_Profile_Timer::dump");
}
// Initialize interval timer.
ACE_Profile_Timer::ACE_Profile_Timer (void)
{
ACE_TRACE ("ACE_Profile_Timer::ACE_Profile_Timer");
ACE_OS::memset (&this->end_usage_, 0, sizeof this->end_usage_);
ACE_OS::memset (&this->begin_usage_, 0, sizeof this->begin_usage_);
ACE_OS::memset (&this->last_usage_, 0, sizeof this->last_usage_);
# if defined (ACE_HAS_PRUSAGE_T)
ACE_OS::memset (&this->last_usage_, 0, sizeof this->last_usage_);
char buf[20];
ACE_OS::sprintf (buf, "/proc/%d", ACE_static_cast (int, ACE_OS::getpid ()));
if ((this->proc_handle_ = ACE_OS::open (buf, O_RDONLY, 0)) == -1)
ACE_OS::perror (buf);
# elif defined (ACE_HAS_GETRUSAGE)
ACE_OS::memset (&this->begin_time_, 0, sizeof this->begin_time_);
ACE_OS::memset (&this->end_time_, 0, sizeof this->end_time_);
ACE_OS::memset (&this->last_time_, 0, sizeof this->last_time_);
# endif /* ACE_HAS_PRUSAGE_T */
}
// Terminate the interval timer.
ACE_Profile_Timer::~ACE_Profile_Timer (void)
{
ACE_TRACE ("ACE_Profile_Timer::~ACE_Profile_Timer");
# if defined (ACE_HAS_PRUSAGE_T)
if (ACE_OS::close (this->proc_handle_) == -1)
ACE_OS::perror ("ACE_Profile_Timer::~ACE_Profile_Timer");
# endif /* ACE_HAS_PRUSAGE_T */
}
// Return the resource utilization.
void
ACE_Profile_Timer::get_rusage (ACE_Profile_Timer::Rusage &usage)
{
ACE_TRACE ("ACE_Profile_Timer::get_rusage");
usage = this->end_usage_;
}
# if defined (ACE_HAS_PRUSAGE_T)
// Compute the amount of resource utilization since the start time.
void
ACE_Profile_Timer::elapsed_rusage (ACE_Profile_Timer::Rusage &rusage)
{
ACE_TRACE ("ACE_Profile_Timer::elapsed_rusage");
rusage.pr_lwpid =
this->end_usage_.pr_lwpid - this->last_usage_.pr_lwpid;
rusage.pr_count =
this->end_usage_.pr_count - this->last_usage_.pr_count;
rusage.pr_minf =
this->end_usage_.pr_minf - this->last_usage_.pr_minf;
rusage.pr_majf =
this->end_usage_.pr_majf - this->last_usage_.pr_majf;
rusage.pr_inblk =
this->end_usage_.pr_inblk - this->last_usage_.pr_inblk;
rusage.pr_oublk =
this->end_usage_.pr_oublk - this->last_usage_.pr_oublk;
rusage.pr_msnd =
this->end_usage_.pr_msnd - this->last_usage_.pr_msnd;
rusage.pr_mrcv =
this->end_usage_.pr_mrcv - this->last_usage_.pr_mrcv;
rusage.pr_sigs =
this->end_usage_.pr_sigs - this->last_usage_.pr_sigs;
this->subtract (rusage.pr_wtime,
this->end_usage_.pr_wtime,
this->last_usage_.pr_wtime);
this->subtract (rusage.pr_ltime,
this->end_usage_.pr_ltime,
this->last_usage_.pr_ltime);
this->subtract (rusage.pr_slptime,
this->end_usage_.pr_slptime,
this->last_usage_.pr_slptime);
rusage.pr_vctx =
this->end_usage_.pr_vctx - this->last_usage_.pr_vctx;
rusage.pr_ictx =
this->end_usage_.pr_ictx - this->last_usage_.pr_ictx;
rusage.pr_sysc =
this->end_usage_.pr_sysc - this->last_usage_.pr_sysc;
rusage.pr_ioch =
this->end_usage_.pr_ioch - this->last_usage_.pr_ioch;
}
// Compute the elapsed time.
void
ACE_Profile_Timer::compute_times (ACE_Elapsed_Time &et)
{
ACE_TRACE ("ACE_Profile_Timer::compute_times");
timespec_t td;
ACE_Profile_Timer::Rusage &end = this->end_usage_;
ACE_Profile_Timer::Rusage &begin = this->begin_usage_;
this->subtract (td, end.pr_tstamp, begin.pr_tstamp);
// Convert nanoseconds into seconds.
et.real_time = td.tv_sec + ((double) td.tv_nsec) / ACE_ONE_SECOND_IN_NSECS;
this->subtract (td, end.pr_utime, begin.pr_utime);
// Convert nanoseconds into seconds.
et.user_time = td.tv_sec + ((double) td.tv_nsec) / ACE_ONE_SECOND_IN_NSECS;
this->subtract (td, end.pr_stime, begin.pr_stime);
// Convert nanoseconds into seconds.
et.system_time = td.tv_sec + ((double) td.tv_nsec) / ACE_ONE_SECOND_IN_NSECS;
}
// Determine the difference between T1 and T2.
void
ACE_Profile_Timer::subtract (timespec_t &tdiff, timespec_t &t1, timespec_t &t0)
{
ACE_TRACE ("ACE_Profile_Timer::subtract");
tdiff.tv_sec = t1.tv_sec - t0.tv_sec;
tdiff.tv_nsec = t1.tv_nsec - t0.tv_nsec;
// Normalize the time.
while (tdiff.tv_nsec < 0)
{
tdiff.tv_sec--;
tdiff.tv_nsec += ACE_ONE_SECOND_IN_NSECS;
}
}
# elif defined (ACE_HAS_GETRUSAGE)
// Compute the amount of resource utilization since the start time.
void
ACE_Profile_Timer::elapsed_rusage (ACE_Profile_Timer::Rusage &usage)
{
ACE_TRACE ("ACE_Profile_Timer::elapsed_rusage");
# if !defined (ACE_WIN32) && !defined (ACE_HAS_LIMITED_RUSAGE_T)
// integral shared memory size
usage.ru_ixrss =
this->end_usage_.ru_ixrss - this->last_usage_.ru_ixrss;
// integral unshared data "
usage.ru_idrss =
this->end_usage_.ru_idrss - this->last_usage_.ru_idrss;
// integral unshared stack "
usage.ru_isrss =
this->end_usage_.ru_isrss - this->last_usage_.ru_isrss;
// page reclaims - total vmfaults
usage.ru_minflt =
this->end_usage_.ru_minflt - this->last_usage_.ru_minflt;
// page faults
usage.ru_majflt =
this->end_usage_.ru_majflt - this->last_usage_.ru_majflt;
// swaps
usage.ru_nswap =
this->end_usage_.ru_nswap - this->last_usage_.ru_nswap;
// block input operations
usage.ru_inblock =
this->end_usage_.ru_inblock - this->last_usage_.ru_inblock;
// block output operations
usage.ru_oublock =
this->end_usage_.ru_oublock - this->last_usage_.ru_oublock;
// messages sent
usage.ru_msgsnd =
this->end_usage_.ru_msgsnd - this->last_usage_.ru_msgsnd;
// messages received
usage.ru_msgrcv =
this->end_usage_.ru_msgrcv - this->last_usage_.ru_msgrcv;
// signals received
usage.ru_nsignals =
this->end_usage_.ru_nsignals - this->last_usage_.ru_nsignals;
// voluntary context switches
usage.ru_nvcsw =
this->end_usage_.ru_nvcsw - this->last_usage_.ru_nvcsw;
// involuntary context switches
usage.ru_nivcsw =
this->end_usage_.ru_nivcsw - this->last_usage_.ru_nivcsw;
this->subtract (usage.ru_utime,
this->end_usage_.ru_utime,
this->last_usage_.ru_utime);
this->subtract (usage.ru_stime,
this->end_usage_.ru_stime,
this->last_usage_.ru_stime);
# else
ACE_UNUSED_ARG(usage);
# endif /* ACE_WIN32 */
}
void
ACE_Profile_Timer::compute_times (ACE_Elapsed_Time &et)
{
ACE_TRACE ("ACE_Profile_Timer::compute_times");
# if defined (ACE_WIN32)
ACE_Time_Value atv = this->end_time_ - this->begin_time_;
et.real_time = atv.sec () + ((double) atv.usec ()) / ACE_ONE_SECOND_IN_USECS;
atv = ACE_Time_Value (this->end_usage_.ru_utime)
- ACE_Time_Value (this->begin_usage_.ru_utime);
et.user_time = atv.sec () + ((double) atv.usec ()) / ACE_ONE_SECOND_IN_USECS;
atv = ACE_Time_Value (this->end_usage_.ru_stime)
- ACE_Time_Value (this->begin_usage_.ru_stime);
et.system_time = atv.sec () + ((double) atv.usec ()) / ACE_ONE_SECOND_IN_USECS;
# else
timeval td;
this->subtract (td, this->end_time_, this->begin_time_);
et.real_time = td.tv_sec + ((double) td.tv_usec) / ACE_ONE_SECOND_IN_USECS;
this->subtract (td, this->end_usage_.ru_utime, this->begin_usage_.ru_utime);
et.user_time = td.tv_sec + ((double) td.tv_usec) / ACE_ONE_SECOND_IN_USECS;
this->subtract (td, this->end_usage_.ru_stime, this->begin_usage_.ru_stime);
et.system_time = td.tv_sec + ((double) td.tv_usec) / ACE_ONE_SECOND_IN_USECS;
# endif /* ACE_WIN32 */
}
// Determine the difference between T1 and T2.
void
ACE_Profile_Timer::subtract (timeval &tdiff, timeval &t1, timeval &t0)
{
ACE_TRACE ("ACE_Profile_Timer::subtract");
tdiff.tv_sec = t1.tv_sec - t0.tv_sec;
tdiff.tv_usec = t1.tv_usec - t0.tv_usec;
// Normalize the time.
while (tdiff.tv_usec < 0)
{
tdiff.tv_sec--;
tdiff.tv_usec += ACE_ONE_SECOND_IN_USECS;
}
}
# endif /* ACE_HAS_PRUSAGE_T */
// Compute the amount of time that has elapsed between start and stop.
int
ACE_Profile_Timer::elapsed_time (ACE_Elapsed_Time &et)
{
ACE_TRACE ("ACE_Profile_Timer::elapsed_time");
this->compute_times (et);
return 0;
}
#elif defined (ACE_WIN32) /* defined (ACE_HAS_PRUSAGE_T) || defined (ACE_HAS_GETRUSAGE) */
void
ACE_Profile_Timer::dump (void) const
{
ACE_TRACE ("ACE_Profile_Timer::dump");
timer_.dump ();
}
// Initialize interval timer.
ACE_Profile_Timer::ACE_Profile_Timer (void)
: timer_ ()
{
ACE_TRACE ("ACE_Profile_Timer::ACE_Profile_Timer");
# if defined (ACE_HAS_GETRUSAGE)
ACE_OS::memset (&this->end_usage_, 0, sizeof this->end_usage_);
ACE_OS::memset (&this->begin_usage_, 0, sizeof this->begin_usage_);
ACE_OS::memset (&this->last_usage_, 0, sizeof this->last_usage_);
ACE_OS::memset (&this->begin_time_, 0, sizeof this->begin_time_);
ACE_OS::memset (&this->end_time_, 0, sizeof this->end_time_);
ACE_OS::memset (&this->last_time_, 0, sizeof this->last_time_);
# endif /* ACE_HAS_GETRUSAGE */
}
int
ACE_Profile_Timer::elapsed_time (ACE_Elapsed_Time &et)
{
ACE_TRACE ("ACE_Profile_Timer::elapsed_time");
ACE_hrtime_t delta_t; // nanoseconds
timer_.elapsed_time (delta_t);
et.real_time = (__int64) delta_t / (double) ACE_ONE_SECOND_IN_NSECS;
# if defined (ACE_HAS_GETRUSAGE)
ACE_Time_Value atv = ACE_Time_Value (this->end_usage_.ru_utime)
- ACE_Time_Value (this->begin_usage_.ru_utime);
et.user_time = atv.sec () + ((double) atv.usec ()) / ACE_ONE_SECOND_IN_USECS;
atv = ACE_Time_Value (this->end_usage_.ru_stime)
- ACE_Time_Value (this->begin_usage_.ru_stime);
et.system_time = atv.sec () + ((double) atv.usec ()) / ACE_ONE_SECOND_IN_USECS;
# else /* ACE_HAS_GETRUSAGE */
et.user_time = 0;
et.system_time = 0;
# endif /* ACE_HAS_GETRUSAGE */
return 0;
}
// Return the resource utilization.
void
ACE_Profile_Timer::get_rusage (ACE_Profile_Timer::Rusage &usage)
{
ACE_TRACE ("ACE_Profile_Timer::get_rusage");
# if defined (ACE_HAS_GETRUSAGE)
usage = this->end_usage_;
# else /* ACE_HAS_GETRUSAGE */
usage = 0;
# endif /* ACE_HAS_GETRUSAGE */
}
// Compute the amount of resource utilization since the start time.
void
ACE_Profile_Timer::elapsed_rusage (ACE_Profile_Timer::Rusage &usage)
{
ACE_TRACE ("ACE_Profile_Timer::elapsed_rusage");
# if defined (ACE_HAS_GETRUSAGE)
usage.ru_utime =
this->end_usage_.ru_utime - this->begin_usage_.ru_utime;
usage.ru_stime =
this->end_usage_.ru_stime - this->begin_usage_.ru_stime;
# else /* ACE_HAS_GETRUSAGE */
usage = 0;
# endif /* ACE_HAS_GETRUSAGE */
}
# if defined (ACE_HAS_GETRUSAGE)
// Determine the difference between T1 and T2.
void
ACE_Profile_Timer::subtract (timeval &tdiff, timeval &t1, timeval &t0)
{
ACE_TRACE ("ACE_Profile_Timer::subtract");
tdiff.tv_sec = t1.tv_sec - t0.tv_sec;
tdiff.tv_usec = t1.tv_usec - t0.tv_usec;
// Normalize the time.
while (tdiff.tv_usec < 0)
{
tdiff.tv_sec--;
tdiff.tv_usec += ACE_ONE_SECOND_IN_USECS;
}
}
# endif /* ACE_HAS_GETRUSAGE */
#else /* defined (ACE_HAS_PRUSAGE_T) || defined (ACE_HAS_GETRUSAGE) */
void
ACE_Profile_Timer::dump (void) const
{
ACE_TRACE ("ACE_Profile_Timer::dump");
timer_.dump ();
}
ACE_Profile_Timer::ACE_Profile_Timer (void)
: timer_ ()
{
ACE_TRACE ("ACE_Profile_Timer::ACE_Profile_Timer");
}
int
ACE_Profile_Timer::elapsed_time (ACE_Elapsed_Time &et)
{
ACE_TRACE ("ACE_Profile_Timer::elapsed_time");
# if defined (ACE_LACKS_FLOATING_POINT)
ACE_Time_Value delta_t; /* elapsed time will be in microseconds */
timer_.elapsed_time (delta_t);
// Store the time in usecs.
et.real_time = delta_t.sec () * ACE_ONE_SECOND_IN_USECS +
delta_t.usec ();
# else /* ! ACE_LACKS_FLOATING_POINT */
ACE_hrtime_t delta_t; /* nanoseconds */
timer_.elapsed_time (delta_t);
et.real_time = delta_t / (double) ACE_ONE_SECOND_IN_NSECS;
# endif /* ! ACE_LACKS_FLOATING_POINT */
et.user_time = 0;
et.system_time = 0;
return 0;
}
#endif /* defined (ACE_HAS_PRUSAGE_T) || defined (ACE_HAS_GETRUSAGE) */
|