mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
Make fine-grained hashing. (#814)
Speed up golint: don't typecheck packages twice. Relates: #805
This commit is contained in:
parent
f13436112d
commit
48599c64ba
11 changed files with 138 additions and 68 deletions
|
@ -10,6 +10,8 @@ import (
|
|||
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||
)
|
||||
|
||||
const noStagesText = "no stages"
|
||||
|
||||
type Stopwatch struct {
|
||||
name string
|
||||
startedAt time.Time
|
||||
|
@ -33,11 +35,7 @@ type stageDuration struct {
|
|||
d time.Duration
|
||||
}
|
||||
|
||||
func (s *Stopwatch) sprintStages() string {
|
||||
if len(s.stages) == 0 {
|
||||
return "no stages"
|
||||
}
|
||||
|
||||
func (s *Stopwatch) stageDurationsSorted() []stageDuration {
|
||||
stageDurations := []stageDuration{}
|
||||
for n, d := range s.stages {
|
||||
stageDurations = append(stageDurations, stageDuration{
|
||||
|
@ -48,6 +46,16 @@ func (s *Stopwatch) sprintStages() string {
|
|||
sort.Slice(stageDurations, func(i, j int) bool {
|
||||
return stageDurations[i].d > stageDurations[j].d
|
||||
})
|
||||
return stageDurations
|
||||
}
|
||||
|
||||
func (s *Stopwatch) sprintStages() string {
|
||||
if len(s.stages) == 0 {
|
||||
return noStagesText
|
||||
}
|
||||
|
||||
stageDurations := s.stageDurationsSorted()
|
||||
|
||||
stagesStrings := []string{}
|
||||
for _, s := range stageDurations {
|
||||
stagesStrings = append(stagesStrings, fmt.Sprintf("%s: %s", s.name, s.d))
|
||||
|
@ -56,6 +64,22 @@ func (s *Stopwatch) sprintStages() string {
|
|||
return fmt.Sprintf("stages: %s", strings.Join(stagesStrings, ", "))
|
||||
}
|
||||
|
||||
func (s *Stopwatch) sprintTopStages(n int) string {
|
||||
if len(s.stages) == 0 {
|
||||
return noStagesText
|
||||
}
|
||||
|
||||
stageDurations := s.stageDurationsSorted()
|
||||
|
||||
stagesStrings := []string{}
|
||||
for i := 0; i < len(stageDurations) && i < n; i++ {
|
||||
s := stageDurations[i]
|
||||
stagesStrings = append(stagesStrings, fmt.Sprintf("%s: %s", s.name, s.d))
|
||||
}
|
||||
|
||||
return fmt.Sprintf("top %d stages: %s", n, strings.Join(stagesStrings, ", "))
|
||||
}
|
||||
|
||||
func (s *Stopwatch) Print() {
|
||||
p := fmt.Sprintf("%s took %s", s.name, time.Since(s.startedAt))
|
||||
if len(s.stages) == 0 {
|
||||
|
@ -74,6 +98,14 @@ func (s *Stopwatch) PrintStages() {
|
|||
s.log.Infof("%s took %s with %s", s.name, stagesDuration, s.sprintStages())
|
||||
}
|
||||
|
||||
func (s *Stopwatch) PrintTopStages(n int) {
|
||||
var stagesDuration time.Duration
|
||||
for _, s := range s.stages {
|
||||
stagesDuration += s
|
||||
}
|
||||
s.log.Infof("%s took %s with %s", s.name, stagesDuration, s.sprintTopStages(n))
|
||||
}
|
||||
|
||||
func (s *Stopwatch) TrackStage(name string, f func()) {
|
||||
startedAt := time.Now()
|
||||
f()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue