Browse Source

*: golint, go tool vet, unsued, gosimple, staticcheck (#113)

* `git ls-files -- '*.go' | xargs gofmt -s -w`

* driver: unexport InternalOptions

This was an exported method that returned an internal type, so it's
unlikely that anyone depends on its presence.

* internal/binutils: remove newline in error string

golint reported: error strings should not be capitalized or end with
punctuation or a newline

* internal/driver: s/buildId/buildID/ per golint

* internal/elfexec: remove punctuation in error string

golint reported: error strings should not be capitalized or end with
punctuation or a newline

* internal/graph: correct comment

Found with golint.

* internal/graph: add method comment

golint reported: exported method Edge.WeightValue should have comment
or be unexported

* internal/report: remove newline in error string

golint reported: error strings should not be capitalized or end with
punctuation or a newline

* *: remove unused code

Found with honnef.co/go/tools/cmd/unused:

	internal/binutils/disasm_test.go:137:8: const objdump is unused (U1000)
	internal/driver/driver_test.go:353:6: type testProfile is unused (U1000)
	internal/graph/graph.go:838:6: func countEdges is unused (U1000)
	profile/proto.go:148:6: func encodeStringOpt is unused (U1000)

* *: simply code

Found with honnef.co/go/tools/cmd/gosimple:

	internal/driver/commands.go:471:24: should omit comparison to bool constant, can be simplified to !b (S1002)
	internal/driver/driver.go:163:5: should omit comparison to bool constant, can be simplified to !trim (S1002)
	internal/driver/driver.go:168:5: should omit comparison to bool constant, can be simplified to !focus (S1002)
	internal/driver/driver.go:172:5: should omit comparison to bool constant, can be simplified to !tagfocus (S1002)
	internal/driver/driver.go:176:5: should omit comparison to bool constant, can be simplified to !hide (S1002)
	internal/graph/dotgraph.go:213:34: should use make(map[string][]*Tag) instead (S1019)
	internal/report/report.go:1061:3: should replace loop with label = append(label, rpt.options.ProfileLabels...) (S1011)
	profile/proto.go:157:5: should omit comparison to bool constant, can be simplified to !x (S1002)

* *: correct mistakes

Found with honnef.co/go/tools/cmd/staticcheck:

	driver/driver.go:280:20: infinite recursive call (SA5007)
	internal/driver/driver_focus.go:54:11: this value of err is never used (SA4006)
	profile/proto.go:74:32: x | 0 always equals x (SA4016)

* Add linters to .travis.yml
Tamir Duberstein 8 years ago
parent
commit
ff2edbdec7

+ 13
- 0
.travis.yml View File

2
 go:
2
 go:
3
   - 1.7.x
3
   - 1.7.x
4
   - 1.8.x
4
   - 1.8.x
5
+
6
+before_install:
7
+  - go get -u github.com/golang/lint/golint honnef.co/go/tools/cmd/...
8
+
9
+script:
10
+  - gofmtdiff=$(gofmt -s -d .) && if [ -n "$gofmtdiff" ]; then printf 'gofmt -s found:\n%s\n' "$gofmtdiff" && exit 1; fi
11
+  - golintlint=$(golint ./...) && if [ -n "$golintlint" ]; then printf 'golint found:\n%s\n' "$golintlint" && exit 1; fi
12
+  - go tool vet -all .
13
+  - gosimple ./...
14
+  - staticcheck ./...
15
+  - unused ./...
16
+  - go test -v ./...
17
+  - go test -v -race ./...

+ 4
- 4
driver/driver.go View File

29
 // manager. Then it generates a report formatted according to the
29
 // manager. Then it generates a report formatted according to the
30
 // options selected through the flags package.
30
 // options selected through the flags package.
31
 func PProf(o *Options) error {
31
 func PProf(o *Options) error {
32
-	return internaldriver.PProf(o.InternalOptions())
32
+	return internaldriver.PProf(o.internalOptions())
33
 }
33
 }
34
 
34
 
35
-func (o *Options) InternalOptions() *plugin.Options {
35
+func (o *Options) internalOptions() *plugin.Options {
36
 	var obj plugin.ObjTool
36
 	var obj plugin.ObjTool
37
 	if o.Obj != nil {
37
 	if o.Obj != nil {
38
 		obj = &internalObjTool{o.Obj}
38
 		obj = &internalObjTool{o.Obj}
273
 }
273
 }
274
 
274
 
275
 func (s *internalSymbolizer) Symbolize(mode string, srcs plugin.MappingSources, prof *profile.Profile) error {
275
 func (s *internalSymbolizer) Symbolize(mode string, srcs plugin.MappingSources, prof *profile.Profile) error {
276
-	isrcs := plugin.MappingSources{}
276
+	isrcs := MappingSources{}
277
 	for m, s := range srcs {
277
 	for m, s := range srcs {
278
 		isrcs[m] = s
278
 		isrcs[m] = s
279
 	}
279
 	}
280
-	return s.Symbolize(mode, isrcs, prof)
280
+	return s.Symbolizer.Symbolize(mode, isrcs, prof)
281
 }
281
 }

+ 1
- 3
internal/binutils/disasm_test.go View File

73
 
73
 
74
 func checkSymbol(got []*plugin.Sym, want []plugin.Sym) error {
74
 func checkSymbol(got []*plugin.Sym, want []plugin.Sym) error {
75
 	if len(got) != len(want) {
75
 	if len(got) != len(want) {
76
-		return fmt.Errorf("unexpected number of symbols %d (want %d)\n", len(got), len(want))
76
+		return fmt.Errorf("unexpected number of symbols %d (want %d)", len(got), len(want))
77
 	}
77
 	}
78
 
78
 
79
 	for i, g := range got {
79
 	for i, g := range got {
134
 		},
134
 		},
135
 	}
135
 	}
136
 
136
 
137
-	const objdump = "testdata/wrapper/objdump"
138
-
139
 	for _, tc := range testcases {
137
 	for _, tc := range testcases {
140
 		insts, err := disassemble([]byte(tc.asm))
138
 		insts, err := disassemble([]byte(tc.asm))
141
 		if err != nil {
139
 		if err != nil {

+ 1
- 1
internal/driver/commands.go View File

468
 	case boolKind:
468
 	case boolKind:
469
 		var b bool
469
 		var b bool
470
 		if b, err = stringToBool(value); err == nil {
470
 		if b, err = stringToBool(value); err == nil {
471
-			if v.group != "" && b == false {
471
+			if v.group != "" && !b {
472
 				err = fmt.Errorf("%q can only be set to true", name)
472
 				err = fmt.Errorf("%q can only be set to true", name)
473
 			}
473
 			}
474
 		}
474
 		}

+ 4
- 4
internal/driver/driver.go View File

160
 			v.set("nodecount", "80")
160
 			v.set("nodecount", "80")
161
 		}
161
 		}
162
 	}
162
 	}
163
-	if trim == false {
163
+	if !trim {
164
 		v.set("nodecount", "0")
164
 		v.set("nodecount", "0")
165
 		v.set("nodefraction", "0")
165
 		v.set("nodefraction", "0")
166
 		v.set("edgefraction", "0")
166
 		v.set("edgefraction", "0")
167
 	}
167
 	}
168
-	if focus == false {
168
+	if !focus {
169
 		v.set("focus", "")
169
 		v.set("focus", "")
170
 		v.set("ignore", "")
170
 		v.set("ignore", "")
171
 	}
171
 	}
172
-	if tagfocus == false {
172
+	if !tagfocus {
173
 		v.set("tagfocus", "")
173
 		v.set("tagfocus", "")
174
 		v.set("tagignore", "")
174
 		v.set("tagignore", "")
175
 	}
175
 	}
176
-	if hide == false {
176
+	if !hide {
177
 		v.set("hide", "")
177
 		v.set("hide", "")
178
 		v.set("show", "")
178
 		v.set("show", "")
179
 	}
179
 	}

+ 1
- 1
internal/driver/driver_focus.go View File

59
 	if prunefrom != nil {
59
 	if prunefrom != nil {
60
 		prof.PruneFrom(prunefrom)
60
 		prof.PruneFrom(prunefrom)
61
 	}
61
 	}
62
-	return nil
62
+	return err
63
 }
63
 }
64
 
64
 
65
 func compileRegexOption(name, value string, err error) (*regexp.Regexp, error) {
65
 func compileRegexOption(name, value string, err error) (*regexp.Regexp, error) {

+ 14
- 17
internal/driver/driver_test.go View File

350
 	}
350
 	}
351
 }
