Source File
encode.go
Belonging Package
github.com/google/pprof/profile
package profile
import (
)
func ( *Profile) () []decoder {
return profileDecoder
}
func ( *Profile) () {
:= make(map[string]int)
addString(, "")
for , := range .SampleType {
.typeX = addString(, .Type)
.unitX = addString(, .Unit)
}
for , := range .Sample {
.labelX = nil
var []string
for := range .Label {
= append(, )
}
sort.Strings()
for , := range {
:= .Label[]
for , := range {
.labelX = append(.labelX,
label{
keyX: addString(, ),
strX: addString(, ),
},
)
}
}
var []string
for := range .NumLabel {
= append(, )
}
sort.Strings()
for , := range {
:= addString(, )
:= .NumLabel[]
:= .NumUnit[]
for , := range {
var int64
if len() != 0 {
= addString(, [])
}
.labelX = append(.labelX,
label{
keyX: ,
numX: ,
unitX: ,
},
)
}
}
.locationIDX = make([]uint64, len(.Location))
for , := range .Location {
.locationIDX[] = .ID
}
}
for , := range .Mapping {
.fileX = addString(, .File)
.buildIDX = addString(, .BuildID)
}
for , := range .Location {
for , := range .Line {
if .Function != nil {
.Line[].functionIDX = .Function.ID
} else {
.Line[].functionIDX = 0
}
}
if .Mapping != nil {
.mappingIDX = .Mapping.ID
} else {
.mappingIDX = 0
}
}
for , := range .Function {
.nameX = addString(, .Name)
.systemNameX = addString(, .SystemName)
.filenameX = addString(, .Filename)
}
.dropFramesX = addString(, .DropFrames)
.keepFramesX = addString(, .KeepFrames)
if := .PeriodType; != nil {
.typeX = addString(, .Type)
.unitX = addString(, .Unit)
}
.commentX = nil
for , := range .Comments {
.commentX = append(.commentX, addString(, ))
}
.defaultSampleTypeX = addString(, .DefaultSampleType)
.stringTable = make([]string, len())
for , := range {
.stringTable[] =
}
}
func ( *Profile) ( *buffer) {
for , := range .SampleType {
encodeMessage(, 1, )
}
for , := range .Sample {
encodeMessage(, 2, )
}
for , := range .Mapping {
encodeMessage(, 3, )
}
for , := range .Location {
encodeMessage(, 4, )
}
for , := range .Function {
encodeMessage(, 5, )
}
encodeStrings(, 6, .stringTable)
encodeInt64Opt(, 7, .dropFramesX)
encodeInt64Opt(, 8, .keepFramesX)
encodeInt64Opt(, 9, .TimeNanos)
encodeInt64Opt(, 10, .DurationNanos)
if := .PeriodType; != nil && (.typeX != 0 || .unitX != 0) {
encodeMessage(, 11, .PeriodType)
}
encodeInt64Opt(, 12, .Period)
encodeInt64s(, 13, .commentX)
encodeInt64(, 14, .defaultSampleTypeX)
}
var profileDecoder = []decoder{
func( *buffer, message) error {
:= new(ValueType)
:= .(*Profile)
.SampleType = append(.SampleType, )
return decodeMessage(, )
func( *buffer, message) error {
:= decodeStrings(, &.(*Profile).stringTable)
if != nil {
return
}
if .(*Profile).stringTable[0] != "" {
return errors.New("string_table[0] must be ''")
}
return nil
func( *buffer, message) error {
if .(*Profile).TimeNanos != 0 {
return errConcatProfile
}
return decodeInt64(, &.(*Profile).TimeNanos)
func( *buffer, message) error {
:= new(ValueType)
:= .(*Profile)
.PeriodType =
return decodeMessage(, )
func( *buffer, message) error { return decodeInt64(, &.(*Profile).defaultSampleTypeX) },
}
func ( *Profile) () error {
var error
:= make(map[uint64]*Mapping, len(.Mapping))
:= make([]*Mapping, len(.Mapping)+1)
for , := range .Mapping {
.File, = getString(.stringTable, &.fileX, )
.BuildID, = getString(.stringTable, &.buildIDX, )
if .ID < uint64(len()) {
[.ID] =
} else {
[.ID] =
}
}
:= make(map[uint64]*Function, len(.Function))
:= make([]*Function, len(.Function)+1)
for , := range .Function {
.Name, = getString(.stringTable, &.nameX, )
.SystemName, = getString(.stringTable, &.systemNameX, )
.Filename, = getString(.stringTable, &.filenameX, )
if .ID < uint64(len()) {
[.ID] =
} else {
[.ID] =
}
}
:= make(map[uint64]*Location, len(.Location))
:= make([]*Location, len(.Location)+1)
for , := range .Location {
if := .mappingIDX; < uint64(len()) {
.Mapping = []
} else {
.Mapping = []
}
.mappingIDX = 0
for , := range .Line {
if := .functionIDX; != 0 {
.Line[].functionIDX = 0
if < uint64(len()) {
.Line[].Function = []
} else {
.Line[].Function = []
}
}
}
if .ID < uint64(len()) {
[.ID] =
} else {
[.ID] =
}
}
for , := range .SampleType {
.Type, = getString(.stringTable, &.typeX, )
.Unit, = getString(.stringTable, &.unitX, )
}
for , := range .Sample {
:= make(map[string][]string, len(.labelX))
:= make(map[string][]int64, len(.labelX))
:= make(map[string][]string, len(.labelX))
for , := range .labelX {
var , string
, = getString(.stringTable, &.keyX, )
if .strX != 0 {
, = getString(.stringTable, &.strX, )
[] = append([], )
} else if .numX != 0 {
:= []
:= []
if .unitX != 0 {
var string
, = getString(.stringTable, &.unitX, )
= padStringArray(, len())
[] = append(, )
}
[] = append([], .numX)
}
}
if len() > 0 {
.Label =
}
if len() > 0 {
.NumLabel =
for , := range {
if len() > 0 {
[] = padStringArray(, len([]))
}
}
.NumUnit =
}
.Location = make([]*Location, len(.locationIDX))
for , := range .locationIDX {
if < uint64(len()) {
.Location[] = []
} else {
.Location[] = []
}
}
.locationIDX = nil
}
.DropFrames, = getString(.stringTable, &.dropFramesX, )
.KeepFrames, = getString(.stringTable, &.keepFramesX, )
if := .PeriodType; == nil {
.PeriodType = &ValueType{}
}
if := .PeriodType; != nil {
.Type, = getString(.stringTable, &.typeX, )
.Unit, = getString(.stringTable, &.unitX, )
}
for , := range .commentX {
var string
, = getString(.stringTable, &, )
.Comments = append(.Comments, )
}
.commentX = nil
.DefaultSampleType, = getString(.stringTable, &.defaultSampleTypeX, )
.stringTable = nil
return
}
func ( []string, int) []string {
if <= len() {
return
}
return append(, make([]string, -len())...)
}
func ( *ValueType) () []decoder {
return valueTypeDecoder
}
func ( *ValueType) ( *buffer) {
encodeInt64Opt(, 1, .typeX)
encodeInt64Opt(, 2, .unitX)
}
var valueTypeDecoder = []decoder{
func( *buffer, message) error { return decodeInt64(, &.(*ValueType).unitX) },
}
func ( *Sample) () []decoder {
return sampleDecoder
}
func ( *Sample) ( *buffer) {
encodeUint64s(, 1, .locationIDX)
encodeInt64s(, 2, .Value)
for , := range .labelX {
encodeMessage(, 3, )
}
}
var sampleDecoder = []decoder{
func( *buffer, message) error {
:= .(*Sample)
:= len(.labelX)
.labelX = append(.labelX, label{})
return decodeMessage(, &.labelX[])
},
}
func ( label) () []decoder {
return labelDecoder
}
func ( label) ( *buffer) {
encodeInt64Opt(, 1, .keyX)
encodeInt64Opt(, 2, .strX)
encodeInt64Opt(, 3, .numX)
encodeInt64Opt(, 4, .unitX)
}
var labelDecoder = []decoder{
func( *buffer, message) error { return decodeInt64(, &.(*label).unitX) },
}
func ( *Mapping) () []decoder {
return mappingDecoder
}
func ( *Mapping) ( *buffer) {
encodeUint64Opt(, 1, .ID)
encodeUint64Opt(, 2, .Start)
encodeUint64Opt(, 3, .Limit)
encodeUint64Opt(, 4, .Offset)
encodeInt64Opt(, 5, .fileX)
encodeInt64Opt(, 6, .buildIDX)
encodeBoolOpt(, 7, .HasFunctions)
encodeBoolOpt(, 8, .HasFilenames)
encodeBoolOpt(, 9, .HasLineNumbers)
encodeBoolOpt(, 10, .HasInlineFrames)
}
var mappingDecoder = []decoder{
nil, // 0
func( *buffer, message) error { return decodeUint64(, &.(*Mapping).ID) }, // optional uint64 id = 1
func( *buffer, message) error { return decodeUint64(, &.(*Mapping).Start) }, // optional uint64 memory_offset = 2
func( *buffer, message) error { return decodeUint64(, &.(*Mapping).Limit) }, // optional uint64 memory_limit = 3
func( *buffer, message) error { return decodeUint64(, &.(*Mapping).Offset) }, // optional uint64 file_offset = 4
func( *buffer, message) error { return decodeInt64(, &.(*Mapping).fileX) }, // optional int64 filename = 5
func( *buffer, message) error { return decodeInt64(, &.(*Mapping).buildIDX) }, // optional int64 build_id = 6
func( *buffer, message) error { return decodeBool(, &.(*Mapping).HasFunctions) }, // optional bool has_functions = 7
func( *buffer, message) error { return decodeBool(, &.(*Mapping).HasFilenames) }, // optional bool has_filenames = 8
func( *buffer, message) error { return decodeBool(, &.(*Mapping).HasLineNumbers) }, // optional bool has_line_numbers = 9
func( *buffer, message) error { return decodeBool(, &.(*Mapping).HasInlineFrames) }, // optional bool has_inline_frames = 10
}
func ( *Location) () []decoder {
return locationDecoder
}
func ( *Location) ( *buffer) {
encodeUint64Opt(, 1, .ID)
encodeUint64Opt(, 2, .mappingIDX)
encodeUint64Opt(, 3, .Address)
for := range .Line {
encodeMessage(, 4, &.Line[])
}
encodeBoolOpt(, 5, .IsFolded)
}
var locationDecoder = []decoder{
nil, // 0
func( *buffer, message) error { return decodeUint64(, &.(*Location).ID) }, // optional uint64 id = 1;
func( *buffer, message) error { return decodeUint64(, &.(*Location).mappingIDX) }, // optional uint64 mapping_id = 2;
func( *buffer, message) error { return decodeUint64(, &.(*Location).Address) }, // optional uint64 address = 3;
func( *buffer, message) error { // repeated Line line = 4
:= .(*Location)
:= len(.Line)
.Line = append(.Line, Line{})
return decodeMessage(, &.Line[])
},
func( *buffer, message) error { return decodeBool(, &.(*Location).IsFolded) }, // optional bool is_folded = 5;
}
func ( *Line) () []decoder {
return lineDecoder
}
func ( *Line) ( *buffer) {
encodeUint64Opt(, 1, .functionIDX)
encodeInt64Opt(, 2, .Line)
}
var lineDecoder = []decoder{
func( *buffer, message) error { return decodeInt64(, &.(*Line).Line) },
}
func ( *Function) () []decoder {
return functionDecoder
}
func ( *Function) ( *buffer) {
encodeUint64Opt(, 1, .ID)
encodeInt64Opt(, 2, .nameX)
encodeInt64Opt(, 3, .systemNameX)
encodeInt64Opt(, 4, .filenameX)
encodeInt64Opt(, 5, .StartLine)
}
var functionDecoder = []decoder{
func( *buffer, message) error { return decodeInt64(, &.(*Function).StartLine) },
}
func ( map[string]int, string) int64 {
, := []
if ! {
= len()
[] =
}
return int64()
}
func ( []string, *int64, error) (string, error) {
if != nil {
return "",
}
:= int(*)
if < 0 || >= len() {
return "", errMalformed
}
* = 0
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. |