-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregator.go
73 lines (60 loc) · 1.53 KB
/
aggregator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package stamets
import (
"bytes"
"io"
"io/fs"
"os"
"path/filepath"
"sync"
)
// AggregatePTAResults recursively walks a directory, reads every file,
// and then unparses and aggregates all potential PTA metrics in the contents.
func AggregatePTAResults(dir string) []PTAMetrics {
results := make([]PTAMetrics, 0)
wg, c := &sync.WaitGroup{}, make(chan struct{}, 10)
dir, _ = filepath.Abs(dir)
filepath.WalkDir(dir, func(p string, d fs.DirEntry, err error) error {
if d == nil || d.IsDir() {
return nil
}
bs, err := os.ReadFile(p)
if err != nil && err != io.EOF {
return nil
}
wg.Add(1)
go func() {
defer wg.Done()
defer func() { <-c }()
c <- struct{}{}
results = append(results, UnparsePTAResultsFromReader(bytes.NewReader(bs))...)
}()
return nil
})
wg.Wait()
return results
}
// AggregateCallGraphResults recursively walks a directory, reads every file,
// and then unparses and aggregates all potential call graph metrics in the contents.
func AggregateCallGraphResults(dir string) []CallGraphMetrics {
results := make([]CallGraphMetrics, 0)
wg, c := &sync.WaitGroup{}, make(chan struct{}, 10)
filepath.WalkDir(dir, func(p string, d fs.DirEntry, err error) error {
if d == nil || d.IsDir() {
return nil
}
bs, err := os.ReadFile(p)
if err != nil {
return nil
}
wg.Add(1)
go func() {
defer wg.Done()
defer func() { <-c }()
c <- struct{}{}
results = append(results, UnparseCallGraphMetricsFromReader(bytes.NewReader(bs))...)
}()
return nil
})
wg.Wait()
return results
}