blob: f5e0949b41ed4d2db0ccf3e9107acd9c78fa0a2f (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <chrono>
namespace proton {
/**
* Class the samples job load average of jobs running in a given time interval.
*
* If 1 job runs during a complete interval the sampled load is 1.0,
* if 2 jobs run for 0.7 intervals each the load is 1.4.
*/
class JobLoadSampler
{
private:
using time_point = std::chrono::time_point<std::chrono::steady_clock>;
time_point _lastSampleTime;
time_point _lastUpdateTime;
uint32_t _currJobCnt;
double _loadIntegral;
void updateIntegral(time_point now, uint32_t jobCnt);
public:
/**
* Start the sampler with now (in seconds).
*/
JobLoadSampler(time_point now);
/**
* Signal that a job starts now (in seconds).
*/
void startJob(time_point now);
/**
* Signal that a job ends now (in seconds).
*/
void endJob(time_point now);
/**
* Samples the average load from previous sample time to now (in seconds).
*/
double sampleLoad(time_point now);
};
} // namespace proton
|