mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-05 04:11:59 +00:00
sockstats: switch label to enum
Makes it cheaper/simpler to persist values, and encourages reuse of labels as opposed to generating an arbitrary number. Updates tailscale/corp#9230 Updates #3363 Signed-off-by: Mihai Parparita <mihai@tailscale.com>
This commit is contained in:
committed by
Mihai Parparita
parent
9687f3700d
commit
6ac6ddbb47
@@ -24,7 +24,7 @@ var sockStats = struct {
|
||||
// mu protects fields in this group. It should not be held in the per-read/
|
||||
// write callbacks.
|
||||
mu sync.Mutex
|
||||
countersByLabel map[string]*sockStatCounters
|
||||
countersByLabel map[Label]*sockStatCounters
|
||||
knownInterfaces map[int]string // interface index -> name
|
||||
usedInterfaces map[int]int // set of interface indexes
|
||||
|
||||
@@ -32,12 +32,12 @@ var sockStats = struct {
|
||||
// write callbacks.
|
||||
currentInterface atomic.Uint32
|
||||
}{
|
||||
countersByLabel: make(map[string]*sockStatCounters),
|
||||
countersByLabel: make(map[Label]*sockStatCounters),
|
||||
knownInterfaces: make(map[int]string),
|
||||
usedInterfaces: make(map[int]int),
|
||||
}
|
||||
|
||||
func withSockStats(ctx context.Context, label string) context.Context {
|
||||
func withSockStats(ctx context.Context, label Label) context.Context {
|
||||
sockStats.mu.Lock()
|
||||
defer sockStats.mu.Unlock()
|
||||
counters, ok := sockStats.countersByLabel[label]
|
||||
@@ -85,7 +85,7 @@ func get() *SockStats {
|
||||
defer sockStats.mu.Unlock()
|
||||
|
||||
r := &SockStats{
|
||||
Stats: make(map[string]SockStat),
|
||||
Stats: make(map[Label]SockStat),
|
||||
Interfaces: make([]string, 0, len(sockStats.usedInterfaces)),
|
||||
}
|
||||
for iface := range sockStats.usedInterfaces {
|
||||
|
||||
Reference in New Issue
Block a user