summaryrefslogtreecommitdiff
path: root/ace/High_Res_Timer.i
blob: acd82ea4e142bfbca20390718c8b33c37767bd3d (plain)
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
/* -*- C++ -*- */
// $Id$

// High_Res_Timer.i

ACE_INLINE int
ACE_High_Res_Timer::supported ()
{
  return ACE_OS::gethrtime () != -1;
}

ACE_INLINE
ACE_High_Res_Timer::ACE_High_Res_Timer (void)
{
  ACE_TRACE ("ACE_High_Res_Timer::ACE_High_Res_Timer");

  this->reset ();
}

ACE_INLINE void
ACE_High_Res_Timer::start (void)
{
  ACE_TRACE ("ACE_High_Res_Timer::start");
  this->start_ = ACE_OS::gethrtime ();
}

ACE_INLINE void
ACE_High_Res_Timer::stop (void)
{
  ACE_TRACE ("ACE_High_Res_Timer::stop");
  this->end_ = ACE_OS::gethrtime ();
}

ACE_INLINE void
ACE_High_Res_Timer::start_incr (void)
{
  ACE_TRACE ("ACE_High_Res_Timer::start_incr");
  this->start_incr_ = ACE_OS::gethrtime ();
}

ACE_INLINE void
ACE_High_Res_Timer::stop_incr (void)
{
  ACE_TRACE ("ACE_High_Res_Timer::stop_incr");
  this->total_ += ACE_OS::gethrtime () - this->start_incr_;
}

ACE_INLINE void
ACE_High_Res_Timer::elapsed_microseconds (ACE_hrtime_t &usecs) const
{
  usecs = (ACE_hrtime_t) ((this->end_ - this->start_) / global_scale_factor_);
}

ACE_INLINE void
ACE_High_Res_Timer::global_scale_factor (u_long gsf)
{
  global_scale_factor_ = gsf;
}

ACE_INLINE void
ACE_High_Res_Timer::hrtime_to_tv (ACE_Time_Value &tv,
				  ACE_hrtime_t hrt)
{
  tv.sec ((long) (hrt / global_scale_factor_) / 1000000);
  tv.usec ((long) (hrt / global_scale_factor_) % 1000000);
}

ACE_INLINE ACE_Time_Value
ACE_High_Res_Timer::gettimeofday (void)
{
#if defined (ACE_WIN32)
  // If the global_scale_factor_ == 1 and we're on an Intel platform,
  // then a scale factor is needed by the platform gethrtime.  Since
  // one has not been set, just return ACE_OS::gettimeofday.
  if (ACE_High_Res_Timer::global_scale_factor_ == 1)
    return ACE_OS::gettimeofday ();
#endif /* ACE_WIN32 */

  ACE_Time_Value tv;
  ACE_High_Res_Timer::hrtime_to_tv (tv,
				    ACE_OS::gethrtime ());
  return tv;
}