profile.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "profile.h"
  2. #include "log.h"
  3. #include <util/stream/format.h>
  4. #define YQL_PERF_LOG(level, file, line) YQL_LOG_IMPL( \
  5. ::NYql::NLog::YqlLogger(), ::NYql::NLog::EComponent::Perf, level, \
  6. ::NYql::NLog::TContextPreprocessor, file, line)
  7. namespace NYql {
  8. namespace NLog {
  9. TProfilingScope::~TProfilingScope() {
  10. if (Name_ == nullptr) {
  11. return;
  12. }
  13. double elapsed = static_cast<double>(::MicroSeconds() - StartedAt_);
  14. TStringBuf unit("us");
  15. if (elapsed > 1000000) {
  16. elapsed /= 1000000;
  17. unit = TStringBuf("s");
  18. } else if (elapsed > 1000) {
  19. elapsed /= 1000;
  20. unit = TStringBuf("ms");
  21. }
  22. auto doLog = [&]() {
  23. YQL_PERF_LOG(Level_, File_, Line_)
  24. << TStringBuf("Execution of [") << Name_
  25. << TStringBuf("] took ") << Prec(elapsed, 3) << unit;
  26. };
  27. if (!LogCtxPath_.first.empty() || !LogCtxPath_.second.empty()) {
  28. YQL_LOG_CTX_ROOT_SESSION_SCOPE(LogCtxPath_);
  29. doLog();
  30. } else {
  31. doLog();
  32. }
  33. }
  34. } // namspace NLog
  35. } // namspace NYql