Skip to content

Commit 3e1354c

Browse files
authored
dev: extends usage of new Stopwatch methods (#5102)
1 parent e28ddc1 commit 3e1354c

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

pkg/goanalysis/runner_action.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ func (act *action) analyzeSafe() {
109109
act.a.Name, act.pkg.Name, act.isInitialPkg, act.needAnalyzeSource, p), debug.Stack())
110110
}
111111
}()
112-
act.r.sw.TrackStage(act.a.Name, func() {
113-
act.analyze()
114-
})
112+
113+
act.r.sw.TrackStage(act.a.Name, act.analyze)
115114
}
116115

117116
func (act *action) analyze() {

pkg/lint/runner.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]result.Is
115115
)
116116

117117
for _, lc := range linters {
118-
sw.TrackStage(lc.Name(), func() {
119-
linterIssues, err := r.runLinterSafe(ctx, r.lintCtx, lc)
120-
if err != nil {
121-
lintErrors = errors.Join(lintErrors, fmt.Errorf("can't run linter %s", lc.Linter.Name()), err)
122-
r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err)
118+
linterIssues, err := timeutils.TrackStage(sw, lc.Name(), func() ([]result.Issue, error) {
119+
return r.runLinterSafe(ctx, r.lintCtx, lc)
120+
})
121+
if err != nil {
122+
lintErrors = errors.Join(lintErrors, fmt.Errorf("can't run linter %s", lc.Linter.Name()), err)
123+
r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err)
123124

124-
return
125-
}
125+
continue
126+
}
126127

127-
issues = append(issues, linterIssues...)
128-
})
128+
issues = append(issues, linterIssues...)
129129
}
130130

131131
return r.processLintResults(issues), lintErrors
@@ -188,9 +188,7 @@ func (r *Runner) processLintResults(inIssues []result.Issue) []result.Issue {
188188
// finalize processors: logging, clearing, no heavy work here
189189

190190
for _, p := range r.Processors {
191-
sw.TrackStage(p.Name(), func() {
192-
p.Finish()
193-
})
191+
sw.TrackStage(p.Name(), p.Finish)
194192
}
195193

196194
if issuesBefore != issuesAfter {
@@ -216,10 +214,8 @@ func (r *Runner) printPerProcessorStat(stat map[string]processorStat) {
216214

217215
func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []result.Issue {
218216
for _, p := range r.Processors {
219-
var newIssues []result.Issue
220-
var err error
221-
sw.TrackStage(p.Name(), func() {
222-
newIssues, err = p.Process(issues)
217+
newIssues, err := timeutils.TrackStage(sw, p.Name(), func() ([]result.Issue, error) {
218+
return p.Process(issues)
223219
})
224220

225221
if err != nil {

pkg/result/processors/fixer.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ func (p Fixer) Process(issues []result.Issue) ([]result.Issue, error) {
5656
}
5757

5858
for file, issuesToFix := range issuesToFixPerFile {
59-
var err error
60-
p.sw.TrackStage("all", func() {
61-
err = p.fixIssuesInFile(file, issuesToFix)
59+
err := p.sw.TrackStageErr("all", func() error {
60+
return p.fixIssuesInFile(file, issuesToFix)
6261
})
6362
if err != nil {
6463
p.log.Errorf("Failed to fix issues in file %s: %s", file, err)

0 commit comments

Comments
 (0)