浏览代码

Merge pull request #82 from rauls5382/mutex

Add support for golang legacy mutex profiles
Alexey Alexandrov 8 年前
父节点
当前提交
48033981f8
共有 1 个文件被更改,包括 11 次插入7 次删除
  1. 11
    7
      profile/legacy_profile.go

+ 11
- 7
profile/legacy_profile.go 查看文件

676
 	return int64(float64(count) * scale), int64(float64(size) * scale)
676
 	return int64(float64(count) * scale), int64(float64(size) * scale)
677
 }
677
 }
678
 
678
 
679
-// parseContention parses a contentionz profile and returns a newly
680
-// populated Profile.
681
-func parseContention(b []byte) (p *Profile, err error) {
679
+// parseContention parses a mutex or contention profile. There are 2 cases:
680
+// "--- contentionz " for legacy C++ profiles (and backwards compatibility)
681
+// "--- mutex:" or "--- contention:" for profiles generated by the Go runtime.
682
+func parseContention(b []byte) (*Profile, error) {
682
 	s := bufio.NewScanner(bytes.NewBuffer(b))
683
 	s := bufio.NewScanner(bytes.NewBuffer(b))
683
 	if !s.Scan() {
684
 	if !s.Scan() {
684
 		if err := s.Err(); err != nil {
685
 		if err := s.Err(); err != nil {
686
 		}
687
 		}
687
 		return nil, errUnrecognized
688
 		return nil, errUnrecognized
688
 	}
689
 	}
689
-	line := s.Text()
690
 
690
 
691
-	if !strings.HasPrefix(line, "--- contention") {
691
+	switch l := s.Text(); {
692
+	case strings.HasPrefix(l, "--- contentionz "):
693
+	case strings.HasPrefix(l, "--- mutex:"):
694
+	case strings.HasPrefix(l, "--- contention:"):
695
+	default:
692
 		return nil, errUnrecognized
696
 		return nil, errUnrecognized
693
 	}
697
 	}
694
 
698
 
695
-	p = &Profile{
699
+	p := &Profile{
696
 		PeriodType: &ValueType{Type: "contentions", Unit: "count"},
700
 		PeriodType: &ValueType{Type: "contentions", Unit: "count"},
697
 		Period:     1,
701
 		Period:     1,
698
 		SampleType: []*ValueType{
702
 		SampleType: []*ValueType{
789
 		return nil, err
793
 		return nil, err
790
 	}
794
 	}
791
 
795
 
792
-	if err = parseAdditionalSections(s, p); err != nil {
796
+	if err := parseAdditionalSections(s, p); err != nil {
793
 		return nil, err
797
 		return nil, err
794
 	}
798
 	}
795
 
799