aboutsummaryrefslogtreecommitdiffstats
path: root/util/datetime
diff options
context:
space:
mode:
authordenplusplus <denplusplus@yandex-team.ru>2022-02-10 16:47:34 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:34 +0300
commit57c20d143e8a438cd76b9fdc3ca2e8ee3ac1f32a (patch)
treecc63639f8e502db19a82c20e2861c6d1edbf9fea /util/datetime
parent464ba3814a83db4f2d5327393b0b6eaf0c86bfd7 (diff)
downloadydb-57c20d143e8a438cd76b9fdc3ca2e8ee3ac1f32a.tar.gz
Restoring authorship annotation for <denplusplus@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/datetime')
-rw-r--r--util/datetime/constants.h4
-rw-r--r--util/datetime/cputimer.cpp112
-rw-r--r--util/datetime/cputimer.h48
3 files changed, 82 insertions, 82 deletions
diff --git a/util/datetime/constants.h b/util/datetime/constants.h
index 352403270e..a6395da3d3 100644
--- a/util/datetime/constants.h
+++ b/util/datetime/constants.h
@@ -1,7 +1,7 @@
#pragma once
-#include <time.h>
+#include <time.h>
const time_t SECONDS_IN_DAY = 86400;
const time_t SECONDS_IN_HOUR = 3600;
-const time_t SECONDS_IN_HALFHOUR = 1800;
+const time_t SECONDS_IN_HALFHOUR = 1800;
diff --git a/util/datetime/cputimer.cpp b/util/datetime/cputimer.cpp
index 516d372c37..a4e8eb1cbc 100644
--- a/util/datetime/cputimer.cpp
+++ b/util/datetime/cputimer.cpp
@@ -1,12 +1,12 @@
-#include "cputimer.h"
+#include "cputimer.h"
-#include <util/system/defaults.h>
+#include <util/system/defaults.h>
#include <util/system/hp_timer.h>
#include <util/string/printf.h>
#include <util/stream/output.h>
-#include <util/generic/singleton.h>
+#include <util/generic/singleton.h>
-#if defined(_unix_)
+#if defined(_unix_)
#include <unistd.h>
#include <sched.h>
#include <sys/types.h>
@@ -21,15 +21,15 @@ TTimer::TTimer(const TStringBuf message) {
Message_.Reserve(message.length() + SMALL_DURATION_CHAR_LENGTH + 1); // +"\n"
Message_ << message;
// Do not measure the allocations above.
- Start_ = TInstant::Now();
-}
-
-TTimer::~TTimer() {
+ Start_ = TInstant::Now();
+}
+
+TTimer::~TTimer() {
const TDuration duration = TInstant::Now() - Start_;
Message_ << duration << "\n";
Cerr << Message_.Str();
-}
-
+}
+
static ui64 ManuallySetCyclesPerSecond = 0;
static ui64 GetCyclesPerSecond() {
@@ -38,8 +38,8 @@ static ui64 GetCyclesPerSecond() {
} else {
return NHPTimer::GetCyclesPerSecond();
}
-}
-
+}
+
void SetCyclesPerSecond(ui64 cycles) {
ManuallySetCyclesPerSecond = cycles;
}
@@ -58,79 +58,79 @@ ui64 DurationToCycles(TDuration duration) {
TPrecisionTimer::TPrecisionTimer()
: Start(::GetCycleCount())
-{
-}
-
+{
+}
+
ui64 TPrecisionTimer::GetCycleCount() const {
return ::GetCycleCount() - Start;
-}
-
+}
+
TString FormatCycles(ui64 cycles) {
- ui64 milliseconds = cycles / GetCyclesPerMillisecond();
- ui32 ms = ui32(milliseconds % 1000);
- milliseconds /= 1000;
- ui32 secs = ui32(milliseconds % 60);
- milliseconds /= 60;
- ui32 mins = ui32(milliseconds);
+ ui64 milliseconds = cycles / GetCyclesPerMillisecond();
+ ui32 ms = ui32(milliseconds % 1000);
+ milliseconds /= 1000;
+ ui32 secs = ui32(milliseconds % 60);
+ milliseconds /= 60;
+ ui32 mins = ui32(milliseconds);
TString result;
- sprintf(result, "%" PRIu32 " m %.2" PRIu32 " s %.3" PRIu32 " ms", mins, secs, ms);
- return result;
-}
-
+ sprintf(result, "%" PRIu32 " m %.2" PRIu32 " s %.3" PRIu32 " ms", mins, secs, ms);
+ return result;
+}
+
TFormattedPrecisionTimer::TFormattedPrecisionTimer(const char* message, IOutputStream* out)
: Message(message)
, Out(out)
-{
- Start = GetCycleCount();
-}
-
+{
+ Start = GetCycleCount();
+}
+
TFormattedPrecisionTimer::~TFormattedPrecisionTimer() {
const ui64 end = GetCycleCount();
const ui64 diff = end - Start;
*Out << Message << ": " << diff << " ticks " << FormatCycles(diff) << Endl;
-}
-
-TFuncTimer::TFuncTimer(const char* func)
- : Start_(TInstant::Now())
- , Func_(func)
-{
- Cerr << "enter " << Func_ << Endl;
-}
-
+}
+
+TFuncTimer::TFuncTimer(const char* func)
+ : Start_(TInstant::Now())
+ , Func_(func)
+{
+ Cerr << "enter " << Func_ << Endl;
+}
+
TFuncTimer::~TFuncTimer() {
- Cerr << "leave " << Func_ << " -> " << (TInstant::Now() - Start_) << Endl;
-}
-
+ Cerr << "leave " << Func_ << " -> " << (TInstant::Now() - Start_) << Endl;
+}
+
TTimeLogger::TTimeLogger(const TString& message, bool verbose)
: Message(message)
- , Verbose(verbose)
+ , Verbose(verbose)
, OK(false)
, Begin(time(nullptr))
- , BeginCycles(GetCycleCount())
+ , BeginCycles(GetCycleCount())
{
- if (Verbose) {
- fprintf(stderr, "=========================================================\n");
+ if (Verbose) {
+ fprintf(stderr, "=========================================================\n");
fprintf(stderr, "%s started: %.24s (%lu) (%d)\n", Message.data(), ctime(&Begin), (unsigned long)Begin, (int)getpid());
- }
+ }
}
-double TTimeLogger::ElapsedTime() const {
+double TTimeLogger::ElapsedTime() const {
return time(nullptr) - Begin;
-}
-
+}
+
void TTimeLogger::SetOK() {
OK = true;
}
TTimeLogger::~TTimeLogger() {
time_t tim = time(nullptr);
- ui64 endCycles = GetCycleCount();
- if (Verbose) {
- const char* prefix = (OK) ? "" : "!";
+ ui64 endCycles = GetCycleCount();
+ if (Verbose) {
+ const char* prefix = (OK) ? "" : "!";
fprintf(stderr, "%s%s ended: %.24s (%lu) (%d) (took %lus = %s)\n",
prefix, Message.data(), ctime(&tim), (unsigned long)tim, (int)getpid(),
(unsigned long)tim - (unsigned long)Begin, FormatCycles(endCycles - BeginCycles).data());
- fprintf(stderr, "%s=========================================================\n", prefix);
- }
+ fprintf(stderr, "%s=========================================================\n", prefix);
+ }
}
diff --git a/util/datetime/cputimer.h b/util/datetime/cputimer.h
index 7d38d5bdb3..d43102dff6 100644
--- a/util/datetime/cputimer.h
+++ b/util/datetime/cputimer.h
@@ -6,14 +6,14 @@
#include <util/generic/string.h>
#include <util/stream/str.h>
-class TTimer {
+class TTimer {
private:
TInstant Start_;
TStringStream Message_;
public:
TTimer(const TStringBuf message = TStringBuf(" took: "));
- ~TTimer();
+ ~TTimer();
};
class TSimpleTimer {
@@ -56,38 +56,38 @@ public:
/// Return cached processor cycle count per second. Method takes 1 second at first invocation.
/// Note, on older systems cycle rate may change during program lifetime,
/// so returned value may be incorrect. Modern Intel and AMD processors keep constant TSC rate.
-ui64 GetCyclesPerMillisecond();
+ui64 GetCyclesPerMillisecond();
void SetCyclesPerSecond(ui64 cycles);
-
+
TDuration CyclesToDuration(ui64 cycles);
ui64 DurationToCycles(TDuration duration);
class TPrecisionTimer {
-private:
+private:
ui64 Start = 0;
-
-public:
+
+public:
TPrecisionTimer();
ui64 GetCycleCount() const;
-};
-
+};
+
TString FormatCycles(ui64 cycles);
-
+
class TFormattedPrecisionTimer {
-private:
- ui64 Start;
- const char* Message;
+private:
+ ui64 Start;
+ const char* Message;
IOutputStream* Out;
-
-public:
+
+public:
TFormattedPrecisionTimer(const char* message = "took ", IOutputStream* out = &Cout);
- ~TFormattedPrecisionTimer();
-};
-
+ ~TFormattedPrecisionTimer();
+};
+
class TFuncTimer {
public:
- TFuncTimer(const char* func);
+ TFuncTimer(const char* func);
~TFuncTimer();
private:
@@ -105,20 +105,20 @@ public:
#define TDebugTimer TFuncTimer
#else
#define TDebugTimer TFakeTimer
-#endif
+#endif
class TTimeLogger {
private:
TString Message;
- bool Verbose;
+ bool Verbose;
bool OK;
- time_t Begin;
- ui64 BeginCycles;
+ time_t Begin;
+ ui64 BeginCycles;
public:
TTimeLogger(const TString& message, bool verbose = true);
~TTimeLogger();
void SetOK();
- double ElapsedTime() const;
+ double ElapsedTime() const;
};