Fix profile events.

This commit is contained in:
Vitaly Baranov 2023-12-11 15:55:34 +01:00
parent ff1e95c357
commit ca262d6e10
2 changed files with 10 additions and 6 deletions

View File

@ -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(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(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(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.") \ M(ThreadPoolReaderPageCacheHitBytes, "Number of bytes read inside ThreadPoolReader when it was done from page cache.") \

View File

@ -17,6 +17,7 @@ namespace ProfileEvents
{ {
extern const Event SleepFunctionCalls; extern const Event SleepFunctionCalls;
extern const Event SleepFunctionMicroseconds; extern const Event SleepFunctionMicroseconds;
extern const Event SleepFunctionElapsedMicroseconds;
} }
namespace DB namespace DB
@ -134,14 +135,15 @@ public:
"The maximum sleep time is {} microseconds. Requested: {} microseconds per block (of size {})", "The maximum sleep time is {} microseconds. Requested: {} microseconds per block (of size {})",
max_microseconds, microseconds, 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) if (query_status)
sleep_ms = std::min(sleep_ms, /* 1 second */ static_cast<size_t>(1000000)); sleep_time = std::min(sleep_time, /* 1 second */ static_cast<size_t>(1000000));
sleepForMicroseconds(sleep_ms); sleepForMicroseconds(sleep_time);
microseconds -= sleep_ms; elapsed += sleep_time;
if (query_status && !query_status->checkTimeLimit()) if (query_status && !query_status->checkTimeLimit())
break; break;
@ -149,6 +151,7 @@ public:
ProfileEvents::increment(ProfileEvents::SleepFunctionCalls, count); ProfileEvents::increment(ProfileEvents::SleepFunctionCalls, count);
ProfileEvents::increment(ProfileEvents::SleepFunctionMicroseconds, microseconds); ProfileEvents::increment(ProfileEvents::SleepFunctionMicroseconds, microseconds);
ProfileEvents::increment(ProfileEvents::SleepFunctionElapsedMicroseconds, elapsed);
} }
} }