parseJavaHeader parses the attribute section on a java profile and populates a profile. Returns the remainder of the buffer after all attributes.
(pType string, b []byte, p *Profile)
| 110 | // populates a profile. Returns the remainder of the buffer after all |
| 111 | // attributes. |
| 112 | func parseJavaHeader(pType string, b []byte, p *Profile) ([]byte, error) { |
| 113 | nextNewLine := bytes.IndexByte(b, byte('\n')) |
| 114 | for nextNewLine != -1 { |
| 115 | line := string(bytes.TrimSpace(b[0:nextNewLine])) |
| 116 | if line != "" { |
| 117 | h := attributeRx.FindStringSubmatch(line) |
| 118 | if h == nil { |
| 119 | // Not a valid attribute, exit. |
| 120 | return b, nil |
| 121 | } |
| 122 | |
| 123 | attribute, value := strings.TrimSpace(h[1]), strings.TrimSpace(h[2]) |
| 124 | var err error |
| 125 | switch pType + "/" + attribute { |
| 126 | case "heap/format", "cpu/format", "contention/format": |
| 127 | if value != "java" { |
| 128 | return nil, errUnrecognized |
| 129 | } |
| 130 | case "heap/resolution": |
| 131 | p.SampleType = []*ValueType{ |
| 132 | {Type: "inuse_objects", Unit: "count"}, |
| 133 | {Type: "inuse_space", Unit: value}, |
| 134 | } |
| 135 | case "contention/resolution": |
| 136 | p.SampleType = []*ValueType{ |
| 137 | {Type: "contentions", Unit: "count"}, |
| 138 | {Type: "delay", Unit: value}, |
| 139 | } |
| 140 | case "contention/sampling period": |
| 141 | p.PeriodType = &ValueType{ |
| 142 | Type: "contentions", Unit: "count", |
| 143 | } |
| 144 | if p.Period, err = strconv.ParseInt(value, 0, 64); err != nil { |
| 145 | return nil, fmt.Errorf("failed to parse attribute %s: %v", line, err) |
| 146 | } |
| 147 | case "contention/ms since reset": |
| 148 | millis, err := strconv.ParseInt(value, 0, 64) |
| 149 | if err != nil { |
| 150 | return nil, fmt.Errorf("failed to parse attribute %s: %v", line, err) |
| 151 | } |
| 152 | p.DurationNanos = millis * 1000 * 1000 |
| 153 | default: |
| 154 | return nil, errUnrecognized |
| 155 | } |
| 156 | } |
| 157 | // Grab next line. |
| 158 | b = b[nextNewLine+1:] |
| 159 | nextNewLine = bytes.IndexByte(b, byte('\n')) |
| 160 | } |
| 161 | return b, nil |
| 162 | } |
| 163 | |
| 164 | // parseJavaSamples parses the samples from a java profile and |
| 165 | // populates the Samples in a profile. Returns the remainder of the |
no outgoing calls
no test coverage detected
searching dependent graphs…