351
 }
352
 
352
 
353
-type testProfile struct {
354
-}
355
-
356
 const testStart = 0x1000
353
 const testStart = 0x1000
357
 const testOffset = 0x5000
354
 const testOffset = 0x5000
358
 
355
 
548
 				Location: []*profile.Location{cpuL[0], cpuL[1], cpuL[2]},
545
 				Location: []*profile.Location{cpuL[0], cpuL[1], cpuL[2]},
549
 				Value:    []int64{1000, 1000},
546
 				Value:    []int64{1000, 1000},
550
 				Label: map[string][]string{
547
 				Label: map[string][]string{
551
-					"key1": []string{"tag1"},
552
-					"key2": []string{"tag1"},
548
+					"key1": {"tag1"},
549
+					"key2": {"tag1"},
553
 				},
550
 				},
554
 			},
551
 			},
555
 			{
552
 			{
556
 				Location: []*profile.Location{cpuL[0], cpuL[3]},
553
 				Location: []*profile.Location{cpuL[0], cpuL[3]},
557
 				Value:    []int64{100, 100},
554
 				Value:    []int64{100, 100},
558
 				Label: map[string][]string{
555
 				Label: map[string][]string{
559
-					"key1": []string{"tag2"},
560
-					"key3": []string{"tag2"},
556
+					"key1": {"tag2"},
557
+					"key3": {"tag2"},
561
 				},
558
 				},
562
 			},
559
 			},
