summaryrefslogtreecommitdiff
path: root/TAO/IIOP/test/Orbeline/client/Profile_Timer.h
blob: 8a4f73314cec3920af4960b76a4343f248da3a2f (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
/* -*- C++ -*- */
// $Id$

/* An interval timer class using C++. */

#ifndef ACE_PROFILE_TIMER_H
#define ACE_PROFILE_TIMER_H

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/procfs.h>
#include <stdio.h>
#include <memory.h>

class Profile_Timer
{
public:
  struct Elapsed_Time
    {
      double real_time;
      double user_time;
      double system_time;
    };

  Profile_Timer (void);
  ~Profile_Timer (void);
  int  start (void);
  int  stop (void);
  int  elapsed_time (Elapsed_Time &et);
  void elapsed_rusage (prusage_t &rusage);
  void get_rusage (prusage_t &rusage);

private:
  void subtract (timespec_t &tdiff, timespec_t &t0, timespec_t &t1);
  void compute_times (Elapsed_Time &et, prusage_t &, prusage_t &);

  prusage_t begin_usage_;
  prusage_t end_usage_;
  prusage_t last_usage_;
  int       proc_fd_;
};

/* Start timing */

inline int
Profile_Timer::start (void)
{
  return ::ioctl (this->proc_fd_, PIOCUSAGE, &this->begin_usage_);
}

/* Stop timing */

inline int
Profile_Timer::stop (void)
{
  this->last_usage_ = this->end_usage_;
  return ::ioctl (this->proc_fd_, PIOCUSAGE, &this->end_usage_);
}

#endif /* ACE_PROFILE_TIMER_H */