From 2e4e77df9186f234bf37cfaa1b0f2731bff41e97 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 5 Nov 2024 20:41:15 +0100 Subject: [PATCH] dev: extends usage of new Stopwatch methods --- pkg/goanalysis/runner_action.go | 5 ++--- pkg/lint/runner.go | 28 ++++++++++++---------------- pkg/result/processors/fixer.go | 5 ++--- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/pkg/goanalysis/runner_action.go b/pkg/goanalysis/runner_action.go index 81e2556b39f9..0ef8c094c772 100644 --- a/pkg/goanalysis/runner_action.go +++ b/pkg/goanalysis/runner_action.go @@ -109,9 +109,8 @@ func (act *action) analyzeSafe() { act.a.Name, act.pkg.Name, act.isInitialPkg, act.needAnalyzeSource, p), debug.Stack()) } }() - act.r.sw.TrackStage(act.a.Name, func() { - act.analyze() - }) + + act.r.sw.TrackStage(act.a.Name, act.analyze) } func (act *action) analyze() { diff --git a/pkg/lint/runner.go b/pkg/lint/runner.go index c3b983ff6a4a..2c47c7166e6a 100644 --- a/pkg/lint/runner.go +++ b/pkg/lint/runner.go @@ -115,17 +115,17 @@ func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]result.Is ) for _, lc := range linters { - sw.TrackStage(lc.Name(), func() { - linterIssues, err := r.runLinterSafe(ctx, r.lintCtx, lc) - if err != nil { - lintErrors = errors.Join(lintErrors, fmt.Errorf("can't run linter %s", lc.Linter.Name()), err) - r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err) + linterIssues, err := timeutils.TrackStage(sw, lc.Name(), func() ([]result.Issue, error) { + return r.runLinterSafe(ctx, r.lintCtx, lc) + }) + if err != nil { + lintErrors = errors.Join(lintErrors, fmt.Errorf("can't run linter %s", lc.Linter.Name()), err) + r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err) - return - } + continue + } - issues = append(issues, linterIssues...) - }) + issues = append(issues, linterIssues...) } return r.processLintResults(issues), lintErrors @@ -188,9 +188,7 @@ func (r *Runner) processLintResults(inIssues []result.Issue) []result.Issue { // finalize processors: logging, clearing, no heavy work here for _, p := range r.Processors { - sw.TrackStage(p.Name(), func() { - p.Finish() - }) + sw.TrackStage(p.Name(), p.Finish) } if issuesBefore != issuesAfter { @@ -216,10 +214,8 @@ func (r *Runner) printPerProcessorStat(stat map[string]processorStat) { func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []result.Issue { for _, p := range r.Processors { - var newIssues []result.Issue - var err error - sw.TrackStage(p.Name(), func() { - newIssues, err = p.Process(issues) + newIssues, err := timeutils.TrackStage(sw, p.Name(), func() ([]result.Issue, error) { + return p.Process(issues) }) if err != nil { diff --git a/pkg/result/processors/fixer.go b/pkg/result/processors/fixer.go index cc99e6940ef8..764af5a9231e 100644 --- a/pkg/result/processors/fixer.go +++ b/pkg/result/processors/fixer.go @@ -56,9 +56,8 @@ func (p Fixer) Process(issues []result.Issue) ([]result.Issue, error) { } for file, issuesToFix := range issuesToFixPerFile { - var err error - p.sw.TrackStage("all", func() { - err = p.fixIssuesInFile(file, issuesToFix) + err := p.sw.TrackStageErr("all", func() error { + return p.fixIssuesInFile(file, issuesToFix) }) if err != nil { p.log.Errorf("Failed to fix issues in file %s: %s", file, err)