563
 			{
560
 			{
564
 				Location: []*profile.Location{cpuL[1], cpuL[4]},
561
 				Location: []*profile.Location{cpuL[1], cpuL[4]},
565
 				Value:    []int64{10, 10},
562
 				Value:    []int64{10, 10},
566
 				Label: map[string][]string{
563
 				Label: map[string][]string{
567
-					"key1": []string{"tag3"},
568
-					"key2": []string{"tag2"},
564
+					"key1": {"tag3"},
565
+					"key2": {"tag2"},
569
 				},
566
 				},
570
 			},
567
 			},
571
 			{
568
 			{
572
 				Location: []*profile.Location{cpuL[2]},
569
 				Location: []*profile.Location{cpuL[2]},
573
 				Value:    []int64{10, 10},
570
 				Value:    []int64{10, 10},
574
 				Label: map[string][]string{
571
 				Label: map[string][]string{
575
-					"key1": []string{"tag4"},
576
-					"key2": []string{"tag1"},
572
+					"key1": {"tag4"},
573
+					"key2": {"tag1"},
577
 				},
574
 				},
578
 			},
575
 			},
579
 		},
576
 		},
750
 				Location: []*profile.Location{heapL[0], heapL[1], heapL[2]},
747
 				Location: []*profile.Location{heapL[0], heapL[1], heapL[2]},
751
 				Value:    []int64{10, 1024000},
748
 				Value:    []int64{10, 1024000},
752
 				NumLabel: map[string][]int64{
749
 				NumLabel: map[string][]int64{
753
-					"bytes": []int64{102400},
750
+					"bytes": {102400},
754
 				},
751
 				},
755
 			},
752
 			},
756
 			{
753
 			{
757
 				Location: []*profile.Location{heapL[0], heapL[3]},
754
 				Location: []*profile.Location{heapL[0], heapL[3]},
758
 				Value:    []int64{20, 4096000},
755
 				Value:    []int64{20, 4096000},
759
 				NumLabel: map[string][]int64{
756
 				NumLabel: map[string][]int64{
760
-					"bytes": []int64{204800},
757
+					"bytes": {204800},
761
 				},
758
 				},
762
 			},
759
 			},
763
 			{
760
 			{
764
 				Location: []*profile.Location{heapL[1], heapL[4]},
761
 				Location: []*profile.Location{heapL[1], heapL[4]},
765
 				Value:    []int64{40, 65536000},
762
 				Value:    []int64{40, 65536000},
766
 				NumLabel: map[string][]int64{
763
 				NumLabel: map[string][]int64{
767
-					"bytes": []int64{1638400},
764
+					"bytes": {1638400},
768
 				},
765
 				},
769
 			},
766
 			},
