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
|
#pragma once
#include "libporto.hpp"
#include <util/generic/map.h>
#include <util/generic/vector.h>
#include <util/string/cast.h>
#include <util/string/type.h>
#include <library/cpp/porto/proto/rpc.pb.h>
namespace Porto {
constexpr const char *M_CTXSW = "ctxsw";
enum class EMetric {
NONE,
CTXSW,
};
class TMetric {
public:
TString Name;
EMetric Metric;
TMetric(const TString& name, EMetric metric);
void ClearValues(const TVector<TString>& names, TMap<TString, uint64_t>& values) const;
EError GetValues(const TVector<TString>& names, TMap<TString, uint64_t>& values, TPortoApi& api) const;
// Returns value of metric from /proc/tid/sched for some tid
uint64_t GetTidSchedMetricValue(int procFd, const TString& tid, const TString& metricName) const;
void TidSnapshot(TVector<TString>& tids) const;
void GetPidTasks(const TString& pid, TVector<TString>& tids) const;
// Returns freezer cgroup from /proc/tid/cgroup
TString GetFreezerCgroup(int procFd, const TString& tid) const;
// Resurns clean cgroup[freezer] for containers names
TMap<TString, TString> GetCtFreezerCgroups(const TGetResponse* response) const;
// Verify inclusion of container cgroup in process cgroup
bool MatchCgroups(const TString& tidCgroup, const TString& ctCgroup) const;
private:
virtual uint64_t GetMetric(int procFd, const TString& tid) const = 0;
};
extern TMap<TString, TMetric*> ProcMetrics;
} /* namespace Porto */
|