aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/metrics/job_tracker.h
blob: dee974f8b56bc0ba5bce22c9128df047cf505d5f (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "job_load_sampler.h"
#include "i_job_tracker.h"
#include <mutex>

namespace proton {

/**
 * Class that tracks the start and end of jobs and makes average job load available.
 */
class JobTracker : public IJobTracker
{
private:
    using time_point = std::chrono::time_point<std::chrono::steady_clock>;
    JobLoadSampler  _sampler;
    std::mutex     &_lock;

public:
    JobTracker(time_point now, std::mutex &lock);

    /**
     * Samples the average job load from previous sample time to now (in seconds).
     * The caller of this function must take the guard on the lock referenced by this class.
     */
    double sampleLoad(time_point now, const std::lock_guard<std::mutex> &guard);

    void start() override;
    void end() override;
};

}