parseContention parses a mutex or contention profile. There are 2 cases: "--- contentionz " for legacy C++ profiles (and backwards compatibility) "--- mutex:" or "--- contention:" for profiles generated by the Go runtime.
(b []byte)
| 681 | // "--- contentionz " for legacy C++ profiles (and backwards compatibility) |
| 682 | // "--- mutex:" or "--- contention:" for profiles generated by the Go runtime. |
| 683 | func parseContention(b []byte) (*Profile, error) { |
| 684 | s := bufio.NewScanner(bytes.NewBuffer(b)) |
| 685 | if !s.Scan() { |
| 686 | if err := s.Err(); err != nil { |
| 687 | return nil, err |
| 688 | } |
| 689 | return nil, errUnrecognized |
| 690 | } |
| 691 | |
| 692 | switch l := s.Text(); { |
| 693 | case strings.HasPrefix(l, "--- contentionz "): |
| 694 | case strings.HasPrefix(l, "--- mutex:"): |
| 695 | case strings.HasPrefix(l, "--- contention:"): |
| 696 | default: |
| 697 | return nil, errUnrecognized |
| 698 | } |
| 699 | |
| 700 | p := &Profile{ |
| 701 | PeriodType: &ValueType{Type: "contentions", Unit: "count"}, |
| 702 | Period: 1, |
| 703 | SampleType: []*ValueType{ |
| 704 | {Type: "contentions", Unit: "count"}, |
| 705 | {Type: "delay", Unit: "nanoseconds"}, |
| 706 | }, |
| 707 | } |
| 708 | |
| 709 | var cpuHz int64 |
| 710 | // Parse text of the form "attribute = value" before the samples. |
| 711 | const delimiter = "=" |
| 712 | for s.Scan() { |
| 713 | line := s.Text() |
| 714 | if line = strings.TrimSpace(line); isSpaceOrComment(line) { |
| 715 | continue |
| 716 | } |
| 717 | if strings.HasPrefix(line, "---") { |
| 718 | break |
| 719 | } |
| 720 | attr := strings.SplitN(line, delimiter, 2) |
| 721 | if len(attr) != 2 { |
| 722 | break |
| 723 | } |
| 724 | key, val := strings.TrimSpace(attr[0]), strings.TrimSpace(attr[1]) |
| 725 | var err error |
| 726 | switch key { |
| 727 | case "cycles/second": |
| 728 | if cpuHz, err = strconv.ParseInt(val, 0, 64); err != nil { |
| 729 | return nil, errUnrecognized |
| 730 | } |
| 731 | case "sampling period": |
| 732 | if p.Period, err = strconv.ParseInt(val, 0, 64); err != nil { |
| 733 | return nil, errUnrecognized |
| 734 | } |
| 735 | case "ms since reset": |
| 736 | ms, err := strconv.ParseInt(val, 0, 64) |
| 737 | if err != nil { |
| 738 | return nil, errUnrecognized |
| 739 | } |
| 740 | p.DurationNanos = ms * 1000 * 1000 |
nothing calls this directly
no test coverage detected
searching dependent graphs…