Skip to content

Commit 484f9ce

Browse files
committed
chore: add log
1 parent 5298bab commit 484f9ce

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

lang/golang/parser/parser.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"path/filepath"
3030
"regexp"
3131
"strings"
32+
"time"
3233

3334
"github.com/cloudwego/abcoder/lang/log"
3435
. "github.com/cloudwego/abcoder/lang/uniast"
@@ -284,6 +285,10 @@ func getDeps(dir string, workDirs map[string]bool) (a map[string]string, cgoPkgs
284285

285286
// ParseRepo parse the entiry repo from homePageDir recursively until end
286287
func (p *GoParser) ParseRepo() (Repository, error) {
288+
start := time.Now()
289+
defer func() {
290+
fmt.Fprintf(os.Stderr, "ParseRepo took %v\n", time.Since(start))
291+
}()
287292
for _, lib := range p.modules {
288293
if strings.Contains(lib.path, "@") {
289294
continue
@@ -300,6 +305,10 @@ func (p *GoParser) ParseRepo() (Repository, error) {
300305
}
301306

302307
func (p *GoParser) ParseModule(mod *Module, dir string) (err error) {
308+
start := time.Now()
309+
defer func() {
310+
fmt.Fprintf(os.Stderr, "ParseModule %s took %v\n", mod.Name, time.Since(start))
311+
}()
303312
// run go mod tidy before parse
304313
cmd := exec.Command("go", "mod", "tidy")
305314
cmd.Dir = dir
@@ -333,6 +342,7 @@ func (p *GoParser) ParseModule(mod *Module, dir string) (err error) {
333342

334343
if p.opts.LoadByPackages {
335344
var errs []error
345+
startWalk := time.Now()
336346
filepath.Walk(dir, func(path string, info fs.FileInfo, e error) error {
337347
if e != nil || !info.IsDir() || shouldIgnoreDir(path) {
338348
return nil
@@ -347,6 +357,7 @@ func (p *GoParser) ParseModule(mod *Module, dir string) (err error) {
347357
}
348358
return nil
349359
})
360+
fmt.Fprintf(os.Stderr, "ParseModule Walk %s took %v\n", mod.Name, time.Since(startWalk))
350361
if len(errs) > 0 {
351362
return fmt.Errorf("parse package failed: %v", errs)
352363
}

lang/golang/parser/pkg.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sort"
2525
"strconv"
2626
"strings"
27+
"time"
2728

2829
. "github.com/cloudwego/abcoder/lang/uniast"
2930
"golang.org/x/tools/go/packages"
@@ -166,6 +167,10 @@ func (p *GoParser) parsePackage(pkgPath PkgPath) (err error) {
166167
var loadCount = 0
167168

168169
func (p *GoParser) loadPackages(mod *Module, dir string, pkgPath PkgPath) (err error) {
170+
start := time.Now()
171+
defer func() {
172+
fmt.Fprintf(os.Stderr, "loadPackages %s took %v\n", pkgPath, time.Since(start))
173+
}()
169174
if mm := p.repo.Modules[mod.Name]; mm != nil && (*mm).Packages[pkgPath] != nil {
170175
return nil
171176
}
@@ -191,7 +196,9 @@ func (p *GoParser) loadPackages(mod *Module, dir string, pkgPath PkgPath) (err e
191196
cfg.Tests = true
192197
}
193198

199+
loadStart := time.Now()
194200
pkgs, err := packages.Load(cfg, pkgPath)
201+
fmt.Fprintf(os.Stderr, "packages.Load %s took %v\n", pkgPath, time.Since(loadStart))
195202
if err != nil {
196203
return fmt.Errorf("load path '%s' failed: %v", dir, err)
197204
}
@@ -204,7 +211,9 @@ func (p *GoParser) loadPackages(mod *Module, dir string, pkgPath PkgPath) (err e
204211
if hasCGO {
205212
baseOpts |= packages.NeedCompiledGoFiles
206213
cfg.Mode = baseOpts
214+
loadCgoStart := time.Now()
207215
pkgs, err = packages.Load(cfg, pkgPath)
216+
fmt.Fprintf(os.Stderr, "packages.Load(CGO) %s took %v\n", pkgPath, time.Since(loadCgoStart))
208217
if err != nil {
209218
return fmt.Errorf("load path '%s' with CGO failed: %v", dir, err)
210219
}

0 commit comments

Comments
 (0)