Source File
legacy_java_profile.go
Belonging Package
github.com/google/pprof/profile
package profile
import (
)
var (
attributeRx = regexp.MustCompile(`([\w ]+)=([\w ]+)`)
javaSampleRx = regexp.MustCompile(` *(\d+) +(\d+) +@ +([ x0-9a-f]*)`)
javaLocationRx = regexp.MustCompile(`^\s*0x([[:xdigit:]]+)\s+(.*)\s*$`)
javaLocationFileLineRx = regexp.MustCompile(`^(.*)\s+\((.+):(-?[[:digit:]]+)\)$`)
javaLocationPathRx = regexp.MustCompile(`^(.*)\s+\((.*)\)$`)
)
func ( []byte, int64, func( []byte) (uint64, []byte)) (*Profile, error) {
:= &Profile{
Period: * 1000,
PeriodType: &ValueType{Type: "cpu", Unit: "nanoseconds"},
SampleType: []*ValueType{{Type: "samples", Unit: "count"}, {Type: "cpu", Unit: "nanoseconds"}},
}
var error
var map[uint64]*Location
if , , = parseCPUSamples(, , false, ); != nil {
return nil,
}
if = parseJavaLocations(, , ); != nil {
return nil,
}
func ( []byte) (*Profile, error) {
:= bytes.SplitAfterN(, []byte("\n"), 2)
if len() < 2 {
return nil, errUnrecognized
}
:= &Profile{
PeriodType: &ValueType{},
}
:= string(bytes.TrimSpace([0]))
var error
var string
switch {
case "--- heapz 1 ---":
= "heap"
case "--- contentionz 1 ---":
= "contention"
default:
return nil, errUnrecognized
}
if , = parseJavaHeader(, [1], ); != nil {
return nil,
}
var map[uint64]*Location
if , , = parseJavaSamples(, , ); != nil {
return nil,
}
if = parseJavaLocations(, , ); != nil {
return nil,
}
return , nil
}
, := strings.TrimSpace([1]), strings.TrimSpace([2])
var error
switch + "/" + {
case "heap/format", "cpu/format", "contention/format":
if != "java" {
return nil, errUnrecognized
}
case "heap/resolution":
.SampleType = []*ValueType{
{Type: "inuse_objects", Unit: "count"},
{Type: "inuse_space", Unit: },
}
case "contention/resolution":
.SampleType = []*ValueType{
{Type: "contentions", Unit: "count"},
{Type: "delay", Unit: },
}
case "contention/sampling period":
.PeriodType = &ValueType{
Type: "contentions", Unit: "count",
}
if .Period, = strconv.ParseInt(, 0, 64); != nil {
return nil, fmt.Errorf("failed to parse attribute %s: %v", , )
}
case "contention/ms since reset":
, := strconv.ParseInt(, 0, 64)
if != nil {
return nil, fmt.Errorf("failed to parse attribute %s: %v", , )
}
.DurationNanos = * 1000 * 1000
default:
return nil, errUnrecognized
}
return , , nil
}
var error
, , := [2], [1], [3]
, := parseHexAddresses()
if != nil {
return nil, nil, fmt.Errorf("malformed sample: %s: %v", , )
}
var []*Location
for , := range {
:= []
if [] == nil {
= &Location{
Address: ,
}
.Location = append(.Location, )
[] =
}
= append(, )
}
:= &Sample{
Value: make([]int64, 2),
Location: ,
}
if .Value[0], = strconv.ParseInt(, 0, 64); != nil {
return nil, nil, fmt.Errorf("parsing sample %s: %v", , )
}
if .Value[1], = strconv.ParseInt(, 0, 64); != nil {
return nil, nil, fmt.Errorf("parsing sample %s: %v", , )
}
switch {
case "heap":
const = 524288 // 512K
if .Value[0] == 0 {
return nil, nil, fmt.Errorf("parsing sample %s: second value must be non-zero", )
}
.NumLabel = map[string][]int64{"bytes": {.Value[1] / .Value[0]}}
.Value[0], .Value[1] = scaleHeapSample(.Value[0], .Value[1], )
case "contention":
if := .Period; != 0 {
.Value[0] = .Value[0] * .Period
.Value[1] = .Value[1] * .Period
}
}
.Sample = append(.Sample, )
func ( []byte, map[uint64]*Location, *Profile) error {
:= bytes.NewBuffer()
:= make(map[string]*Function)
for {
, := .ReadString('\n')
if != nil {
if != io.EOF {
return
}
if == "" {
break
}
}
if = strings.TrimSpace(); == "" {
continue
}
:= javaLocationRx.FindStringSubmatch()
if len() != 3 {
continue
}
, := strconv.ParseUint([1], 16, 64)
if != nil {
return fmt.Errorf("parsing sample %s: %v", , )
}
:= []
= [2]
}
:= []
if == nil {
= &Function{
Name: ,
SystemName: ,
Filename: ,
}
[] =
.Function = append(.Function, )
}
.Line = []Line{
{
Function: ,
Line: ,
},
}
.Address = 0
}
.remapLocationIDs()
.remapFunctionIDs()
.remapMappingIDs()
return nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |