Skip to content

Commit 5f6ecdf

Browse files
committed
Print artifact size analysis in the text form if -v option is passed.
1 parent 0c991f0 commit 5f6ecdf

6 files changed

Lines changed: 21 additions & 10 deletions

File tree

build/analysis/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (n *treeMapNode) Describe() string {
218218
// String representation of the node and its effective children.
219219
func (n *treeMapNode) String() string {
220220
s := &strings.Builder{}
221-
fmt.Fprintf(s, " %s %s\n", strings.Repeat(" *", n.depth), n.Describe())
221+
fmt.Fprintf(s, " %s %s\n", strings.Repeat(" |", n.depth), n.Describe())
222222
for _, c := range n.effectiveChildren {
223223
s.WriteString(c.String())
224224
}

build/analysis/tree_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func TestTreeNodeOrganize(t *testing.T) {
2121
// shorter path to the tree root.
2222
want := "" +
2323
" main — 1.0 MiB own size, 1.1 MiB with children\n" +
24-
" * fmt — 50 KiB own size, 51 KiB with children\n" +
25-
" * * strconv — 1.0 KiB own size, 1.0 KiB with children\n" +
26-
" * io — 10 KiB own size, 10 KiB with children\n"
24+
" | fmt — 50 KiB own size, 51 KiB with children\n" +
25+
" | | strconv — 1.0 KiB own size, 1.0 KiB with children\n" +
26+
" | io — 10 KiB own size, 10 KiB with children\n"
2727
got := main.String()
2828
if diff := cmp.Diff(want, got); diff != "" {
2929
t.Errorf("main.organizeTree() produced unexpected structure (-want,+got):\n%s", diff)

build/analysis/visualize.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
// Visualizer renders a TreeMap diagram representing the generated JS file and
1111
// how different packages contributed it its size.
1212
type Visualizer struct {
13-
File *os.File
14-
Main *compiler.Archive
15-
Deps []*compiler.Archive
13+
File *os.File
14+
Main *compiler.Archive
15+
Deps []*compiler.Archive
16+
PrintStats bool
1617
}
1718

1819
// Render a Tree Map diagram for the given package sizes.
@@ -32,6 +33,10 @@ func (v *Visualizer) Render(stats map[string]int) error {
3233
return err
3334
}
3435
fmt.Fprintf(v.File, "</svg>\n")
36+
37+
if v.PrintStats {
38+
fmt.Println(tree)
39+
}
3540
return nil
3641
}
3742

build/build.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,10 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string)
966966
}
967967
defer f.Close()
968968
visualizer := &analysis.Visualizer{
969-
Main: archive,
970-
Deps: deps,
971-
File: f,
969+
Main: archive,
970+
Deps: deps,
971+
File: f,
972+
PrintStats: s.options.Verbose && !s.options.Quiet,
972973
}
973974
defer func() {
974975
if err := visualizer.Render(sourceMapFilter.BytesWritten); err != nil {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.13
55
require (
66
github.com/dustin/go-humanize v1.0.0
77
github.com/fsnotify/fsnotify v1.4.7
8+
github.com/google/go-cmp v0.5.4
89
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00
910
github.com/kisielk/gotool v1.0.0
1011
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
1515
github.com/go-delve/delve v1.3.2 h1:K8VjV+Q2YnBYlPq0ctjrvc9h7h03wXszlszzfGW5Tog=
1616
github.com/go-delve/delve v1.3.2/go.mod h1:LLw6qJfIsRK9WcwV2IRRqsdlgrqzOeuGrQOCOIhDpt8=
1717
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
18+
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
19+
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1820
github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de h1:F7WD09S8QB4LrkEpka0dFPLSotH11HRpCsLIbIcJ7sU=
1921
github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
2022
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
@@ -121,6 +123,8 @@ golang.org/x/tools v0.0.0-20200131143746-097c1f2eed26/go.mod h1:TB2adYChydJhpapK
121123
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
122124
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
123125
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
126+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
127+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
124128
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
125129
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
126130
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)