-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6618cd8
commit efa48d5
Showing
26 changed files
with
20 additions
and
1,833 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
add_subdirectory(charset) | ||
add_subdirectory(draft) | ||
|
||
add_library(yutil) | ||
target_compile_options(yutil PRIVATE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,27 @@ | ||
#pragma once | ||
|
||
#include "base.h" | ||
|
||
#include <util/system/rusage.h> | ||
#include <util/stream/str.h> | ||
#include <chrono> | ||
|
||
class TTimer { | ||
private: | ||
TInstant Start_; | ||
TStringStream Message_; | ||
using TClock = std::chrono::high_resolution_clock; | ||
|
||
TClock Clock_; | ||
std::chrono::time_point<TClock, TClock::duration> Start_; | ||
std::stringstream Message_; | ||
|
||
public: | ||
TTimer(const std::string_view message = " took: "); | ||
~TTimer(); | ||
}; | ||
|
||
class TSimpleTimer { | ||
TInstant T; | ||
|
||
public: | ||
TSimpleTimer() { | ||
Reset(); | ||
} | ||
TDuration Get() const { | ||
return TInstant::Now() - T; | ||
} | ||
void Reset() { | ||
T = TInstant::Now(); | ||
} | ||
}; | ||
|
||
class TProfileTimer { | ||
TDuration T; | ||
|
||
public: | ||
TProfileTimer() { | ||
Reset(); | ||
} | ||
TDuration Get() const { | ||
return TRusage::Get().Utime - T; | ||
} | ||
TDuration Step() { | ||
TRusage r; | ||
r.Fill(); | ||
TDuration d = r.Utime - T; | ||
T = r.Utime; | ||
return d; | ||
} | ||
void Reset() { | ||
T = TRusage::Get().Utime; | ||
} | ||
}; | ||
|
||
/// 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(); | ||
void SetCyclesPerSecond(ui64 cycles); | ||
|
||
TDuration CyclesToDuration(ui64 cycles); | ||
ui64 DurationToCycles(TDuration duration); | ||
|
||
// NBS-3400 - CyclesToDuration and DurationToCycles may overflow for long running events | ||
TDuration CyclesToDurationSafe(ui64 cycles); | ||
ui64 DurationToCyclesSafe(TDuration duration); | ||
|
||
class TPrecisionTimer { | ||
private: | ||
ui64 Start = 0; | ||
|
||
public: | ||
TPrecisionTimer(); | ||
|
||
ui64 GetCycleCount() const; | ||
}; | ||
|
||
std::string FormatCycles(ui64 cycles); | ||
|
||
class TFuncTimer { | ||
using TClock = std::chrono::high_resolution_clock; | ||
public: | ||
TFuncTimer(const char* func); | ||
~TFuncTimer(); | ||
|
||
private: | ||
const TInstant Start_; | ||
TClock Clock_; | ||
const std::chrono::time_point<TClock, TClock::duration> Start_; | ||
const char* Func_; | ||
}; | ||
|
||
class TFakeTimer { | ||
public: | ||
inline TFakeTimer(const char* = nullptr) noexcept { | ||
} | ||
}; | ||
|
||
#if defined(WITH_DEBUG) | ||
#define TDebugTimer TFuncTimer | ||
#else | ||
#define TDebugTimer TFakeTimer | ||
#endif | ||
|
||
class TTimeLogger { | ||
private: | ||
std::string Message; | ||
bool Verbose; | ||
bool OK; | ||
time_t Begin; | ||
ui64 BeginCycles; | ||
|
||
public: | ||
TTimeLogger(const std::string& message, bool verbose = true); | ||
~TTimeLogger(); | ||
|
||
void SetOK(); | ||
double ElapsedTime() const; | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.