File: duration.cpp

package info (click to toggle)
bonnie%2B%2B 2.00a%2Bnmu3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 384 kB
  • sloc: cpp: 4,413; perl: 164; sh: 117; makefile: 76
file content (61 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download | duplicates (5)
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
using namespace std;

#include <stdlib.h>

#include "duration.h"
#define TIMEVAL_TO_DOUBLE(XX) (double((XX).tv_sec) + double((XX).tv_usec) / 1000000.0)

#include "conf.h"
#include <unistd.h>
#include <sys/resource.h>
#include <sys/time.h>

#ifdef HAVE_ALGORITHM
#include <algorithm>
#else
#ifdef HAVE_ALGO
#include <algo>
#else
#include <algo.h>
#endif
#endif

Duration_Base::Duration_Base()
 : m_start(0.0)
 , m_max(0.0)
{
}

double Duration_Base::start()
{
  getTime(&m_start);
  return m_start;
}

double Duration_Base::stop()
{
  double tv;
  getTime(&tv);
  double ret;
  ret = tv - m_start;
  m_max = max(m_max, ret);
  return ret;
}

bool Duration::getTime(double *tv)
{
  TIMEVAL_TYPE t;
  if (gettimeofday(&t, static_cast<struct timezone *>(NULL)) == -1)
    return true;
  *tv = TIMEVAL_TO_DOUBLE(t);
  return false;
}

bool CPU_Duration::getTime(double *tv)
{
  struct rusage res_usage;
 
  getrusage(RUSAGE_SELF, &res_usage);
  *tv = TIMEVAL_TO_DOUBLE(res_usage.ru_utime) + TIMEVAL_TO_DOUBLE(res_usage.ru_stime);
  return false;
}