GetPoolStats returns a snapshot of all named pool counters. The map is keyed by pool name. Standard pool names ("tokenizer", "parser", "ast") are always present with zero values even if no operations have been recorded. This function is safe for concurrent use.
()
| 85 | // are always present with zero values even if no operations have been recorded. |
| 86 | // This function is safe for concurrent use. |
| 87 | func GetPoolStats() map[string]PoolStat { |
| 88 | // Ensure standard pools are always present |
| 89 | for _, name := range standardPoolNames { |
| 90 | getOrCreatePoolCounter(name) |
| 91 | } |
| 92 | |
| 93 | poolStatsMu.RLock() |
| 94 | defer poolStatsMu.RUnlock() |
| 95 | result := make(map[string]PoolStat, len(poolCounters)) |
| 96 | for name, c := range poolCounters { |
| 97 | result[name] = PoolStat{ |
| 98 | Gets: atomic.LoadInt64(&c.gets), |
| 99 | Puts: atomic.LoadInt64(&c.puts), |
| 100 | } |
| 101 | } |
| 102 | return result |
| 103 | } |
| 104 | |
| 105 | // ResetPoolStats zeroes all named pool counters. Primarily intended for testing. |
| 106 | // This is safe for concurrent use. |