Browse Source

Merge pull request #43 from rauls5382/golang

Upstream minor changes from golang version of pprof
Josef Jelinek 8 years ago
parent
commit
2abe7148c6

+ 1
- 1
driver/driver.go View File

123
 
123
 
124
 // An ObjTool inspects shared libraries and executable files.
124
 // An ObjTool inspects shared libraries and executable files.
125
 type ObjTool interface {
125
 type ObjTool interface {
126
-	// Open opens the named object file.  If the object is a shared
126
+	// Open opens the named object file. If the object is a shared
127
 	// library, start/limit/offset are the addresses where it is mapped
127
 	// library, start/limit/offset are the addresses where it is mapped
128
 	// into memory in the address space being inspected.
128
 	// into memory in the address space being inspected.
129
 	Open(file string, start, limit, offset uint64) (ObjFile, error)
129
 	Open(file string, start, limit, offset uint64) (ObjFile, error)

+ 2
- 2
internal/binutils/addr2liner.go View File

129
 	}
129
 	}
130
 	if strings.HasPrefix(funcname, "0x") {
130
 	if strings.HasPrefix(funcname, "0x") {
131
 		// If addr2line returns a hex address we can assume it is the
131
 		// If addr2line returns a hex address we can assume it is the
132
-		// sentinel.  Read and ignore next two lines of output from
132
+		// sentinel. Read and ignore next two lines of output from
133
 		// addr2line
133
 		// addr2line
134
 		d.readString()
134
 		d.readString()
135
 		d.readString()
135
 		d.readString()
204
 		nm, err := d.nm.addrInfo(addr)
204
 		nm, err := d.nm.addrInfo(addr)
205
 		if err == nil && len(nm) > 0 {
205
 		if err == nil && len(nm) > 0 {
206
 			// Last entry in frame list should match since
206
 			// Last entry in frame list should match since
207
-			// it is non-inlined.  As a simple heuristic,
207
+			// it is non-inlined. As a simple heuristic,
208
 			// we only switch to the nm-based name if it
208
 			// we only switch to the nm-based name if it
209
 			// is longer.
209
 			// is longer.
210
 			nmName := nm[len(nm)-1].Func
210
 			nmName := nm[len(nm)-1].Func

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

164
 	var pageAligned = func(addr uint64) bool { return addr%4096 == 0 }
164
 	var pageAligned = func(addr uint64) bool { return addr%4096 == 0 }
165
 	if strings.Contains(name, "vmlinux") || !pageAligned(start) || !pageAligned(limit) || !pageAligned(offset) {
165
 	if strings.Contains(name, "vmlinux") || !pageAligned(start) || !pageAligned(limit) || !pageAligned(offset) {
166
 		// Reading all Symbols is expensive, and we only rarely need it so
166
 		// Reading all Symbols is expensive, and we only rarely need it so
167
-		// we don't want to do it every time.  But if _stext happens to be
167
+		// we don't want to do it every time. But if _stext happens to be
168
 		// page-aligned but isn't the same as Vaddr, we would symbolize
168
 		// page-aligned but isn't the same as Vaddr, we would symbolize
169
-		// wrong.  So if the name the addresses aren't page aligned, or if
170
-		// the name is "vmlinux" we read _stext.  We can be wrong if: (1)
169
+		// wrong. So if the name the addresses aren't page aligned, or if
170
+		// the name is "vmlinux" we read _stext. We can be wrong if: (1)
171
 		// someone passes a kernel path that doesn't contain "vmlinux" AND
171
 		// someone passes a kernel path that doesn't contain "vmlinux" AND
172
 		// (2) _stext is page-aligned AND (3) _stext is not at Vaddr
172
 		// (2) _stext is page-aligned AND (3) _stext is not at Vaddr
173
 		symbols, err := ef.Symbols()
173
 		symbols, err := ef.Symbols()

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

107
 		}
107
 		}
108
 	}
108
 	}
109
 
109
 
110
+	if len(p.Sample) == 0 {
111
+		return fmt.Errorf("profile is empty")
112
+	}
113
+
110
 	if err := aggregate(p, vars); err != nil {
114
 	if err := aggregate(p, vars); err != nil {
111
 		return err
115
 		return err
112
 	}
116
 	}

+ 2
- 2
internal/driver/testdata/pprof.cpu.flat.addresses.weblist View File

67
 <div class="legend">File: testbinary<br>
67
 <div class="legend">File: testbinary<br>
68
 Type: cpu<br>
68
 Type: cpu<br>
69
 Duration: 10s, Total samples = 1.12s (11.20%)<br>Total: 1.12s</div><h1>line1000</h1>testdata/file1000.src
69
 Duration: 10s, Total samples = 1.12s (11.20%)<br>Total: 1.12s</div><h1>line1000</h1>testdata/file1000.src
70
-<pre onClick="pprof_toggle_asm()">
70
+<pre onClick="pprof_toggle_asm(event)">
71
   Total:       1.10s      1.10s (flat, cum) 98.21%
71
   Total:       1.10s      1.10s (flat, cum) 98.21%
72
 <span class=line>      1</span> <span class=deadsrc>       1.10s      1.10s line1 </span><span class=asm>               1.10s      1.10s     1000: instruction one                                  <span class=disasmloc>testdata/file1000.src:1</span>
72
 <span class=line>      1</span> <span class=deadsrc>       1.10s      1.10s line1 </span><span class=asm>               1.10s      1.10s     1000: instruction one                                  <span class=disasmloc>testdata/file1000.src:1</span>
73
                    .          .     1001: instruction two                                  <span class=disasmloc></span>
73
                    .          .     1001: instruction two                                  <span class=disasmloc></span>
81
 <span class=line>      6</span> <span class=nop>           .          . line6 </span>
81
 <span class=line>      6</span> <span class=nop>           .          . line6 </span>
82
 </pre>
82
 </pre>
83
 <h1>line3000</h1>testdata/file3000.src
83
 <h1>line3000</h1>testdata/file3000.src
84
-<pre onClick="pprof_toggle_asm()">
84
+<pre onClick="pprof_toggle_asm(event)">
85
   Total:        10ms      1.12s (flat, cum)   100%
85
   Total:        10ms      1.12s (flat, cum)   100%
86
 <span class=line>      1</span> <span class=nop>           .          . line1 </span>
86
 <span class=line>      1</span> <span class=nop>           .          . line1 </span>
87
 <span class=line>      2</span> <span class=nop>           .          . line2 </span>
87
 <span class=line>      2</span> <span class=nop>           .          . line2 </span>

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

166
 }
166
 }