770
 			{
767
 			{
771
 				Location: []*profile.Location{heapL[2]},
768
 				Location: []*profile.Location{heapL[2]},
772
 				Value:    []int64{80, 32768000},
769
 				Value:    []int64{80, 32768000},
773
 				NumLabel: map[string][]int64{
770
 				NumLabel: map[string][]int64{
774
-					"bytes": []int64{409600},
771
+					"bytes": {409600},
775
 				},
772
 				},
776
 			},
773
 			},
777
 		},
774
 		},
1051
 }
1048
 }
1052
 
1049
 
1053
 type mockFile struct {
1050
 type mockFile struct {
1054
-	name, buildId string
1051
+	name, buildID string
1055
 	base          uint64
1052
 	base          uint64
1056
 }
1053
 }
1057
 
1054
 
1067
 
1064
 
1068
 // BuildID returns the GNU build ID of the file, or an empty string.
1065
 // BuildID returns the GNU build ID of the file, or an empty string.
1069
 func (m *mockFile) BuildID() string {
1066
 func (m *mockFile) BuildID() string {
1070
-	return m.buildId
1067
+	return m.buildID
1071
 }
1068
 }
1072
 
1069
 
1073
 // SourceLine reports the source line information for a given
1070
 // SourceLine reports the source line information for a given

+ 1
- 1
internal/elfexec/elfexec.go View File

131
 				if buildID == nil {
131
 				if buildID == nil {
132
 					buildID = note.Desc
132
 					buildID = note.Desc
133
 				} else {
133
 				} else {
134
-					return nil, fmt.Errorf("multiple build ids found, don't know which to use!")
134
+					return nil, fmt.Errorf("multiple build ids found, don't know which to use")
135
 				}
135
 				}
136
 			}
136
 			}
137
 		}
137
 		}

+ 2
- 2
internal/graph/dotgraph.go View File

50
 	Total       int64                      // The total weight of the graph, used to compute percentages
50
 	Total       int64                      // The total weight of the graph, used to compute percentages
51
 }
51
 }
52
 
52
 
53
-// Compose creates and writes a in the DOT format to the writer, using
53
+// ComposeDot creates and writes a in the DOT format to the writer, using
54
 // the configurations given.
54
 // the configurations given.
55
 func ComposeDot(w io.Writer, g *Graph, a *DotAttributes, c *DotConfig) {
55
 func ComposeDot(w io.Writer, g *Graph, a *DotAttributes, c *DotConfig) {
56
 	builder := &builder{w, a, c}
56
 	builder := &builder{w, a, c}
210
 
210
 
211
 	// Populate two Tag slices, one for LabelTags and one for NumericTags.
211
 	// Populate two Tag slices, one for LabelTags and one for NumericTags.
212
 	var ts []*Tag
212
 	var ts []*Tag
213
-	lnts := make(map[string][]*Tag, 0)
213
+	lnts := make(map[string][]*Tag)
214
 	for _, t := range node.LabelTags {
214
 	for _, t := range node.LabelTags {
215
 		ts = append(ts, t)
215
 		ts = append(ts, t)
216
 	}
216
 	}

+ 4
- 4
internal/graph/dotgraph_test.go View File

240
 	}
240
 	}
241
 
241
 
242
 	tagWant := [][]*Tag{
242
 	tagWant := [][]*Tag{
243
-		[]*Tag{
243
+		{
244
 			makeTag("1B..2GB", "", 0, 2401, 2401),
244
 			makeTag("1B..2GB", "", 0, 2401, 2401),
245
 		},
245
 		},
246
-		[]*Tag{
246
+		{
247
 			makeTag("2GB", "", 0, 1000, 1000),
247
 			makeTag("2GB", "", 0, 1000, 1000),
248
 			makeTag("1B..12MB", "", 0, 1401, 1401),
248
 			makeTag("1B..12MB", "", 0, 1401, 1401),
249
 		},
249
 		},
250
-		[]*Tag{
250
+		{
251
 			makeTag("2GB", "", 0, 1000, 1000),
251
 			makeTag("2GB", "", 0, 1000, 1000),
252
 			makeTag("12MB", "", 0, 100, 100),
252
 			makeTag("12MB", "", 0, 100, 100),
253
 			makeTag("1B..1MB", "", 0, 1301, 1301),
253
 			makeTag("1B..1MB", "", 0, 1301, 1301),
254
 		},
254
 		},
255
-		[]*Tag{
255
+		{
256
 			makeTag("2GB", "", 0, 1000, 1000),
256
 			makeTag("2GB", "", 0, 1000, 1000),
257
 			makeTag("1MB", "", 0, 1000, 1000),
257
 			makeTag("1MB", "", 0, 1000, 1000),
258
 			makeTag("2B..1kB", "", 0, 201, 201),
258
 			makeTag("2B..1kB", "", 0, 201, 201),

+ 2
- 11
internal/graph/graph.go View File

240
 	Inline bool
240
 	Inline bool
241
 }
241
 }
242
 
242
 
243
+// WeightValue returns the weight value for this edge, normalizing if a
244
+// divisor is available.
243
 func (e *Edge) WeightValue() int64 {
245
 func (e *Edge) WeightValue() int64 {
244
 	if e.WeightDiv == 0 {
246
 	if e.WeightDiv == 0 {
245
 		return e.Weight
247
 		return e.Weight
832
 	return count
834
 	return count
833
 }
835
 }
834
 
836
 
835
-// countEdges counts the number of edges below the specified cutoff.
836
-func countEdges(el EdgeMap, cutoff int64) int {
837
-	count := 0
838
-	for _, e := range el {
839
-		if e.Weight > cutoff {
840
-			count++
841
-		}
842
-	}
843
-	return count
844
-}
845
-
846
 // RemoveRedundantEdges removes residual edges if the destination can
837
 // RemoveRedundantEdges removes residual edges if the destination can
847
 // be reached through another path. This is done to simplify the graph
838
 // be reached through another path. This is done to simplify the graph
848
 // while preserving connectivity.
839
 // while preserving connectivity.

+ 1
- 3
internal/report/report.go View File

1058
 
1058
 
1059
 	var label []string
1059
 	var label []string
1060
 	if len(rpt.options.ProfileLabels) > 0 {
1060
 	if len(rpt.options.ProfileLabels) > 0 {
1061
-		for _, l := range rpt.options.ProfileLabels {
1062
-			label = append(label, l)
1063
-		}
1061
+		label = append(label, rpt.options.ProfileLabels...)
1064
 	} else if fullHeaders || !rpt.options.CompactLabels {
1062
 	} else if fullHeaders || !rpt.options.CompactLabels {
1065
 		label = ProfileLabels(rpt)
1063
 		label = ProfileLabels(rpt)
1066
 	}
1064
 	}

+ 1
- 1
internal/report/source.go View File

167
 	}
167
 	}
168
 
168
 
169
 	if len(fileNodes) == 0 {
169
 	if len(fileNodes) == 0 {
170
-		return fmt.Errorf("No source information for %s\n", o.Symbol.String())
170
+		return fmt.Errorf("No source information for %s", o.Symbol.String())
171
 	}
171
 	}
172
 
172
 
173
 	sourceFiles := make(graph.Nodes, 0, len(fileNodes))
173
 	sourceFiles := make(graph.Nodes, 0, len(fileNodes))

+ 5
- 5
internal/symbolizer/symbolizer_test.go View File

207
 }
207
 }
208
 
208
 
209
 var mockAddresses = map[uint64][]plugin.Frame{
209
 var mockAddresses = map[uint64][]plugin.Frame{
210
-	1000: []plugin.Frame{frame("fun11", "file11.src", 10)},
211
-	2000: []plugin.Frame{frame("fun21", "file21.src", 20), frame("fun22", "file22.src", 20)},
212
-	3000: []plugin.Frame{frame("fun31", "file31.src", 30), frame("fun32", "file32.src", 30), frame("fun33", "file33.src", 30)},
213
-	4000: []plugin.Frame{frame("fun41", "file41.src", 40), frame("fun42", "file42.src", 40), frame("fun43", "file43.src", 40), frame("fun44", "file44.src", 40)},
214
-	5000: []plugin.Frame{frame("fun51", "file51.src", 50), frame("fun52", "file52.src", 50), frame("fun53", "file53.src", 50), frame("fun54", "file54.src", 50), frame("fun55", "file55.src", 50)},
210
+	1000: {frame("fun11", "file11.src", 10)},
211
+	2000: {frame("fun21", "file21.src", 20), frame("fun22", "file22.src", 20)},
212
+	3000: {frame("fun31", "file31.src", 30), frame("fun32", "file32.src", 30), frame("fun33", "file33.src", 30)},
213
+	4000: {frame("fun41", "file41.src", 40), frame("fun42", "file42.src", 40), frame("fun43", "file43.src", 40), frame("fun44", "file44.src", 40)},
214
+	5000: {frame("fun51", "file51.src", 50), frame("fun52", "file52.src", 50), frame("fun53", "file53.src", 50), frame("fun54", "file54.src", 50), frame("fun55", "file55.src", 50)},
215
 }
215
 }
216
 
216
 
217
 func frame(fname, file string, line int) plugin.Frame {
217
 func frame(fname, file string, line int) plugin.Frame {

+ 1
- 1
profile/legacy_java_profile.go View File

212
 			switch pType {
212
 			switch pType {
213
 			case "heap":
213
 			case "heap":
214
 				const javaHeapzSamplingRate = 524288 // 512K
214
 				const javaHeapzSamplingRate = 524288 // 512K
215
-				s.NumLabel = map[string][]int64{"bytes": []int64{s.Value[1] / s.Value[0]}}
215
+				s.NumLabel = map[string][]int64{"bytes": {s.Value[1] / s.Value[0]}}
216
 				s.Value[0], s.Value[1] = scaleHeapSample(s.Value[0], s.Value[1], javaHeapzSamplingRate)
216
 				s.Value[0], s.Value[1] = scaleHeapSample(s.Value[0], s.Value[1], javaHeapzSamplingRate)
217
 			case "contention":
217
 			case "contention":
218
 				if period := p.Period; period != 0 {
218
 				if period := p.Period; period != 0 {

+ 14
- 14
profile/profile_test.go View File

230
 			Location: []*Location{cpuL[0]},
230
 			Location: []*Location{cpuL[0]},
231
 			Value:    []int64{1000, 1000},
231
 			Value:    []int64{1000, 1000},
232
 			Label: map[string][]string{
232
 			Label: map[string][]string{
233
-				"key1": []string{"tag1"},
234
-				"key2": []string{"tag1"},
233
+				"key1": {"tag1"},
234
+				"key2": {"tag1"},
235
 			},
235
 			},
236
 		},
236
 		},
237
 		{
237
 		{
238
 			Location: []*Location{cpuL[1], cpuL[0]},
238
 			Location: []*Location{cpuL[1], cpuL[0]},
239
 			Value:    []int64{100, 100},
239
 			Value:    []int64{100, 100},
240
 			Label: map[string][]string{
240
 			Label: map[string][]string{
241
-				"key1": []string{"tag2"},
242
-				"key3": []string{"tag2"},
241
+				"key1": {"tag2"},
242
+				"key3": {"tag2"},
243
 			},
243
 			},
244
 		},
244
 		},
245
 		{
245
 		{
246
 			Location: []*Location{cpuL[2], cpuL[0]},
246
 			Location: []*Location{cpuL[2], cpuL[0]},
247
 			Value:    []int64{10, 10},
247
 			Value:    []int64{10, 10},
248
 			Label: map[string][]string{
248
 			Label: map[string][]string{
249
-				"key1": []string{"tag3"},
250
-				"key2": []string{"tag2"},
249
+				"key1": {"tag3"},
250
+				"key2": {"tag2"},
251
 			},
251
 			},
252
 		},
252
 		},
253
 		{
253
 		{
254
 			Location: []*Location{cpuL[3], cpuL[0]},
254
 			Location: []*Location{cpuL[3], cpuL[0]},
255
 			Value:    []int64{10000, 10000},
255
 			Value:    []int64{10000, 10000},
256
 			Label: map[string][]string{
256
 			Label: map[string][]string{
257
-				"key1": []string{"tag4"},
258
-				"key2": []string{"tag1"},
257
+				"key1": {"tag4"},
258
+				"key2": {"tag1"},
259
 			},
259
 			},
260
 		},
260
 		},
261
 		{
261
 		{
262
 			Location: []*Location{cpuL[4], cpuL[0]},
262
 			Location: []*Location{cpuL[4], cpuL[0]},
263
 			Value:    []int64{1, 1},
263
 			Value:    []int64{1, 1},
264
 			Label: map[string][]string{
264
 			Label: map[string][]string{
265
-				"key1": []string{"tag4"},
266
-				"key2": []string{"tag1"},
265
+				"key1": {"tag4"},
266
+				"key2": {"tag1"},
267
 			},
267
 			},
268
 		},
268
 		},
269
 	},
269
 	},
273
 }
273
 }
