Skip to content

Commit

Permalink
addind some metrics to worker
Browse files Browse the repository at this point in the history
  • Loading branch information
filimonov committed Jan 22, 2024
1 parent 3c1e3bc commit 7cbfee6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Common/ProfileEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
M(GlobalThreadPoolJobEmplacementMicroseconds, "") \
M(GlobalThreadPoolCondVarWaitingMicroseconds, "") \
M(GlobalThreadPoolJobsCounter, "") \
M(GlobalThreadPoolWorkerLoops, "") \
M(GlobalThreadPoolWorkerLockWaitMicroseconds, "") \
M(GlobalThreadPoolWorkerLockHoldingMicroseconds, "") \
\
M(LocalThreadPoolExpansions, "Counts the total number of times threads were borrowed from the global thread pool to expand local thread pools.") \
M(LocalThreadPoolShrinks, "Counts the total number of times threads were returned to the global thread pool from local thread pools.") \
Expand All @@ -89,6 +92,9 @@
M(LocalThreadPoolJobEmplacementMicroseconds, "") \
M(LocalThreadPoolCondVarWaitingMicroseconds, "") \
M(LocalThreadPoolJobsCounter, "") \
M(LocalThreadPoolWorkerLoops, "") \
M(LocalThreadPoolWorkerLockWaitMicroseconds, "") \
M(LocalThreadPoolWorkerLockHoldingMicroseconds, "") \
\
M(DiskS3GetRequestThrottlerCount, "Number of DiskS3 GET and SELECT requests passed through throttler.") \
M(DiskS3GetRequestThrottlerSleepMicroseconds, "Total time a query was sleeping to conform DiskS3 GET and SELECT request throttling.") \
Expand Down
21 changes: 21 additions & 0 deletions src/Common/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace ProfileEvents
extern const Event GlobalThreadPoolJobEmplacementMicroseconds;
extern const Event GlobalThreadPoolJobsCounter;
extern const Event GlobalThreadPoolCondVarWaitingMicroseconds;
extern const Event GlobalThreadPoolWorkerLoops;
extern const Event GlobalThreadPoolWorkerLockWaitMicroseconds;
extern const Event GlobalThreadPoolWorkerLockHoldingMicroseconds;


extern const Event LocalThreadPoolExpansions;
extern const Event LocalThreadPoolShrinks;
Expand All @@ -48,6 +52,10 @@ namespace ProfileEvents
extern const Event LocalThreadPoolJobEmplacementMicroseconds;
extern const Event LocalThreadPoolJobsCounter;
extern const Event LocalThreadPoolCondVarWaitingMicroseconds;
extern const Event LocalThreadPoolWorkerLoops;
extern const Event LocalThreadPoolWorkerLockWaitMicroseconds;
extern const Event LocalThreadPoolWorkerLockHoldingMicroseconds;

}

class JobWithPriority
Expand Down Expand Up @@ -463,11 +471,20 @@ void ThreadPoolImpl<Thread>::worker(typename std::list<Thread>::iterator thread_
/// This is inside the loop to also reset previous thread names set inside the jobs.
setThreadName(DEFAULT_THREAD_NAME);

ProfileEvents::increment( std::is_same_v<Thread, std::thread> ? ProfileEvents::GlobalThreadPoolWorkerLoops : ProfileEvents::LocalThreadPoolWorkerLoops);


/// Get a job from the queue.
std::optional<JobWithPriority> job_data;

{
Stopwatch watch;
std::unique_lock lock(mutex);
ProfileEvents::increment(
std::is_same_v<Thread, std::thread> ? ProfileEvents::GlobalThreadPoolWorkerLockWaitMicroseconds : ProfileEvents::LocalThreadPoolWorkerLockWaitMicroseconds,
watch.elapsedMicroseconds());

watch.restart();

// Finish with previous job if any
if (job_is_done)
Expand Down Expand Up @@ -518,6 +535,10 @@ void ThreadPoolImpl<Thread>::worker(typename std::list<Thread>::iterator thread_
job_is_done = true;
continue;
}

ProfileEvents::increment(
std::is_same_v<Thread, std::thread> ? ProfileEvents::GlobalThreadPoolWorkerLockHoldingMicroseconds : ProfileEvents::LocalThreadPoolWorkerLockHoldingMicroseconds,
watch.elapsedMicroseconds());
}

ALLOW_ALLOCATIONS_IN_SCOPE;
Expand Down

0 comments on commit 7cbfee6

Please sign in to comment.