Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::diagnostics::bottleneck_report Struct Reference

Analysis report of bottlenecks in the thread pool. More...

#include <bottleneck_report.h>

Collaboration diagram for kcenon::thread::diagnostics::bottleneck_report:
Collaboration graph

Public Member Functions

auto severity () const -> int
 Gets the severity level of the bottleneck.
 
auto severity_string () const -> std::string
 Gets severity as a string.
 
auto requires_immediate_action () const -> bool
 Checks if immediate action is required.
 
auto to_json () const -> std::string
 Converts the bottleneck report to a JSON string.
 
auto to_string () const -> std::string
 Converts the bottleneck report to a human-readable string.
 

Public Attributes

bool has_bottleneck {false}
 Whether a bottleneck was detected.
 
std::string description
 Human-readable description of the bottleneck.
 
bottleneck_type type {bottleneck_type::none}
 Type of bottleneck detected.
 
double queue_saturation {0.0}
 Queue saturation level.
 
double avg_wait_time_ms {0.0}
 Average wait time in milliseconds.
 
double worker_utilization {0.0}
 Average worker utilization.
 
std::size_t estimated_backlog_time_ms {0}
 Estimated time to process the current backlog.
 
double utilization_variance {0.0}
 Variance in worker utilization.
 
std::uint64_t jobs_rejected {0}
 Jobs rejected due to queue full.
 
std::size_t queue_depth {0}
 Current queue depth.
 
std::size_t idle_workers {0}
 Number of idle workers.
 
std::size_t total_workers {0}
 Total number of workers.
 
std::vector< std::string > recommendations
 Actionable recommendations to resolve the bottleneck.
 

Detailed Description

Analysis report of bottlenecks in the thread pool.

Contains the results of bottleneck analysis including the type of bottleneck detected, supporting metrics, and actionable recommendations.

Diagnosis Logic

avg_wait_time > threshold && worker_utilization > 0.9 → slow_consumer
utilization variance highuneven_distribution
@ high
Above high_watermark, approaching capacity.
@ slow_consumer
Workers can't keep up with job submission rate.
@ worker_starvation
Not enough workers for the workload.
@ uneven_distribution
Work is not evenly distributed (work stealing needed)
double worker_utilization
Average worker utilization.

Usage Example

auto report = pool->diagnostics().detect_bottlenecks();
if (report.has_bottleneck) {
LOG_WARN("Bottleneck: {} - {}", bottleneck_type_to_string(report.type),
report.description);
for (const auto& rec : report.recommendations) {
LOG_INFO(" Recommendation: {}", rec);
}
}
auto bottleneck_type_to_string(bottleneck_type type) -> std::string
Converts bottleneck_type to human-readable string.

Definition at line 91 of file bottleneck_report.h.

Member Function Documentation

◆ requires_immediate_action()

auto kcenon::thread::diagnostics::bottleneck_report::requires_immediate_action ( ) const -> bool
inlinenodiscard

Checks if immediate action is required.

Returns
true if severity is critical (3).

Definition at line 234 of file bottleneck_report.h.

235 {
236 return severity() >= 3;
237 }
auto severity() const -> int
Gets the severity level of the bottleneck.

References severity().

Here is the call graph for this function:

◆ severity()

auto kcenon::thread::diagnostics::bottleneck_report::severity ( ) const -> int
inlinenodiscard

Gets the severity level of the bottleneck.

Returns
Severity from 0 (none) to 3 (critical).

Definition at line 191 of file bottleneck_report.h.

192 {
193 if (!has_bottleneck)
194 {
195 return 0;
196 }
197
198 // Critical: queue full or severe worker starvation
199 if (queue_saturation > 0.95 || worker_utilization > 0.98)
200 {
201 return 3;
202 }
203
204 // High: approaching capacity
205 if (queue_saturation > 0.8 || worker_utilization > 0.9)
206 {
207 return 2;
208 }
209
210 // Medium: noticeable but not urgent
211 return 1;
212 }
bool has_bottleneck
Whether a bottleneck was detected.

References has_bottleneck, queue_saturation, and worker_utilization.

Referenced by requires_immediate_action(), and severity_string().

Here is the caller graph for this function:

◆ severity_string()

auto kcenon::thread::diagnostics::bottleneck_report::severity_string ( ) const -> std::string
inlinenodiscard

Gets severity as a string.

Returns
Severity level string.

Definition at line 218 of file bottleneck_report.h.

219 {
220 switch (severity())
221 {
222 case 0: return "none";
223 case 1: return "low";
224 case 2: return "medium";
225 case 3: return "critical";
226 default: return "unknown";
227 }
228 }

References severity().

Referenced by to_json(), and to_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_json()

auto kcenon::thread::diagnostics::bottleneck_report::to_json ( ) const -> std::string
inlinenodiscard

Converts the bottleneck report to a JSON string.

Returns
JSON representation of the bottleneck report.

Output format:

