diff --git a/src/Common/ProfileEvents.cpp b/src/Common/ProfileEvents.cpp index f9ea03f4947..7d6abd587c5 100644 --- a/src/Common/ProfileEvents.cpp +++ b/src/Common/ProfileEvents.cpp @@ -456,7 +456,8 @@ The server successfully detected this situation and will download merged part fr M(ReadBufferSeekCancelConnection, "Number of seeks which lead to new connection (s3, http)") \ \ M(SleepFunctionCalls, "Number of times a sleep function (sleep, sleepEachRow) has been called.") \ - M(SleepFunctionMicroseconds, "Time spent sleeping due to a sleep function call.") \ + M(SleepFunctionMicroseconds, "Time set to sleep in a sleep function (sleep, sleepEachRow).") \ + M(SleepFunctionElapsedMicroseconds, "Time spent sleeping in a sleep function (sleep, sleepEachRow).") \ \ M(ThreadPoolReaderPageCacheHit, "Number of times the read inside ThreadPoolReader was done from page cache.") \ M(ThreadPoolReaderPageCacheHitBytes, "Number of bytes read inside ThreadPoolReader when it was done from page cache.") \ diff --git a/src/Functions/sleep.h b/src/Functions/sleep.h index 11b8e48a295..f5d3b6f29cd 100644 --- a/src/Functions/sleep.h +++ b/src/Functions/sleep.h @@ -17,6 +17,7 @@ namespace ProfileEvents { extern const Event SleepFunctionCalls; extern const Event SleepFunctionMicroseconds; +extern const Event SleepFunctionElapsedMicroseconds; } namespace DB @@ -134,14 +135,15 @@ public: "The maximum sleep time is {} microseconds. Requested: {} microseconds per block (of size {})", max_microseconds, microseconds, size); - while (microseconds) + UInt64 elapsed = 0; + while (elapsed < microseconds) { - UInt64 sleep_ms = microseconds; + UInt64 sleep_time = microseconds - elapsed; if (query_status) - sleep_ms = std::min(sleep_ms, /* 1 second */ static_cast(1000000)); + sleep_time = std::min(sleep_time, /* 1 second */ static_cast(1000000)); - sleepForMicroseconds(sleep_ms); - microseconds -= sleep_ms; + sleepForMicroseconds(sleep_time); + elapsed += sleep_time; if (query_status && !query_status->checkTimeLimit()) break; @@ -149,6 +151,7 @@ public: ProfileEvents::increment(ProfileEvents::SleepFunctionCalls, count); ProfileEvents::increment(ProfileEvents::SleepFunctionMicroseconds, microseconds); + ProfileEvents::increment(ProfileEvents::SleepFunctionElapsedMicroseconds, elapsed); } }