github.com/imran-kn/cilium-fork@v1.6.9/pkg/bpf/stats_linux.go (about)

     1  // Copyright 2018 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // +build linux
    16  
    17  package bpf
    18  
    19  import (
    20  	"time"
    21  )
    22  
    23  // DumpStats tracks statistics over the dump of a map.
    24  type DumpStats struct {
    25  	// Started is the timestamp when the gc run was started.
    26  	Started time.Time
    27  
    28  	// Finished is the timestamp when the gc run completed.
    29  	Finished time.Time
    30  
    31  	// Lookup is the number of key lookups performed.
    32  	Lookup uint32
    33  
    34  	// LookupFailed is the number of key lookups that failed.
    35  	LookupFailed uint32
    36  
    37  	// PrevKeyUnavailable is the number of times the previous key was not
    38  	// available.
    39  	PrevKeyUnavailable uint32
    40  
    41  	// KeyFallback is the number of times the current key became invalid
    42  	// while traversing and we had to fall back to the previous key.
    43  	KeyFallback uint32
    44  
    45  	// MaxEntries is the maximum number of entries in the gc table.
    46  	MaxEntries uint32
    47  
    48  	// Interrupted is the number of times the gc run was interrupted and
    49  	// had to start from scratch.
    50  	Interrupted uint32
    51  
    52  	// Completed is true when the gc run has been completed.
    53  	Completed bool
    54  }
    55  
    56  // NewDumpStats returns a new stats structure for collecting dump statistics.
    57  func NewDumpStats(m *Map) *DumpStats {
    58  	return &DumpStats{
    59  		MaxEntries: m.MapInfo.MaxEntries,
    60  	}
    61  }
    62  
    63  // start starts the dump.
    64  func (d *DumpStats) start() {
    65  	d.Started = time.Now()
    66  }
    67  
    68  // finish finishes the dump.
    69  func (d *DumpStats) finish() {
    70  	d.Finished = time.Now()
    71  }
    72  
    73  // Duration returns the duration of the dump.
    74  func (d *DumpStats) Duration() time.Duration {
    75  	return d.Finished.Sub(d.Started)
    76  }