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)
| 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. |
| 179 | func 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. |
no test coverage detected
searching dependent graphs…