167
 
167
 
168
 // GetBase determines the base address to subtract from virtual
168
 // GetBase determines the base address to subtract from virtual
169
-// address to get symbol table address.  For an executable, the base
170
-// is 0.  Otherwise, it's a shared library, and the base is the
171
-// address where the mapping starts.  The kernel is special, and may
172
-// use the address of the _stext symbol as the mmap start.  _stext
169
+// address to get symbol table address. For an executable, the base
170
+// is 0. Otherwise, it's a shared library, and the base is the
171
+// address where the mapping starts. The kernel is special, and may
172
+// use the address of the _stext symbol as the mmap start. _stext
173
 // offset can be obtained with `nm vmlinux | grep _stext`
173
 // offset can be obtained with `nm vmlinux | grep _stext`
174
 func GetBase(fh *elf.FileHeader, loadSegment *elf.ProgHeader, stextOffset *uint64, start, limit, offset uint64) (uint64, error) {
174
 func GetBase(fh *elf.FileHeader, loadSegment *elf.ProgHeader, stextOffset *uint64, start, limit, offset uint64) (uint64, error) {
175
 	const (
175
 	const (
193
 			return 0, nil
193
 			return 0, nil
194
 		}
194
 		}
195
 		if start == 0 && limit != 0 {
195
 		if start == 0 && limit != 0 {
196
-			// ChromeOS remaps its kernel to 0.  Nothing else should come
197
-			// down this path.  Empirical values:
196
+			// ChromeOS remaps its kernel to 0. Nothing else should come
197
+			// down this path. Empirical values:
198
 			//       VADDR=0xffffffff80200000
198
 			//       VADDR=0xffffffff80200000
199
 			// stextOffset=0xffffffff80200198
199
 			// stextOffset=0xffffffff80200198
200
 			if stextOffset != nil {
200
 			if stextOffset != nil {
217
 			//      Offset=0 (0xc000000000000000 for PowerPC64)
217
 			//      Offset=0 (0xc000000000000000 for PowerPC64)
218
 			// So the base should be:
218
 			// So the base should be:
219
 			if stextOffset != nil && (start%pageSize) == (*stextOffset%pageSize) {
219
 			if stextOffset != nil && (start%pageSize) == (*stextOffset%pageSize) {
220
-				// perf uses the address of _stext as start.  Some tools may
220
+				// perf uses the address of _stext as start. Some tools may
221
 				// adjust for this before calling GetBase, in which case the the page
221
 				// adjust for this before calling GetBase, in which case the the page
222
 				// alignment should be different from that of stextOffset.
222
 				// alignment should be different from that of stextOffset.
223
 				return start - *stextOffset, nil
223
 				return start - *stextOffset, nil
225
 
225
 
226
 			return start - loadSegment.Vaddr, nil
226
 			return start - loadSegment.Vaddr, nil
227
 		} else if start < loadSegment.Vaddr && start%pageSize != 0 && stextOffset != nil && *stextOffset%pageSize == start%pageSize {
227
 		} else if start < loadSegment.Vaddr && start%pageSize != 0 && stextOffset != nil && *stextOffset%pageSize == start%pageSize {
228
-			// ChromeOS remaps its kernel to 0 + start%pageSize.  Nothing
229
-			// else should come down this path.  Empirical values:
228
+			// ChromeOS remaps its kernel to 0 + start%pageSize. Nothing
229
+			// else should come down this path. Empirical values:
230
 			//       start=0x198 limit=0x2f9fffff offset=0
230
 			//       start=0x198 limit=0x2f9fffff offset=0
231
 			//       VADDR=0xffffffff81000000
231
 			//       VADDR=0xffffffff81000000
232
 			// stextOffset=0xffffffff81000198
232
 			// stextOffset=0xffffffff81000198

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

313
 
313
 
314
 // dotColor returns a color for the given score (between -1.0 and
314
 // dotColor returns a color for the given score (between -1.0 and
315
 // 1.0), with -1.0 colored red, 0.0 colored grey, and 1.0 colored
315
 // 1.0), with -1.0 colored red, 0.0 colored grey, and 1.0 colored
316
-// green.  If isBackground is true, then a light (low-saturation)
316
+// green. If isBackground is true, then a light (low-saturation)
317
 // color is returned (suitable for use as a background color);
317
 // color is returned (suitable for use as a background color);
318
 // otherwise, a darker color is returned (suitable for use as a
318
 // otherwise, a darker color is returned (suitable for use as a
319
 // foreground color).
319
 // foreground color).

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

55
 	// Info describes the source location associated to this node.
55
 	// Info describes the source location associated to this node.
56
 	Info NodeInfo
56
 	Info NodeInfo
57
 
57
 
58
-	// Function represents the function that this node belongs to.  On
58
+	// Function represents the function that this node belongs to. On
59
 	// graphs with sub-function resolution (eg line number or
59
 	// graphs with sub-function resolution (eg line number or
60
 	// addresses), two nodes in a NodeMap that are part of the same
60
 	// addresses), two nodes in a NodeMap that are part of the same
61
 	// function have the same value of Node.Function. If the Node
61
 	// function have the same value of Node.Function. If the Node
508
 	}
508
 	}
509
 }
509
 }
510
 
510
 
511
-// CreateNodes creates graph nodes for all locations in a profile.  It
511
+// CreateNodes creates graph nodes for all locations in a profile. It
512
 // returns set of all nodes, plus a mapping of each location to the
512
 // returns set of all nodes, plus a mapping of each location to the
513
 // set of corresponding nodes (one per location.Line). If kept is
513
 // set of corresponding nodes (one per location.Line). If kept is
514
 // non-nil, only nodes in that set are included; nodes that do not
514
 // non-nil, only nodes in that set are included; nodes that do not

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

115
 }
115
 }
116
 
116
 
117
 // Scale a measurement from an unit to a different unit and returns
117
 // Scale a measurement from an unit to a different unit and returns
118
-// the scaled value and the target unit.  The returned target unit
118
+// the scaled value and the target unit. The returned target unit
119
 // will be empty if uninteresting (could be skipped).
119
 // will be empty if uninteresting (could be skipped).
120
 func Scale(value int64, fromUnit, toUnit string) (float64, string) {
120
 func Scale(value int64, fromUnit, toUnit string) (float64, string) {
121
 	// Avoid infinite recursion on overflow.
121
 	// Avoid infinite recursion on overflow.

+ 2
- 2
internal/plugin/plugin.go View File

73
 	Parse(usage func()) []string
73
 	Parse(usage func()) []string
74
 }
74
 }
75
 
75
 
76
-// A Fetcher reads and returns the profile named by src.  src can be a
76
+// A Fetcher reads and returns the profile named by src. src can be a
77
 // local file path or a URL. duration and timeout are units specified
77
 // local file path or a URL. duration and timeout are units specified
78
 // by the end user, or 0 by default. duration refers to the length of
78
 // by the end user, or 0 by default. duration refers to the length of
79
 // the profile collection, if applicable, and timeout is the amount of
79
 // the profile collection, if applicable, and timeout is the amount of
98
 
98
 
99
 // An ObjTool inspects shared libraries and executable files.
99
 // An ObjTool inspects shared libraries and executable files.
100
 type ObjTool interface {
100
 type ObjTool interface {
101
-	// Open opens the named object file.  If the object is a shared
101
+	// Open opens the named object file. If the object is a shared
102
 	// library, start/limit/offset are the addresses where it is mapped
102
 	// library, start/limit/offset are the addresses where it is mapped
103
 	// into memory in the address space being inspected.
103
 	// into memory in the address space being inspected.
104
 	Open(file string, start, limit, offset uint64) (ObjFile, error)
104
 	Open(file string, start, limit, offset uint64) (ObjFile, error)

+ 5
- 31
internal/report/report.go View File

20
 	"fmt"
20
 	"fmt"
21
 	"io"
21
 	"io"
22
 	"math"
22
 	"math"
23
-	"os"
24
 	"path/filepath"
23
 	"path/filepath"
25
 	"regexp"
24
 	"regexp"
26
 	"sort"
25
 	"sort"
419
 }
418
 }
420
 
419
 
421
 // annotateAssembly annotates a set of assembly instructions with a
420
 // annotateAssembly annotates a set of assembly instructions with a
422
-// set of samples. It returns a set of nodes to display.  base is an
421
+// set of samples. It returns a set of nodes to display. base is an
423
 // offset to adjust the sample addresses.
422
 // offset to adjust the sample addresses.
424
 func annotateAssembly(insns []plugin.Inst, samples graph.Nodes, base uint64) graph.Nodes {
423
 func annotateAssembly(insns []plugin.Inst, samples graph.Nodes, base uint64) graph.Nodes {
425
 	// Add end marker to simplify printing loop.
424
 	// Add end marker to simplify printing loop.
426
-	insns = append(insns, plugin.Inst{^uint64(0), "", "", 0})
425
+	insns = append(insns, plugin.Inst{
426
+		Addr: ^uint64(0),
427
+	})
427
 
428
 
428
 	// Ensure samples are sorted by address.
429
 	// Ensure samples are sorted by address.
429
 	samples.Sort(graph.AddressOrder)
430
 	samples.Sort(graph.AddressOrder)
467
 	return rpt.formatValue(value)
468
 	return rpt.formatValue(value)
468
 }
469
 }
469
 
470
 
470
-// canAccessFile determines if the filename can be opened for reading.
471
-func canAccessFile(path string) bool {
472
-	if fi, err := os.Stat(path); err == nil {
473
-		return fi.Mode().Perm()&0400 != 0
474
-	}
475
-	return false
476
-}
477
-
478
 // printTags collects all tags referenced in the profile and prints
471
 // printTags collects all tags referenced in the profile and prints
479
 // them in a sorted table.
472
 // them in a sorted table.
480
 func printTags(w io.Writer, rpt *Report) error {
473
 func printTags(w io.Writer, rpt *Report) error {
725
 
718
 
726
 // callgrindName implements the callgrind naming compression scheme.
719
 // callgrindName implements the callgrind naming compression scheme.
727
 // For names not previously seen returns "(N) name", where N is a
720
 // For names not previously seen returns "(N) name", where N is a
728
-// unique index.  For names previously seen returns "(N)" where N is
721
+// unique index. For names previously seen returns "(N)" where N is
729
 // the index returned the first time.
722
 // the index returned the first time.
730
 func callgrindName(names map[string]int, name string) string {
723
 func callgrindName(names map[string]int, name string) string {
731
 	if name == "" {
724
 	if name == "" {
1051
 	formatValue func(int64) string
1044
 	formatValue func(int64) string
1052
 }
1045
 }
1053
 
1046
 
1054
-func (rpt *Report) formatTags(s *profile.Sample) (string, bool) {
1055
-	var labels []string
1056
-	for key, vals := range s.Label {
1057
-		for _, v := range vals {
1058
-			labels = append(labels, key+":"+v)
1059
-		}
1060
-	}
1061
-	for key, nvals := range s.NumLabel {
1062
-		for _, v := range nvals {
1063
-			labels = append(labels, measurement.Label(v, key))
1064
-		}
1065
-	}
1066
-	if len(labels) == 0 {
1067
-		return "", false
1068
-	}
1069
-	sort.Strings(labels)
1070
-	return strings.Join(labels, `\n`), true
1071
-}
1072
-
1073
 func abs64(i int64) int64 {
1047
 func abs64(i int64) int64 {
1074
 	if i < 0 {
1048
 	if i < 0 {
1075
 		return -i
1049
 		return -i

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

281
 // printFunctionHeader prints a function header for a weblist report.
281
 // printFunctionHeader prints a function header for a weblist report.
282
 func printFunctionHeader(w io.Writer, name, path string, flatSum, cumSum int64, rpt *Report) {
282
 func printFunctionHeader(w io.Writer, name, path string, flatSum, cumSum int64, rpt *Report) {
283
 	fmt.Fprintf(w, `<h1>%s</h1>%s
283
 	fmt.Fprintf(w, `<h1>%s</h1>%s
284
-<pre onClick="pprof_toggle_asm()">
284
+<pre onClick="pprof_toggle_asm(event)">
285
   Total:  %10s %10s (flat, cum) %s
285
   Total:  %10s %10s (flat, cum) %s
286
 `,
286
 `,
287
 		template.HTMLEscapeString(name), template.HTMLEscapeString(path),
287
 		template.HTMLEscapeString(name), template.HTMLEscapeString(path),

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

36
 
36
 
37
 // Symbolize symbolizes profile p by parsing data returned by a
37
 // Symbolize symbolizes profile p by parsing data returned by a
38
 // symbolz handler. syms receives the symbolz query (hex addresses
38
 // symbolz handler. syms receives the symbolz query (hex addresses
39
-// separated by '+') and returns the symbolz output in a string.  It
39
+// separated by '+') and returns the symbolz output in a string. It
40
 // symbolizes all locations based on their addresses, regardless of
40
 // symbolizes all locations based on their addresses, regardless of
41
 // mapping.
41
 // mapping.
42
 func Symbolize(sources plugin.MappingSources, syms func(string, string) ([]byte, error), p *profile.Profile, ui plugin.UI) error {
42
 func Symbolize(sources plugin.MappingSources, syms func(string, string) ([]byte, error), p *profile.Profile, ui plugin.UI) error {

+ 1
- 0
pprof.go View File

26
 func main() {
26
 func main() {
27
 	if err := driver.PProf(&driver.Options{}); err != nil {
27
 	if err := driver.PProf(&driver.Options{}); err != nil {
28
 		fmt.Fprintf(os.Stderr, "pprof: %v\n", err)
28
 		fmt.Fprintf(os.Stderr, "pprof: %v\n", err)
29
+		os.Exit(2)
29
 	}
30
 	}
30
 }
31
 }

+ 1
- 1
profile/encode.go View File

24
 }
24
 }
25
 
25
 
26
 // preEncode populates the unexported fields to be used by encode
26
 // preEncode populates the unexported fields to be used by encode
27
-// (with suffix X) from the corresponding exported fields.  The
27
+// (with suffix X) from the corresponding exported fields. The
28
 // exported fields are cleared up to facilitate testing.
28
 // exported fields are cleared up to facilitate testing.
29
 func (p *Profile) preEncode() {
29
 func (p *Profile) preEncode() {
30
 	strings := make(map[string]int)
30
 	strings := make(map[string]int)

+ 10
- 10
profile/legacy_profile.go View File

78
 	if m == nil {
78
 	if m == nil {
79
 		return nil, errUnrecognized
79
 		return nil, errUnrecognized
80
 	}
80
 	}
81
-	profileType := string(m[1])
81
+	profileType := m[1]
82
 	p := &Profile{
82
 	p := &Profile{
83
 		PeriodType: &ValueType{Type: profileType, Unit: "count"},
83
 		PeriodType: &ValueType{Type: profileType, Unit: "count"},
84
 		Period:     1,
84
 		Period:     1,
103
 		if m == nil {
103
 		if m == nil {
104
 			return nil, errMalformed
104
 			return nil, errMalformed
105
 		}
105
 		}
106
-		n, err := strconv.ParseInt(string(m[1]), 0, 64)
106
+		n, err := strconv.ParseInt(m[1], 0, 64)
107
 		if err != nil {
107
 		if err != nil {
108
 			return nil, errMalformed
108
 			return nil, errMalformed
109
 		}
109
 		}
110
-		fields := strings.Fields(string(m[2]))
110
+		fields := strings.Fields(m[2])
111
 		locs := make([]*Location, 0, len(fields))
111
 		locs := make([]*Location, 0, len(fields))
112
 		for _, stk := range fields {
112
 		for _, stk := range fields {
113
 			addr, err := strconv.ParseUint(stk, 0, 64)
113
 			addr, err := strconv.ParseUint(stk, 0, 64)
407
 //   3rd word -- 0
407
 //   3rd word -- 0
408
 //
408
 //
409
 // Addresses from stack traces may point to the next instruction after
409
 // Addresses from stack traces may point to the next instruction after
410
-// each call.  Optionally adjust by -1 to land somewhere on the actual
410
+// each call. Optionally adjust by -1 to land somewhere on the actual
411
 // call (except for the leaf, which is not a call).
411
 // call (except for the leaf, which is not a call).
412
 func parseCPUSamples(b []byte, parse func(b []byte) (uint64, []byte), adjust bool, p *Profile) ([]byte, map[uint64]*Location, error) {
412
 func parseCPUSamples(b []byte, parse func(b []byte) (uint64, []byte), adjust bool, p *Profile) ([]byte, map[uint64]*Location, error) {
413
 	locs := make(map[uint64]*Location)
413
 	locs := make(map[uint64]*Location)
444
 		}
444
 		}
445
 		p.Sample = append(p.Sample,
445
 		p.Sample = append(p.Sample,
446
 			&Sample{
446
 			&Sample{
447
-				Value:    []int64{int64(count), int64(count) * int64(p.Period)},
447
+				Value:    []int64{int64(count), int64(count) * p.Period},
448
 				Location: sloc,
448
 				Location: sloc,
449
 			})
449
 			})
450
 	}
450
 	}
526
 		var sloc []*Location
526
 		var sloc []*Location
527
 		for _, addr := range addrs {
527
 		for _, addr := range addrs {
528
 			// Addresses from stack traces point to the next instruction after
528
 			// Addresses from stack traces point to the next instruction after
529
-			// each call.  Adjust by -1 to land somewhere on the actual call.
529
+			// each call. Adjust by -1 to land somewhere on the actual call.
530
 			addr--
530
 			addr--
531
 			loc := locs[addr]
531
 			loc := locs[addr]
532
 			if locs[addr] == nil {
532
 			if locs[addr] == nil {
542
 		p.Sample = append(p.Sample, &Sample{
542
 		p.Sample = append(p.Sample, &Sample{
543
 			Value:    value,
543
 			Value:    value,
544
 			Location: sloc,
544
 			Location: sloc,
545
-			NumLabel: map[string][]int64{"bytes": []int64{blocksize}},
545
+			NumLabel: map[string][]int64{"bytes": {blocksize}},
546
 		})
546
 		})
547
 	}
547
 	}
548
 
548
 
559
 	}
559
 	}
560
 
560
 
561
 	if len(header[6]) > 0 {
561
 	if len(header[6]) > 0 {
562
-		if period, err = strconv.ParseInt(string(header[6]), 10, 64); err != nil {
562
+		if period, err = strconv.ParseInt(header[6], 10, 64); err != nil {
563
 			return "", 0, false, errUnrecognized
563
 			return "", 0, false, errUnrecognized
564
 		}
564
 		}
565
 	}
565
 	}
765
 		var sloc []*Location
765
 		var sloc []*Location
766
 		for _, addr := range addrs {
766
 		for _, addr := range addrs {
767
 			// Addresses from stack traces point to the next instruction after
767
 			// Addresses from stack traces point to the next instruction after
768
-			// each call.  Adjust by -1 to land somewhere on the actual call.
768
+			// each call. Adjust by -1 to land somewhere on the actual call.
769
 			addr--
769
 			addr--
770
 			loc := locs[addr]
770
 			loc := locs[addr]
771
 			if locs[addr] == nil {
771
 			if locs[addr] == nil {
905
 		var sloc []*Location
905
 		var sloc []*Location
906
 		for i, addr := range addrs {
906
 		for i, addr := range addrs {
907
 			// Addresses from stack traces point to the next instruction after
907
 			// Addresses from stack traces point to the next instruction after
908
-			// each call.  Adjust by -1 to land somewhere on the actual call
908
+			// each call. Adjust by -1 to land somewhere on the actual call
909
 			// (except for the leaf, which is not a call).
909
 			// (except for the leaf, which is not a call).
910
 			if i > 0 {
910
 			if i > 0 {
911
 				addr--
911
 				addr--

+ 1
- 1
profile/merge.go View File

61
 
61
 
62
 		if len(pm.mappings) == 0 && len(src.Mapping) > 0 {
62
 		if len(pm.mappings) == 0 && len(src.Mapping) > 0 {
63
 			// The Mapping list has the property that the first mapping
63
 			// The Mapping list has the property that the first mapping
64
-			// represents the main binary.  Take the first Mapping we see,
64
+			// represents the main binary. Take the first Mapping we see,
65
 			// otherwise the operations below will add mappings in an
65
 			// otherwise the operations below will add mappings in an
66
 			// arbitrary order.
66
 			// arbitrary order.
67
 			pm.mapMapping(srcs[0].Mapping[0])
67
 			pm.mapMapping(srcs[0].Mapping[0])

+ 2
- 2
profile/profile.go View File

128
 	filenameX   int64
128
 	filenameX   int64
129
 }
129
 }
130
 
130
 
131
-// Parse parses a profile and checks for its validity.  The input
131
+// Parse parses a profile and checks for its validity. The input
132
 // may be a gzip-compressed encoded protobuf or one of many legacy
132
 // may be a gzip-compressed encoded protobuf or one of many legacy
133
 // profile formats which may be unsupported in the future.
133
 // profile formats which may be unsupported in the future.
134
 func Parse(r io.Reader) (*Profile, error) {
134
 func Parse(r io.Reader) (*Profile, error) {
280
 	return err
280
 	return err
281
 }
281
 }
282
 
282
 
283
-// CheckValid tests whether the profile is valid.  Checks include, but are
283
+// CheckValid tests whether the profile is valid. Checks include, but are
284
 // not limited to:
284
 // not limited to:
285
 //   - len(Profile.Sample[n].value) == len(Profile.value_unit)
285
 //   - len(Profile.Sample[n].value) == len(Profile.value_unit)
286
 //   - Sample.id has a corresponding Profile.Location
286
 //   - Sample.id has a corresponding Profile.Location

+ 26
- 26
profile/profile_test.go View File

91
 }
91
 }
92
 
92
 
93
 // leaveTempfile leaves |b| in a temporary file on disk and returns the
93
 // leaveTempfile leaves |b| in a temporary file on disk and returns the
94
-// temp filename.  This is useful to recover a profile when the test
94
+// temp filename. This is useful to recover a profile when the test
95
 // fails.
95
 // fails.
96
 func leaveTempfile(b []byte) string {
96
 func leaveTempfile(b []byte) string {
97
 	f1, err := ioutil.TempFile("", "profile_test")
97
 	f1, err := ioutil.TempFile("", "profile_test")
508
 }
508
 }
509
 
509
 
510
 func TestTagFilter(t *testing.T) {
510
 func TestTagFilter(t *testing.T) {
511
-     // Perform several forms of tag filtering on the test profile.
511
+	// Perform several forms of tag filtering on the test profile.
512
 
512
 
513
 	type filterTestcase struct {
513
 	type filterTestcase struct {
514
 		include, exclude *regexp.Regexp
514
 		include, exclude *regexp.Regexp
515
-		im, em bool
516
-		count int
517
-	}
518
-
519
-	countTags := func (p *Profile) map[string]bool {
520
-		  tags := make(map[string]bool)
521
-
522
-		  for _, s := range p.Sample {
523
-		      for l := range s.Label {
524
-		      	  tags[l] = true
525
-		      }		      
526
-		      for l := range s.NumLabel {
527
-		      	  tags[l] = true
528
-		      }		      
529
-		  }
530
-		  return tags
531
-	}	
532
-	
515
+		im, em           bool
516
+		count            int
517
+	}
518
+
519
+	countTags := func(p *Profile) map[string]bool {
520
+		tags := make(map[string]bool)
521
+
522
+		for _, s := range p.Sample {
523
+			for l := range s.Label {
524
+				tags[l] = true
525
+			}
526
+			for l := range s.NumLabel {
527
+				tags[l] = true
528
+			}
529
+		}
530
+		return tags
531
+	}
532
+
533
 	for tx, tc := range []filterTestcase{
533
 	for tx, tc := range []filterTestcase{
534
 		{nil, nil, true, false, 3},
534
 		{nil, nil, true, false, 3},
535
 		{regexp.MustCompile("notfound"), nil, false, false, 0},
535
 		{regexp.MustCompile("notfound"), nil, false, false, 0},
538
 	} {
538
 	} {
539
 		prof := testProfile.Copy()
539
 		prof := testProfile.Copy()
540
 		gim, gem := prof.FilterTagsByName(tc.include, tc.exclude)
540
 		gim, gem := prof.FilterTagsByName(tc.include, tc.exclude)
541
-		if  gim != tc.im {
541
+		if gim != tc.im {
542
 			t.Errorf("Filter #%d, got include match=%v, want %v", tx, gim, tc.im)
542
 			t.Errorf("Filter #%d, got include match=%v, want %v", tx, gim, tc.im)
543
-		}		
544
-		if  gem != tc.em {
543
+		}
544
+		if gem != tc.em {
545
 			t.Errorf("Filter #%d, got exclude match=%v, want %v", tx, gem, tc.em)
545
 			t.Errorf("Filter #%d, got exclude match=%v, want %v", tx, gem, tc.em)
546
-		}		
547
-		if  tags := countTags(prof) ; len(tags) != tc.count {
546
+		}
547
+		if tags := countTags(prof); len(tags) != tc.count {
548
 			t.Errorf("Filter #%d, got %d tags[%v], want %d", tx, len(tags), tags, tc.count)
548
 			t.Errorf("Filter #%d, got %d tags[%v], want %d", tx, len(tags), tags, tc.count)
549
-		}		
549
+		}
550
 	}
550
 	}
551
 }
551
 }
552
 
552
 

+ 1
- 1
profile/prune.go View File

23
 )
23
 )
24
 
24
 
25
 // Prune removes all nodes beneath a node matching dropRx, and not
25
 // Prune removes all nodes beneath a node matching dropRx, and not
26
-// matching keepRx.  If the root node of a Sample matches, the sample
26
+// matching keepRx. If the root node of a Sample matches, the sample
27
 // will have an empty stack.
27
 // will have an empty stack.
28
 func (p *Profile) Prune(dropRx, keepRx *regexp.Regexp) {
28
 func (p *Profile) Prune(dropRx, keepRx *regexp.Regexp) {
29
 	prune := make(map[uint64]bool)
29
 	prune := make(map[uint64]bool)