github.com/cilium/cilium@v1.16.2/pkg/bpf/stats_linux.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  //go:build linux
     5  
     6  package bpf
     7  
     8  import (
     9  	"github.com/cilium/cilium/pkg/time"
    10  )
    11  
    12  // DumpStats tracks statistics over the dump of a map.
    13  type DumpStats struct {
    14  	// Started is the timestamp when the gc run was started.
    15  	Started time.Time
    16  
    17  	// Finished is the timestamp when the gc run completed.
    18  	Finished time.Time
    19  
    20  	// Lookup is the number of key lookups performed.
    21  	Lookup uint32
    22  
    23  	// LookupFailed is the number of key lookups that failed.
    24  	LookupFailed uint32
    25  
    26  	// PrevKeyUnavailable is the number of times the previous key was not
    27  	// available.
    28  	PrevKeyUnavailable uint32
    29  
    30  	// KeyFallback is the number of times the current key became invalid
    31  	// while traversing and we had to fall back to the previous key.
    32  	KeyFallback uint32
    33  
    34  	// MaxEntries is the maximum number of entries in the gc table.
    35  	MaxEntries uint32
    36  
    37  	// Interrupted is the number of times the gc run was interrupted and
    38  	// had to start from scratch.
    39  	Interrupted uint32
    40  
    41  	// Completed is true when the gc run has been completed.
    42  	Completed bool
    43  }
    44  
    45  // NewDumpStats returns a new stats structure for collecting dump statistics.
    46  func NewDumpStats(m *Map) *DumpStats {
    47  	return &DumpStats{
    48  		MaxEntries: m.MaxEntries(),
    49  	}
    50  }
    51  
    52  // start starts the dump.
    53  func (d *DumpStats) start() {
    54  	d.Started = time.Now()
    55  }
    56  
    57  // finish finishes the dump.
    58  func (d *DumpStats) finish() {
    59  	d.Finished = time.Now()
    60  }
    61  
    62  // Duration returns the duration of the dump.
    63  func (d *DumpStats) Duration() time.Duration {
    64  	return d.Finished.Sub(d.Started)
    65  }