Skip to content

Commit

Permalink
Backport #55029 to 23.8: ProfileEvents added ContextLockWaitMicroseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-clickhouse committed Sep 27, 2023
1 parent 05137ed commit 9662267
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Common/ProfileEvents.cpp
Expand Up @@ -211,6 +211,7 @@
\
M(RegexpCreated, "Compiled regular expressions. Identical regular expressions compiled just once and cached forever.") \
M(ContextLock, "Number of times the lock of Context was acquired or tried to acquire. This is global lock.") \
M(ContextLockWaitMicroseconds, "Context lock wait time in microseconds") \
\
M(StorageBufferFlush, "Number of times a buffer in a 'Buffer' table was flushed.") \
M(StorageBufferErrorOnFlush, "Number of times a buffer in the 'Buffer' table has not been able to flush due to error writing in the destination table.") \
Expand Down
6 changes: 5 additions & 1 deletion src/Interpreters/Context.cpp
Expand Up @@ -111,6 +111,7 @@ namespace fs = std::filesystem;
namespace ProfileEvents
{
extern const Event ContextLock;
extern const Event ContextLockWaitMicroseconds;
}

namespace CurrentMetrics
Expand Down Expand Up @@ -721,7 +722,10 @@ std::unique_lock<std::recursive_mutex> Context::getLock() const
{
ProfileEvents::increment(ProfileEvents::ContextLock);
CurrentMetrics::Increment increment{CurrentMetrics::ContextLockWait};
return std::unique_lock(shared->mutex);
Stopwatch watch;
auto lock = std::unique_lock(shared->mutex);
ProfileEvents::increment(ProfileEvents::ContextLockWaitMicroseconds, watch.elapsedMicroseconds());
return lock;
}

ProcessList & Context::getProcessList() { return shared->process_list; }
Expand Down

0 comments on commit 9662267

Please sign in to comment.