MCPcopy
hub / github.com/cilium/cilium / DumpEntriesWithTimeDiff

Function DumpEntriesWithTimeDiff

pkg/maps/nat/nat.go:179–214  ·  view source on GitHub ↗

DumpEntriesWithTimeDiff iterates through Map m and writes the values of the nat entries in m to a string. If clockSource is not nil, it uses it to compute the time difference of each entry from now and prints that too.

(m NatMap, clockSource *models.ClockSource)

Source from the content-addressed store, hash-verified

177// nat entries in m to a string. If clockSource is not nil, it uses it to
178// compute the time difference of each entry from now and prints that too.
179func DumpEntriesWithTimeDiff(m NatMap, clockSource *models.ClockSource) (string, error) {
180 var toDeltaSecs func(uint64) string
181 var sb strings.Builder
182
183 if clockSource == nil {
184 toDeltaSecs = func(t uint64) string {
185 return fmt.Sprintf("? (raw %d)", t)
186 }
187 } else {
188 now, err := timestamp.GetCTCurTime(clockSource)
189 if err != nil {
190 return "", err
191 }
192 tsConverter, err := timestamp.NewCTTimeToSecConverter(clockSource)
193 if err != nil {
194 return "", err
195 }
196 tsecNow := tsConverter(now)
197 toDeltaSecs = func(t uint64) string {
198 tsec := tsConverter(uint64(t))
199 diff := int64(tsecNow) - int64(tsec)
200 return fmt.Sprintf("%dsec ago", diff)
201 }
202 }
203
204 cb := func(k bpf.MapKey, v bpf.MapValue) {
205 key := k.(NatKey)
206 if !key.ToHost().Dump(&sb, false) {
207 return
208 }
209 val := v.(NatEntry)
210 sb.WriteString(val.ToHost().Dump(key, toDeltaSecs))
211 }
212 err := m.DumpWithCallback(cb)
213 return sb.String(), err
214}
215
216// DoDumpEntries iterates through Map m and writes the values of the
217// nat entries in m to a string.

Callers 2

dumpNatFunction · 0.92
DoDumpEntriesFunction · 0.70

Calls 7

GetCTCurTimeFunction · 0.92
NewCTTimeToSecConverterFunction · 0.92
DumpMethod · 0.65
ToHostMethod · 0.65
DumpWithCallbackMethod · 0.65
StringMethod · 0.65
WriteStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…