{
"has_bottleneck": true,
"type": "slow_consumer",
"severity": "medium",
"description": "Workers cannot keep up with job submission rate",
"metrics": {
"queue_saturation": 0.75,
"avg_wait_time_ms": 150.5,
"worker_utilization": 0.92,
"utilization_variance": 0.05,
"estimated_backlog_time_ms": 5000,
"queue_depth": 100,
"idle_workers": 1,
"total_workers": 8,
"jobs_rejected": 0
},
"recommendations": [...]
}

Definition at line 265 of file bottleneck_report.h.

266 {
267 std::ostringstream oss;
268 oss << "{\n";
269 oss << " \"has_bottleneck\": " << (has_bottleneck ? "true" : "false") << ",\n";
270 oss << " \"type\": \"" << bottleneck_type_to_string(type) << "\",\n";
271 oss << " \"severity\": \"" << severity_string() << "\",\n";
272 oss << " \"description\": \"" << description << "\",\n";
273
274 // Metrics
275 oss << " \"metrics\": {\n";
276 oss << std::fixed << std::setprecision(4);
277 oss << " \"queue_saturation\": " << queue_saturation << ",\n";
278 oss << std::setprecision(3);
279 oss << " \"avg_wait_time_ms\": " << avg_wait_time_ms << ",\n";
280 oss << std::setprecision(4);
281 oss << " \"worker_utilization\": " << worker_utilization << ",\n";
282 oss << " \"utilization_variance\": " << utilization_variance << ",\n";
283 oss << " \"estimated_backlog_time_ms\": " << estimated_backlog_time_ms << ",\n";
284 oss << " \"queue_depth\": " << queue_depth << ",\n";
285 oss << " \"idle_workers\": " << idle_workers << ",\n";
286 oss << " \"total_workers\": " << total_workers << ",\n";
287 oss << " \"jobs_rejected\": " << jobs_rejected << "\n";
288 oss << " },\n";
289
290 // Recommendations
291 oss << " \"recommendations\": [";
292 for (std::size_t i = 0; i < recommendations.size(); ++i)
293 {
294 oss << "\n \"" << recommendations[i] << "\"";
295 if (i < recommendations.size() - 1)
296 {
297 oss << ",";
298 }
299 }
300 if (!recommendations.empty())
301 {
302 oss << "\n ";
303 }
304 oss << "]\n";
305
306 oss << "}";
307 return oss.str();
308 }
bottleneck_type type
Type of bottleneck detected.
double avg_wait_time_ms
Average wait time in milliseconds.
std::vector< std::string > recommendations
Actionable recommendations to resolve the bottleneck.
std::string description
Human-readable description of the bottleneck.
double utilization_variance
Variance in worker utilization.
std::uint64_t jobs_rejected
Jobs rejected due to queue full.
std::size_t estimated_backlog_time_ms
Estimated time to process the current backlog.
std::size_t idle_workers
Number of idle workers.
auto severity_string() const -> std::string
Gets severity as a string.
std::size_t total_workers
Total number of workers.

References avg_wait_time_ms, kcenon::thread::diagnostics::bottleneck_type_to_string(), description, estimated_backlog_time_ms, has_bottleneck, idle_workers, jobs_rejected, queue_depth, queue_saturation, recommendations, severity_string(), total_workers, type, utilization_variance, and worker_utilization.

Here is the call graph for this function:

◆ to_string()

auto kcenon::thread::diagnostics::bottleneck_report::to_string ( ) const -> std::string
inlinenodiscard

Converts the bottleneck report to a human-readable string.

Returns
String representation of the bottleneck report.

Output format:

=== Bottleneck Report ===
Status: DETECTED (medium severity)
Description: Workers cannot keep up with job submission rate
Metrics:
Queue: 100 items (75.0% saturated)
Workers: 7/8 active (1 idle)
Utilization: 92.0% (variance: 0.0500)
Wait time: 150.500ms avg
Backlog: ~5000ms to clear
Recommendations:
- Add more worker threads
- Optimize job execution time
Represents a unit of work (task) to be executed, typically by a job queue.
Definition job.h:136
@ active
Worker is executing a job.
@ idle
Worker is waiting for jobs.
@ up
Scale up (add workers)

Definition at line 333 of file bottleneck_report.h.

