55 default:
return "UNKNOWN";
171 return std::chrono::steady_clock::now() -
state_since;
194 return static_cast<double>(
jobs_completed) /
static_cast<double>(total);
224 if (total_time.count() == 0)
231 static_cast<double>(total_time.count());
241 return std::chrono::duration<double, std::milli>(
total_busy_time).count();
250 return std::chrono::duration<double, std::milli>(
total_idle_time).count();
277 std::ostringstream oss;
279 oss <<
" \"worker_id\": " <<
worker_id <<
",\n";
280 oss <<
" \"thread_name\": \"" <<
thread_name <<
"\",\n";
283 std::ostringstream tid_oss;
285 oss <<
" \"thread_id\": \"" << tid_oss.str() <<
"\",\n";
288 oss << std::fixed << std::setprecision(3);
289 oss <<
" \"state_duration_ms\": "
290 << std::chrono::duration<double, std::milli>(
state_duration()).count() <<
",\n";
292 oss <<
" \"jobs_failed\": " <<
jobs_failed <<
",\n";
293 oss << std::setprecision(4);
294 oss <<
" \"success_rate\": " <<
success_rate() <<
",\n";
295 oss <<
" \"utilization\": " <<
utilization <<
",\n";
296 oss << std::setprecision(3);
297 oss <<
" \"busy_time_ms\": " <<
busy_time_ms() <<
",\n";
302 oss <<
",\n \"current_job\": " <<
current_job.value().to_json();
306 oss <<
",\n \"current_job\": null";
327 std::ostringstream oss;
329 auto duration_sec = std::chrono::duration<double>(
state_duration()).count();
334 <<
" (" << std::fixed << std::setprecision(1) << duration_sec <<
"s)\n";
340 auto exec_time_ms_val = std::chrono::duration<double, std::milli>(
341 job.execution_time).count();
342 oss <<
" Current Job: " <<
job.job_name <<
"#" <<
job.job_id
343 <<
" (running " << std::setprecision(0) << exec_time_ms_val <<
"ms)\n";
349 << std::setprecision(1) << (
success_rate() * 100.0) <<
"% success)\n";
352 oss <<
" Utilization: " << std::setprecision(1)
Represents a unit of work (task) to be executed, typically by a job queue.
worker_state
Current state of a worker thread.
@ stopping
Worker is in the process of stopping.
@ active
Worker is executing a job.
@ idle
Worker is waiting for jobs.
@ stopped
Worker has stopped.
Job information snapshot for diagnostics and monitoring.
auto worker_state_to_string(worker_state state) -> std::string
Converts worker_state to human-readable string.
Information about a worker thread in the pool.
double utilization
Worker utilization ratio.
worker_state state
Current operational state of the worker.
std::size_t worker_id
Worker ID within the pool.
std::thread::id thread_id
System thread ID.
auto is_busy() const -> bool
Checks if the worker is currently processing a job.
std::uint64_t jobs_completed
Total number of jobs successfully completed by this worker.
auto success_rate() const -> double
Calculates the success rate.
auto total_jobs() const -> std::uint64_t
Gets the total number of jobs processed (completed + failed).
auto to_string() const -> std::string
Converts the thread info to a human-readable string.
auto idle_time_ms() const -> double
Converts idle time to milliseconds.
std::chrono::nanoseconds total_busy_time
Total time spent executing jobs (busy time).
std::uint64_t jobs_failed
Total number of jobs that failed during execution.
std::string thread_name
Human-readable name for this thread.
std::chrono::steady_clock::time_point state_since
Time when the worker entered its current state.
auto busy_time_ms() const -> double
Converts busy time to milliseconds.
auto state_duration() const -> std::chrono::nanoseconds
Calculates the duration in the current state.
std::chrono::nanoseconds total_idle_time
Total time spent waiting for jobs (idle time).
auto is_available() const -> bool
Checks if the worker is available to process jobs.
auto update_utilization() -> void
Recalculates utilization based on busy and idle times.
auto to_json() const -> std::string
Converts the thread info to a JSON string.
std::optional< job_info > current_job
Information about the currently executing job.