|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
📊 Server performance monitoring: resource utilization tracking, client metrics, and health reporting More...
Go to the source code of this file.
Functions | |
| int | stats_init (void) |
| Initialize the stats mutex. | |
| void | stats_cleanup (void) |
| Cleanup the stats mutex. | |
| void * | stats_logger_thread (void *arg) |
| Main statistics collection and reporting thread function. | |
| void | update_server_stats (void) |
| Update global server statistics (placeholder) | |
| void | log_server_stats (void) |
| Log comprehensive server statistics summary. | |
Variables | |
| server_stats_t | g_stats = {0} |
| Global server statistics structure. | |
| mutex_t | g_stats_mutex = {0} |
| Mutex protecting global server statistics. | |
| atomic_bool | g_server_should_exit |
| Global shutdown flag from main.c - coordinate statistics thread termination. | |
📊 Server performance monitoring: resource utilization tracking, client metrics, and health reporting
STATISTICS COLLECTION THREAD:
PERFORMANCE IMPACT MINIMIZATION:
CLIENT MANAGEMENT METRICS:
BUFFER POOL PERFORMANCE:
PACKET QUEUE STATISTICS:
HASH TABLE EFFICIENCY:
FRAME PROCESSING METRICS:
NON-INTRUSIVE MONITORING:
STATISTICS ATOMICITY:
LIFECYCLE MANAGEMENT:
DEBUGGING SUPPORT:
METRIC ADDITION:
INTEGRATION POINTS:
The original server.c had no centralized monitoring, making it impossible to:
This separation provides:
Definition in file stats.c.
| void log_server_stats | ( | void | ) |
Log comprehensive server statistics summary.
Outputs a formatted summary of server performance statistics including frame processing rates, throughput metrics, and system health indicators. This function provides operational visibility into server performance.
FRAME PROCESSING METRICS:
PERFORMANCE INDICATORS:
Definition at line 559 of file stats.c.
References server_stats_t::avg_capture_fps, server_stats_t::avg_send_fps, server_stats_t::frames_captured, server_stats_t::frames_dropped, server_stats_t::frames_sent, g_stats, g_stats_mutex, log_info, mutex_lock, and mutex_unlock.
Referenced by stats_logger_thread().
| void stats_cleanup | ( | void | ) |
Cleanup the stats mutex.
Definition at line 195 of file stats.c.
References g_stats_mutex, and mutex_destroy().
Referenced by server_main().
| int stats_init | ( | void | ) |
Initialize the stats mutex.
Definition at line 184 of file stats.c.
References g_stats_mutex, and mutex_init().
Referenced by server_main().
| void * stats_logger_thread | ( | void * | arg | ) |
Main statistics collection and reporting thread function.
This background thread performs continuous monitoring of server performance and logs comprehensive statistics reports at regular intervals. It operates independently of the main server processing threads to avoid performance impact.
NON-BLOCKING DATA COLLECTION:
RESPONSIVE SHUTDOWN:
CLIENT STATISTICS:
BUFFER POOL METRICS:
PACKET QUEUE PERFORMANCE:
HASH TABLE EFFICIENCY:
EXTENSIVE DEBUG LOGGING: The function contains detailed debug printf statements for troubleshooting threading issues. This instrumentation helps diagnose:
DEBUG OUTPUT INCLUDES:
| arg | Thread argument (unused - required by thread interface) |
Definition at line 332 of file stats.c.
References client_info::active, asciichat_errno_cleanup(), asciichat_error_stats_print(), client_info::audio_queue, client_info::client_id, client_manager_t::clients, video_frame_stats_t::drop_rate, video_frame_stats_t::dropped_frames, g_client_manager, g_client_manager_rwlock, g_server_should_exit, lock_debug_is_initialized(), log_info, log_server_stats(), MAX_CLIENTS, client_info::outgoing_video_buffer, packet_queue_get_stats(), platform_sleep_usec(), rwlock_rdlock, rwlock_rdunlock, safe_snprintf(), video_frame_stats_t::total_frames, and video_frame_get_stats().
Referenced by server_main().
| void update_server_stats | ( | void | ) |
Update global server statistics (placeholder)
This function is intended to update the global server statistics structure with current performance metrics. Currently unimplemented but provides the framework for centralized statistics updates.
IMPLEMENTATION STRATEGY:
INTEGRATION POINTS:
Used by packet queue systems for throughput tracking
Definition at line 478 of file stats.c.
References client_info::active, client_info::client_id, client_manager_t::clients, video_frame_stats_t::dropped_frames, server_stats_t::frames_captured, server_stats_t::frames_dropped, client_info::frames_sent, server_stats_t::frames_sent, g_client_manager, g_client_manager_rwlock, g_stats, g_stats_mutex, MAX_CLIENTS, mutex_lock, mutex_unlock, client_info::outgoing_video_buffer, rwlock_rdlock, rwlock_rdunlock, and video_frame_get_stats().
|
extern |
Global shutdown flag from main.c - coordinate statistics thread termination.
The statistics thread monitors this flag to detect server shutdown and exit its monitoring loop gracefully, ensuring clean resource cleanup.
Global shutdown flag from main.c - coordinate statistics thread termination.
Global shutdown flag from main.c - coordinate graceful thread termination.
Global shutdown flag from main.c - used to avoid error spam during shutdown.
Global shutdown flag from main.c.
This flag is the primary coordination mechanism for clean server shutdown. It's atomic to ensure thread-safe access without mutexes, as it's checked frequently in tight loops across all worker threads.
USAGE PATTERN:
Definition at line 135 of file server/main.c.
Referenced by stats_logger_thread().
| server_stats_t g_stats = {0} |
Global server statistics structure.
Maintains aggregated performance metrics for the entire server including frame processing rates, client counts, and system health indicators. All access to this structure must be protected by g_stats_mutex.
CONTENTS:
Definition at line 159 of file stats.c.
Referenced by log_server_stats(), server_main(), and update_server_stats().
| mutex_t g_stats_mutex = {0} |
Mutex protecting global server statistics.
Ensures thread-safe access to g_stats structure from both the statistics collection thread and any operational threads that update counters. Uses standard mutex (not reader-writer) due to relatively infrequent access.
Definition at line 168 of file stats.c.
Referenced by log_server_stats(), server_main(), stats_cleanup(), stats_init(), and update_server_stats().