334 {
335 std::ostringstream oss;
336
337 oss << "=== Bottleneck Report ===\n";
338 if (has_bottleneck)
339 {
340 oss << "Status: DETECTED (" << severity_string() << " severity)\n";
341 oss << "Type: " << bottleneck_type_to_string(type) << "\n";
342 oss << "Description: " << description << "\n\n";
343 }
344 else
345 {
346 oss << "Status: No bottleneck detected\n\n";
347 }
348
349 // Metrics
350 oss << "Metrics:\n";
351 oss << std::fixed;
352 oss << " Queue: " << queue_depth << " items ("
353 << std::setprecision(1) << (queue_saturation * 100.0) << "% saturated)\n";
354 oss << " Workers: " << (total_workers - idle_workers) << "/" << total_workers
355 << " active (" << idle_workers << " idle)\n";
356 oss << " Utilization: " << std::setprecision(1) << (worker_utilization * 100.0)
357 << "% (variance: " << std::setprecision(4) << utilization_variance << ")\n";
358 oss << " Wait time: " << std::setprecision(3) << avg_wait_time_ms << "ms avg\n";
359 oss << " Backlog: ~" << estimated_backlog_time_ms << "ms to clear\n";
360
361 if (jobs_rejected > 0)
362 {
363 oss << " Jobs rejected: " << jobs_rejected << "\n";
364 }
365
366 // Recommendations
367 if (!recommendations.empty())
368 {
369 oss << "\nRecommendations:\n";
370 for (const auto& rec : recommendations)
371 {
372 oss << " - " << rec << "\n";
373 }
374 }
375
376 return oss.str();
377 }

References avg_wait_time_ms, kcenon::thread::diagnostics::bottleneck_type_to_string(), description, estimated_backlog_time_ms, has_bottleneck, idle_workers, jobs_rejected, queue_depth, queue_saturation, recommendations, severity_string(), total_workers, type, utilization_variance, and worker_utilization.

Here is the call graph for this function:

Member Data Documentation

◆ avg_wait_time_ms

double kcenon::thread::diagnostics::bottleneck_report::avg_wait_time_ms {0.0}

Average wait time in milliseconds.

Average time jobs spend waiting in the queue before execution.

Definition at line 127 of file bottleneck_report.h.

127{0.0};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), to_json(), and to_string().

◆ description

std::string kcenon::thread::diagnostics::bottleneck_report::description

Human-readable description of the bottleneck.

Empty if no bottleneck detected.

Definition at line 103 of file bottleneck_report.h.

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), to_json(), and to_string().

◆ estimated_backlog_time_ms

std::size_t kcenon::thread::diagnostics::bottleneck_report::estimated_backlog_time_ms {0}

Estimated time to process the current backlog.

Based on current processing rate and queue depth.

Definition at line 141 of file bottleneck_report.h.

141{0};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), to_json(), and to_string().

◆ has_bottleneck

bool kcenon::thread::diagnostics::bottleneck_report::has_bottleneck {false}

Whether a bottleneck was detected.

Definition at line 96 of file bottleneck_report.h.

96{false};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), severity(), to_json(), and to_string().

◆ idle_workers

std::size_t kcenon::thread::diagnostics::bottleneck_report::idle_workers {0}

Number of idle workers.

Definition at line 165 of file bottleneck_report.h.

165{0};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), to_json(), and to_string().

◆ jobs_rejected

std::uint64_t kcenon::thread::diagnostics::bottleneck_report::jobs_rejected {0}

Jobs rejected due to queue full.

Count of jobs rejected since last reset.

Definition at line 155 of file bottleneck_report.h.

155{0};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), to_json(), and to_string().

◆ queue_depth

std::size_t kcenon::thread::diagnostics::bottleneck_report::queue_depth {0}

Current queue depth.

Definition at line 160 of file bottleneck_report.h.

160{0};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), to_json(), and to_string().

◆ queue_saturation

double kcenon::thread::diagnostics::bottleneck_report::queue_saturation {0.0}

Queue saturation level.

Current queue depth as a ratio of maximum capacity (0.0 to 1.0+). Values above 1.0 indicate queue overflow attempts.

Definition at line 120 of file bottleneck_report.h.

120{0.0};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), severity(), to_json(), and to_string().

◆ recommendations

std::vector<std::string> kcenon::thread::diagnostics::bottleneck_report::recommendations

Actionable recommendations to resolve the bottleneck.

List of suggestions based on the detected bottleneck type.

Definition at line 181 of file bottleneck_report.h.

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::generate_recommendations(), to_json(), and to_string().

◆ total_workers

std::size_t kcenon::thread::diagnostics::bottleneck_report::total_workers {0}

Total number of workers.

Definition at line 170 of file bottleneck_report.h.

170{0};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), to_json(), and to_string().

◆ type

◆ utilization_variance

double kcenon::thread::diagnostics::bottleneck_report::utilization_variance {0.0}

Variance in worker utilization.

High variance indicates uneven work distribution.

Definition at line 148 of file bottleneck_report.h.

148{0.0};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), to_json(), and to_string().

◆ worker_utilization

double kcenon::thread::diagnostics::bottleneck_report::worker_utilization {0.0}

Average worker utilization.

Average ratio of busy time across all workers (0.0 to 1.0).

Definition at line 134 of file bottleneck_report.h.

134{0.0};

Referenced by kcenon::thread::diagnostics::thread_pool_diagnostics::detect_bottlenecks(), severity(), to_json(), and to_string().


The documentation for this struct was generated from the following file: