parseContentionSample parses a single row from a contention profile into a new Sample.
(line string, period, cpuHz int64)
| 802 | // parseContentionSample parses a single row from a contention profile |
| 803 | // into a new Sample. |
| 804 | func parseContentionSample(line string, period, cpuHz int64) (value []int64, addrs []uint64, err error) { |
| 805 | sampleData := contentionSampleRE.FindStringSubmatch(line) |
| 806 | if sampleData == nil { |
| 807 | return nil, nil, errUnrecognized |
| 808 | } |
| 809 | |
| 810 | v1, err := strconv.ParseInt(sampleData[1], 10, 64) |
| 811 | if err != nil { |
| 812 | return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err) |
| 813 | } |
| 814 | v2, err := strconv.ParseInt(sampleData[2], 10, 64) |
| 815 | if err != nil { |
| 816 | return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err) |
| 817 | } |
| 818 | |
| 819 | // Unsample values if period and cpuHz are available. |
| 820 | // - Delays are scaled to cycles and then to nanoseconds. |
| 821 | // - Contentions are scaled to cycles. |
| 822 | if period > 0 { |
| 823 | if cpuHz > 0 { |
| 824 | cpuGHz := float64(cpuHz) / 1e9 |
| 825 | v1 = int64(float64(v1) * float64(period) / cpuGHz) |
| 826 | } |
| 827 | v2 = v2 * period |
| 828 | } |
| 829 | |
| 830 | value = []int64{v2, v1} |
| 831 | addrs, err = parseHexAddresses(sampleData[3]) |
| 832 | if err != nil { |
| 833 | return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err) |
| 834 | } |
| 835 | |
| 836 | return value, addrs, nil |
| 837 | } |
| 838 | |
| 839 | // parseThread parses a Threadz profile and returns a new Profile. |
| 840 | func parseThread(b []byte) (*Profile, error) { |
no test coverage detected
searching dependent graphs…