DUNE PDELab (2.8)

clock.hh
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=8 sw=2 sts=2:
3
4#ifndef DUNE_PDELAB_COMMON_CLOCK_HH
5#define DUNE_PDELAB_COMMON_CLOCK_HH
6
7#include <ostream>
8
9#include <sys/types.h>
10
12
13namespace Dune {
14 namespace PDELab {
15
17 struct TimeSpec {
19 time_t tv_sec;
21
24 long tv_nsec;
25
26 inline TimeSpec &operator+=(const TimeSpec &o) {
27 tv_sec += o.tv_sec;
28 tv_nsec += o.tv_nsec;
29 if(tv_nsec >= 1000000000L) {
30 ++tv_sec;
31 tv_nsec -= 1000000000L;
32 }
33 return *this;
34 }
35 inline TimeSpec operator+(const TimeSpec &o) const {
36 TimeSpec tmp(*this);
37 tmp += o;
38 return tmp;
39 }
40 inline TimeSpec &operator-=(const TimeSpec &o) {
41 tv_sec -= o.tv_sec;
42 tv_nsec -= o.tv_nsec;
43 if(tv_nsec < 0L) {
44 --tv_sec;
45 tv_nsec += 1000000000L;
46 }
47 return *this;
48 }
49 inline TimeSpec operator-(const TimeSpec &o) const {
50 TimeSpec tmp(*this);
51 tmp -= o;
52 return tmp;
53 }
54
55 };
56
58 std::ostream &operator<<(std::ostream &s, const TimeSpec &t);
59
61 struct ClockError : Exception {};
62
64 TimeSpec getWallTime();
66 TimeSpec getWallTimeResolution();
69 const std::string &getWallTimeImp();
71 TimeSpec getProcessTime();
73 TimeSpec getProcessTimeResolution();
76 const std::string &getProcessTimeImp();
77
78 } // namespace PDELab
79} //namespace Dune
80
81#endif // DUNE_PDELAB_COMMON_CLOCK_HH
82
Base class for all PDELab exceptions.
Definition: exceptions.hh:19
A few common exception classes.
Dune namespace.
Definition: alignedallocator.hh:11
exception thrown by clock functions
Definition: clock.hh:61
struct to store temporal values
Definition: clock.hh:17
time_t tv_sec
seconds part
Definition: clock.hh:19
long tv_nsec
nanoseconds part
Definition: clock.hh:24
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)