mirror of
https://github.com/soypat/lneto.git
synced 2026-09-10 16:49:37 +00:00
Reduce heap allocs 2 (#46)
* reduce heap allocations in tcp logging; omit use of AppendFloat which allocates a metric sh*tton * debugheaplog: better heap statistic logging * heap: use string for pcap.Frame.Protocol * add potential to eliminate Flags.String heap alloc, remove incorrect HEAP comments * add StackAsync.DebugErr and httpraw.SetBytes * many heap alloc reductions and replacement of bytes.Equal with internal.BytesEqual
This commit is contained in:
+27
-1
@@ -62,7 +62,33 @@ func (stack *CapturePrinter) PrintPacket(prefix string, pkt []byte) {
|
||||
if err == nil {
|
||||
if useTimestamps {
|
||||
diff := captime.Sub(stack.origin)
|
||||
fmtbuf = strconv.AppendFloat(fmtbuf, diff.Seconds(), 'f', stack.timeprec, 32)
|
||||
ms := diff.Milliseconds()
|
||||
fmtbuf = strconv.AppendInt(fmtbuf, ms/1000, 10)
|
||||
fmtbuf = append(fmtbuf, '.')
|
||||
frac := ms % 1000
|
||||
if frac < 0 {
|
||||
frac = -frac
|
||||
}
|
||||
// Pad fractional part to timeprec digits (up to 3).
|
||||
switch {
|
||||
case stack.timeprec >= 3:
|
||||
if frac < 100 {
|
||||
fmtbuf = append(fmtbuf, '0')
|
||||
}
|
||||
if frac < 10 {
|
||||
fmtbuf = append(fmtbuf, '0')
|
||||
}
|
||||
fmtbuf = strconv.AppendInt(fmtbuf, frac, 10)
|
||||
case stack.timeprec == 2:
|
||||
frac /= 10 // truncate to centiseconds
|
||||
if frac < 10 {
|
||||
fmtbuf = append(fmtbuf, '0')
|
||||
}
|
||||
fmtbuf = strconv.AppendInt(fmtbuf, frac, 10)
|
||||
case stack.timeprec == 1:
|
||||
frac /= 100 // truncate to deciseconds
|
||||
fmtbuf = strconv.AppendInt(fmtbuf, frac, 10)
|
||||
}
|
||||
fmtbuf = append(fmtbuf, ' ')
|
||||
}
|
||||
fmtbuf = append(fmtbuf, prefix...)
|
||||
|
||||
Reference in New Issue
Block a user