aboutsummaryrefslogtreecommitdiffstats
path: root/yt/yt/core/profiling/timing-inl.h
blob: 81cc08303a9f1cfd0c5e3a4bf757b22a713014ae (plain) (blame)
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
#ifndef TIMING_INL_H_
#error "Direct inclusion of this file is not allowed, include timing.h"
// For the sake of sane code completion.
#include "timing.h"
#endif
#undef TIMING_INL_H_

namespace NYT::NProfiling {

////////////////////////////////////////////////////////////////////////////////

template <class TTimer>
TValueIncrementingTimingGuard<TTimer>::TValueIncrementingTimingGuard(TDuration* value)
    : Value_(value)
{ }

template <class TTimer>
TValueIncrementingTimingGuard<TTimer>::~TValueIncrementingTimingGuard()
{
    *Value_ += Timer_.GetElapsedTime();
}

////////////////////////////////////////////////////////////////////////////////

inline TCpuDurationIncrementingGuard::TCpuDurationIncrementingGuard(TCpuDuration* value)
    : Value_(value)
    , StartInstant_(GetCpuInstant())
{ }

inline TCpuDurationIncrementingGuard::~TCpuDurationIncrementingGuard()
{
    *Value_ += GetCpuInstant() - StartInstant_;

}

////////////////////////////////////////////////////////////////////////////////

template <class TTimer>
TTimerGuard<TTimer>::TTimerGuard(TTimer* timer)
    : Timer_(timer)
{
    Timer_->Start();
}

template <class TTimer>
TTimerGuard<TTimer>::~TTimerGuard()
{
    Timer_->Stop();
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NProfiling