aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/library/user_job_statistics/user_job_statistics.h
diff options
context:
space:
mode:
authorermolovd <ermolovd@yandex-team.com>2023-10-02 16:28:29 +0300
committerermolovd <ermolovd@yandex-team.com>2023-10-02 17:46:23 +0300
commit2dd58a8a79545037b218d32588215396fc850f9f (patch)
treea44470c4215792eca451ceb95f7230c1589a73d0 /yt/cpp/mapreduce/library/user_job_statistics/user_job_statistics.h
parent45d9242d89e0811f346018242fde0dcfd1786202 (diff)
downloadydb-2dd58a8a79545037b218d32588215396fc850f9f.tar.gz
YT-19578: Move user_job_statistics to yt/cpp/mapreduce/library
Diffstat (limited to 'yt/cpp/mapreduce/library/user_job_statistics/user_job_statistics.h')
-rw-r--r--yt/cpp/mapreduce/library/user_job_statistics/user_job_statistics.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/library/user_job_statistics/user_job_statistics.h b/yt/cpp/mapreduce/library/user_job_statistics/user_job_statistics.h
new file mode 100644
index 0000000000..6939d20417
--- /dev/null
+++ b/yt/cpp/mapreduce/library/user_job_statistics/user_job_statistics.h
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <util/stream/file.h>
+#include <util/generic/hash.h>
+#include <util/datetime/cputimer.h>
+
+namespace NYtTools {
+ class TTimeStat;
+ using TTimeStatHolder = THolder<TTimeStat>;
+
+ class TUserJobStatsProxy {
+ public:
+ static const FHANDLE JobStatisticsHandle;
+ private:
+ THolder<IOutputStream> FetchedOut;
+ IOutputStream* UsingStream = &Cerr;
+ public:
+ // TODO: add inheritance
+ THashMap<TString, i64> Stats;//will be dumped in CommitStats or desctructor
+ THashMap<TString, TDuration> TimeStats;//will be dumped in CommitStats or desctructor
+
+ TUserJobStatsProxy() { Init(nullptr); }
+ ~TUserJobStatsProxy() {
+ CommitStats();
+ }
+ TUserJobStatsProxy (IOutputStream* usingStream) {Init(usingStream);}
+
+ void Init(IOutputStream* usingStream);
+ void InitChecked(IOutputStream* ifNotInJob);
+ void InitIfNotInited(IOutputStream* usingStream);
+ IOutputStream* GetStream() const { return UsingStream; }
+ void CommitStats();
+ void WriteStat(TString name, i64 val); //immidiatly wirtes stat
+ void WriteStatNoFlush(TString name, i64 val); //immidiatly wirtes stat but do not flush it
+
+ //@param name name of statistic to be written in millisecs from creation to destruction
+ //@param commitOnFinish if false: will update state/write on job finish; if true: write stat in destructor
+ TTimeStatHolder TimerStart(TString name, bool commitOnFinish = false);
+ };
+
+ class TTimeStat {
+ TUserJobStatsProxy* Parent;
+ TString Name;
+ bool Commit;
+
+ TTimeStat(TUserJobStatsProxy* parent, TString name, bool commit);
+ friend class TUserJobStatsProxy;
+
+ TSimpleTimer Timer;
+ public:
+ ~TTimeStat();
+ TDuration Get() const {
+ return Timer.Get();
+ }
+ void Cancel();
+ void Finish();
+ };
+}