C++ YT Wrapper
C++ library for working with YT clusters
Loading...
Searching...
No Matches
job_statistics.h
Go to the documentation of this file.
1#pragma once
2
8
9#include "fwd.h"
10
11#include <library/cpp/yson/node/node.h>
12
13#include <util/system/defaults.h>
14#include <util/generic/maybe.h>
15#include <util/generic/ptr.h>
16
17namespace NYT {
18
20
28template <typename T>
30
32
35{
36public:
40
43 TJobStatistics(const NYT::TNode& statistics);
44
45 TJobStatistics(const TJobStatistics& jobStatistics);
46 TJobStatistics(TJobStatistics&& jobStatistics) noexcept;
47
48 TJobStatistics& operator=(const TJobStatistics& jobStatistics);
49 TJobStatistics& operator=(TJobStatistics&& jobStatistics) noexcept;
50
52
57 TJobStatistics TaskName(TVector<TTaskName> taskNames) const;
58
65 TJobStatistics JobState(TVector<EJobState> filter) const;
66
75 TJobStatistics JobType(TVector<EJobType> filter) const;
76
81 bool HasStatistics(TStringBuf name) const;
82
97 TJobStatisticsEntry<i64> GetStatistics(TStringBuf name) const;
98
106 template <typename T>
107 TJobStatisticsEntry<T> GetStatisticsAs(TStringBuf name) const;
108
111 TVector<TString> GetStatisticsNames() const;
112
117 bool HasCustomStatistics(TStringBuf name) const;
118
123 TJobStatisticsEntry<i64> GetCustomStatistics(TStringBuf name) const;
124
129 template <typename T>
130 TJobStatisticsEntry<T> GetCustomStatisticsAs(TStringBuf name) const;
131
134 TVector<TString> GetCustomStatisticsNames() const;
135
136private:
137 class TData;
138 struct TFilter;
139
140 struct TDataEntry {
141 i64 Max;
142 i64 Min;
143 i64 Sum;
144 i64 Count;
145 };
146
147 static const TString CustomStatisticsNamePrefix_;
148
149private:
150 TJobStatistics(::TIntrusivePtr<TData> data, ::TIntrusivePtr<TFilter> filter);
151
152 TMaybe<TDataEntry> GetStatisticsImpl(TStringBuf name) const;
153
154private:
155 ::TIntrusivePtr<TData> Data_;
156 ::TIntrusivePtr<TFilter> Filter_;
157
158private:
159 template<typename T>
160 friend class TJobStatisticsEntry;
161};
162
164
166template <typename T>
167class TJobStatisticsEntry
168{
169public:
170 TJobStatisticsEntry(TMaybe<TJobStatistics::TDataEntry> data)
171 : Data_(std::move(data))
172 { }
173
175 TMaybe<T> Sum() const
176 {
177 if (Data_) {
178 return ConvertJobStatisticsEntry<T>(Data_->Sum);
179 }
180 return Nothing();
181 }
182
186 TMaybe<T> Avg() const
187 {
188 if (Data_ && Data_->Count) {
189 return ConvertJobStatisticsEntry<T>(Data_->Sum / Data_->Count);
190 }
191 return Nothing();
192 }
193
195 TMaybe<T> Count() const
196 {
197 if (Data_) {
198 return ConvertJobStatisticsEntry<T>(Data_->Count);
199 }
200 return Nothing();
201 }
202
204 TMaybe<T> Max() const
205 {
206 if (Data_) {
207 return ConvertJobStatisticsEntry<T>(Data_->Max);
208 }
209 return Nothing();
210 }
211
213 TMaybe<T> Min() const
214 {
215 if (Data_) {
216 return ConvertJobStatisticsEntry<T>(Data_->Min);
217 }
218 return Nothing();
219 }
220
221private:
222 TMaybe<TJobStatistics::TDataEntry> Data_;
223
224private:
225 friend class TJobStatistics;
226};
227
229
230template <typename T>
231TJobStatisticsEntry<T> TJobStatistics::GetStatisticsAs(TStringBuf name) const
232{
233 return TJobStatisticsEntry<T>(GetStatisticsImpl(name));
234}
235
236template <typename T>
237TJobStatisticsEntry<T> TJobStatistics::GetCustomStatisticsAs(TStringBuf name) const
238{
239 return TJobStatisticsEntry<T>(GetStatisticsImpl(CustomStatisticsNamePrefix_ + name));
240}
241
243
252void WriteCustomStatistics(TStringBuf path, i64 value);
253
260void WriteCustomStatistics(const TNode& statistics);
261
267
268} // namespace NYT
Class representing single statistic.
Definition job_statistics.h:168
TMaybe< T > Avg() const
Average of the statistic over all jobs.
Definition job_statistics.h:186
TMaybe< T > Count() const
Number of jobs that emitted this statistic.
Definition job_statistics.h:195
TMaybe< T > Max() const
Maximum value of the statistic over all jobs.
Definition job_statistics.h:204
TMaybe< T > Sum() const
Sum of the statistic over all jobs.
Definition job_statistics.h:175
TMaybe< T > Min() const
Minimum value of the statistic over all jobs.
Definition job_statistics.h:213
Class representing a collection of job statistics.
Definition job_statistics.h:35
TJobStatisticsEntry< i64 > GetStatistics(TStringBuf name) const
Get statistics by name.
TVector< TString > GetCustomStatisticsNames() const
Get names of all custom statistics.
TJobStatistics JobState(TVector< EJobState > filter) const
Filter statistics by job state.
TJobStatisticsEntry< i64 > GetCustomStatistics(TStringBuf name) const
Get custom statistics (those the user can write in job with NYT::WriteCustomStatistics).
TJobStatistics()
Construct empty statistics.
TJobStatistics TaskName(TVector< TTaskName > taskNames) const
Filter statistics by task name.
TJobStatistics(const NYT::TNode &statistics)
Construct statistics from statistics node.
bool HasCustomStatistics(TStringBuf name) const
Check if given custom statistics exists.
bool HasStatistics(TStringBuf name) const
Check that given statistics exist.
TJobStatisticsEntry< T > GetStatisticsAs(TStringBuf name) const
Get statistics by name.
Definition job_statistics.h:231
TVector< TString > GetStatisticsNames() const
Get (slash separated) names of statistics.
TJobStatisticsEntry< T > GetCustomStatisticsAs(TStringBuf name) const
Get custom statistics (those the user can write in job with NYT::WriteCustomStatistics).
Definition job_statistics.h:237
TJobStatistics JobType(TVector< EJobType > filter) const
Filter statistics by job type.
Main namespace of YT client.
Definition abortable_stream.h:7
void FlushCustomStatisticsStream()
Flush custom statistics stream.
void WriteCustomStatistics(TStringBuf path, i64 value)
Write custom statistics.
T ConvertJobStatisticsEntry(i64 value)
Convert i64 representation of statistics to other type.