Skip to content

Commit d8323e0

Browse files
- Increased the system metrics update interval from 10 seconds to 60 seconds for improved performance tracking.
- Added detailed comments to clarify the behavior of CPU utilization sampling and the prevention of double-recording in coordination window metrics.
1 parent 00c1554 commit d8323e0

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

pkg/clientinfo/performance.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"sync"
99
"time"
1010

11+
// gopsutil provides cross-platform system and process utilities.
12+
// It supports linux/amd64 and darwin/amd64 (the target platforms for this codebase),
13+
// as well as Windows, FreeBSD, OpenBSD, and Solaris.
1114
"github.com/shirou/gopsutil/cpu"
1215
"github.com/shirou/gopsutil/mem"
1316
)
@@ -424,7 +427,7 @@ func (pm *PerformanceMetrics) SetGauge(name string, value float64) {
424427
// observeSystemMetrics periodically collects and updates system metrics
425428
// including CPU utilization, memory usage, and goroutine count.
426429
func (pm *PerformanceMetrics) observeSystemMetrics(ctx context.Context) {
427-
ticker := time.NewTicker(10 * time.Second) // Update every 10 seconds
430+
ticker := time.NewTicker(60 * time.Second) // Update every 10 seconds
428431
defer ticker.Stop()
429432

430433
var lastMemStats runtime.MemStats
@@ -520,6 +523,10 @@ func (pm *PerformanceMetrics) calculateCPUUtilizationHeuristic(
520523
// including CPU load, RAM utilization, and swapfile utilization.
521524
func (pm *PerformanceMetrics) updateMachineStats() {
522525
// Get CPU load percentage (1-second average)
526+
// NOTE: cpu.Percent blocks for the specified duration (1 second) to sample
527+
// CPU usage over that interval. This blocking behavior is intentional and
528+
// necessary to obtain an accurate CPU utilization measurement. The function
529+
// will not return until the 1-second sampling period completes.
523530
cpuPercent, err := cpu.Percent(time.Second, false)
524531
if err == nil && len(cpuPercent) > 0 {
525532
pm.SetGauge(MetricCPULoadPercent, cpuPercent[0])

pkg/tbtc/coordination_window_metrics.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ func (cwm *coordinationWindowMetrics) recordWindowEnd(window *coordinationWindow
158158
return
159159
}
160160

161-
// Don't overwrite EndTime if it's already been set
161+
// This guard prevents double-recording when recordWindowEnd is called
162+
// both during normal operation (when a new window is detected) and during
163+
// shutdown cleanup (to ensure the last active window is properly closed).
164+
// Without this check, the shutdown cleanup goroutine could overwrite the
165+
// EndTime that was already set by the normal window transition flow.
162166
if !wm.EndTime.IsZero() {
163167
return
164168
}

0 commit comments

Comments
 (0)