|
@@ -622,32 +622,29 @@ func parseHeapSample(line string, rate int64, sampling string, includeAlloc bool
|
622
|
622
|
return nil, 0, nil, err
|
623
|
623
|
}
|
624
|
624
|
|
625
|
|
- addrs = parseHexAddresses(sampleData[5])
|
|
625
|
+ addrs, err = parseHexAddresses(sampleData[5])
|
|
626
|
+ if err != nil {
|
|
627
|
+ return nil, 0, nil, fmt.Errorf("malformed sample: %s: %v", line, err)
|
|
628
|
+ }
|
626
|
629
|
|
627
|
630
|
return value, blocksize, addrs, nil
|
628
|
631
|
}
|
629
|
632
|
|
630
|
|
-// extractHexAddresses extracts hex numbers from a string and returns
|
631
|
|
-// them, together with their numeric value, in a slice.
|
632
|
|
-func extractHexAddresses(s string) ([]string, []uint64) {
|
|
633
|
+// parseHexAddresses extracts hex numbers from a string, attempts to convert
|
|
634
|
+// each to an unsigned 64-bit number and returns the resulting numbers as a
|
|
635
|
+// slice, or an error if the string contains hex numbers which are too large to
|
|
636
|
+// handle (which means a malformed profile).
|
|
637
|
+func parseHexAddresses(s string) ([]uint64, error) {
|
633
|
638
|
hexStrings := hexNumberRE.FindAllString(s, -1)
|
634
|
|
- var ids []uint64
|
|
639
|
+ var addrs []uint64
|
635
|
640
|
for _, s := range hexStrings {
|
636
|
|
- if id, err := strconv.ParseUint(s, 0, 64); err == nil {
|
637
|
|
- ids = append(ids, id)
|
|
641
|
+ if addr, err := strconv.ParseUint(s, 0, 64); err == nil {
|
|
642
|
+ addrs = append(addrs, addr)
|
638
|
643
|
} else {
|
639
|
|
- // Do not expect any parsing failures due to the regexp matching.
|
640
|
|
- panic("failed to parse hex value:" + s)
|
|
644
|
+ return nil, fmt.Errorf("failed to parse as hex 64-bit number: %s", s)
|
641
|
645
|
}
|
642
|
646
|
}
|
643
|
|
- return hexStrings, ids
|
644
|
|
-}
|
645
|
|
-
|
646
|
|
-// parseHexAddresses parses hex numbers from a string and returns them
|
647
|
|
-// in a slice.
|
648
|
|
-func parseHexAddresses(s string) []uint64 {
|
649
|
|
- _, ids := extractHexAddresses(s)
|
650
|
|
- return ids
|
|
647
|
+ return addrs, nil
|
651
|
648
|
}
|
652
|
649
|
|
653
|
650
|
// scaleHeapSample adjusts the data from a heapz Sample to
|
|
@@ -803,16 +800,16 @@ func parseContention(b []byte) (*Profile, error) {
|
803
|
800
|
func parseContentionSample(line string, period, cpuHz int64) (value []int64, addrs []uint64, err error) {
|
804
|
801
|
sampleData := contentionSampleRE.FindStringSubmatch(line)
|
805
|
802
|
if sampleData == nil {
|
806
|
|
- return value, addrs, errUnrecognized
|
|
803
|
+ return nil, nil, errUnrecognized
|
807
|
804
|
}
|
808
|
805
|
|
809
|
806
|
v1, err := strconv.ParseInt(sampleData[1], 10, 64)
|
810
|
807
|
if err != nil {
|
811
|
|
- return value, addrs, fmt.Errorf("malformed sample: %s: %v", line, err)
|
|
808
|
+ return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err)
|
812
|
809
|
}
|
813
|
810
|
v2, err := strconv.ParseInt(sampleData[2], 10, 64)
|
814
|
811
|
if err != nil {
|
815
|
|
- return value, addrs, fmt.Errorf("malformed sample: %s: %v", line, err)
|
|
812
|
+ return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err)
|
816
|
813
|
}
|
817
|
814
|
|
818
|
815
|
// Unsample values if period and cpuHz are available.
|
|
@@ -827,7 +824,10 @@ func parseContentionSample(line string, period, cpuHz int64) (value []int64, add
|
827
|
824
|
}
|
828
|
825
|
|
829
|
826
|
value = []int64{v2, v1}
|
830
|
|
- addrs = parseHexAddresses(sampleData[3])
|
|
827
|
+ addrs, err = parseHexAddresses(sampleData[3])
|
|
828
|
+ if err != nil {
|
|
829
|
+ return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err)
|
|
830
|
+ }
|
831
|
831
|
|
832
|
832
|
return value, addrs, nil
|
833
|
833
|
}
|
|
@@ -872,7 +872,7 @@ func parseThread(b []byte) (*Profile, error) {
|
872
|
872
|
var err error
|
873
|
873
|
line, addrs, err = parseThreadSample(s)
|
874
|
874
|
if err != nil {
|
875
|
|
- return nil, errUnrecognized
|
|
875
|
+ return nil, err
|
876
|
876
|
}
|
877
|
877
|
if len(addrs) == 0 {
|
878
|
878
|
// We got a --same as previous threads--. Bump counters.
|
|
@@ -936,7 +936,11 @@ func parseThreadSample(s *bufio.Scanner) (nextl string, addrs []uint64, err erro
|
936
|
936
|
continue
|
937
|
937
|
}
|
938
|
938
|
|
939
|
|
- addrs = append(addrs, parseHexAddresses(line)...)
|
|
939
|
+ curAddrs, err := parseHexAddresses(line)
|
|
940
|
+ if err != nil {
|
|
941
|
+ return "", nil, fmt.Errorf("malformed sample: %s: %v", line, err)
|
|
942
|
+ }
|
|
943
|
+ addrs = append(addrs, curAddrs...)
|
940
|
944
|
}
|
941
|
945
|
if err := s.Err(); err != nil {
|
942
|
946
|
return "", nil, err
|