1
1
mirror of https://github.com/walles/moar.git synced 2024-08-16 15:30:34 +03:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Johan Walles
eae1915b5e Fix formatting 2024-05-18 15:34:17 +02:00
Johan Walles
11095496b2 Tune logging 2024-05-18 15:23:37 +02:00
Johan Walles
d1fac66a23 Improve search logging 2024-05-18 15:15:45 +02:00

View File

@ -3,6 +3,7 @@ package m
import (
"fmt"
"runtime"
"time"
log "github.com/sirupsen/logrus"
@ -22,7 +23,7 @@ func (p *Pager) scrollToSearchHits() {
}
firstHitPosition := p.findFirstHit(*lineNumber, nil, false)
if firstHitPosition == nil {
if firstHitPosition == nil && (*lineNumber != linenumbers.LineNumber{}) {
// Try again from the top
firstHitPosition = p.findFirstHit(linenumbers.LineNumber{}, lineNumber, false)
}
@ -75,7 +76,27 @@ func (p *Pager) findFirstHit(startPosition linenumbers.LineNumber, beforePositio
}
chunkSize := linesCount / chunkCount
log.Debugf("Searching %d lines across %d cores with %d lines per core", linesCount, chunkCount, chunkSize)
log.Debugf("Searching %d lines across %d cores with %d lines per core...", linesCount, chunkCount, chunkSize)
t0 := time.Now()
defer func() {
linesPerSecond := float64(linesCount) / time.Since(t0).Seconds()
linesPerSecondS := fmt.Sprintf("%.0f", linesPerSecond)
if linesPerSecond > 7_000_000.0 {
linesPerSecondS = fmt.Sprintf("%.0fM", linesPerSecond/1000_000.0)
} else if linesPerSecond > 7_000.0 {
linesPerSecondS = fmt.Sprintf("%.0fk", linesPerSecond/1000.0)
}
if linesCount > 0 {
log.Debugf("Searched %d lines in %s at %slines/s or %s/line",
linesCount,
time.Since(t0),
linesPerSecondS,
time.Since(t0)/time.Duration(linesCount))
} else {
log.Debugf("Searched %d lines in %s at %slines/s", linesCount, time.Since(t0), linesPerSecondS)
}
}()
// Each parallel search will start at one of these positions
searchStarts := make([]linenumbers.LineNumber, chunkCount)