274
 
274
 
275
 var aggTests = map[string]aggTest{
275
 var aggTests = map[string]aggTest{
276
-	"precise":         aggTest{true, true, true, true, 5},
277
-	"fileline":        aggTest{false, true, true, true, 4},
278
-	"inline_function": aggTest{false, true, false, true, 3},
279
-	"function":        aggTest{false, true, false, false, 2},
276
+	"precise":         {true, true, true, true, 5},
277
+	"fileline":        {false, true, true, true, 4},
278
+	"inline_function": {false, true, false, true, 3},
279
+	"function":        {false, true, false, false, 2},
280
 }
280
 }
281
 
281
 
282
 type aggTest struct {
282
 type aggTest struct {

+ 3
- 11
profile/proto.go View File

71
 
71
 
72
 func encodeUint64(b *buffer, tag int, x uint64) {
72
 func encodeUint64(b *buffer, tag int, x uint64) {
73
 	// append varint to b.data
73
 	// append varint to b.data
74
-	encodeVarint(b, uint64(tag)<<3|0)
74
+	encodeVarint(b, uint64(tag)<<3)
75
 	encodeVarint(b, x)
75
 	encodeVarint(b, x)
76
 }
76
 }
77
 
77
 
145
 	}
145
 	}
146
 }
146
 }
147
 
147
 
148
-func encodeStringOpt(b *buffer, tag int, x string) {
149
-	if x == "" {
150
-		return
151
-	}
152
-	encodeString(b, tag, x)
153
-}
154
-
155
 func encodeBool(b *buffer, tag int, x bool) {
148
 func encodeBool(b *buffer, tag int, x bool) {
156
 	if x {
149
 	if x {
157
 		encodeUint64(b, tag, 1)
150
 		encodeUint64(b, tag, 1)
161
 }
154
 }
162
 
155
 
163
 func encodeBoolOpt(b *buffer, tag int, x bool) {
156
 func encodeBoolOpt(b *buffer, tag int, x bool) {
164
-	if x == false {
165
-		return
157
+	if x {
158
+		encodeBool(b, tag, x)
166
 	}
159
 	}
167
-	encodeBool(b, tag, x)
168
 }
160
 }
169
 
161
 
170
 func encodeMessage(b *buffer, tag int, m message) {
162
 func encodeMessage(b *buffer, tag int, m message) {

+ 6
- 6
profile/proto_test.go View File

100
 		{
100
 		{
101
 			Location: []*Location{testL[0], testL[1], testL[2], testL[1], testL[1]},
101
 			Location: []*Location{testL[0], testL[1], testL[2], testL[1], testL[1]},
102
 			Label: map[string][]string{
102
 			Label: map[string][]string{
103
-				"key1": []string{"value1"},
104
-				"key2": []string{"value2"},
103
+				"key1": {"value1"},
104
+				"key2": {"value2"},
105
 			},
105
 			},
106
 			Value: []int64{10, 20},
106
 			Value: []int64{10, 20},
107
 		},
107
 		},
109
 			Location: []*Location{testL[1], testL[2], testL[0], testL[1]},
109
 			Location: []*Location{testL[1], testL[2], testL[0], testL[1]},
110
 			Value:    []int64{30, 40},
110
 			Value:    []int64{30, 40},
111
 			Label: map[string][]string{
111
 			Label: map[string][]string{
112
-				"key1": []string{"value1"},
113
-				"key2": []string{"value2"},
112
+				"key1": {"value1"},
113
+				"key2": {"value2"},
114
 			},
114
 			},
115
 			NumLabel: map[string][]int64{
115
 			NumLabel: map[string][]int64{
116
-				"key1": []int64{1, 2},
117
-				"key2": []int64{3, 4},
116
+				"key1": {1, 2},
117
+				"key2": {3, 4},
118
 			},
118
 			},
119
 		},
119
 		},
120
 	},
120
 	},