Profile is an in-memory representation of profile.proto.
Comments[]stringDefaultSampleTypestringDropFramesstringDurationNanosint64Function[]*FunctionKeepFramesstringLocation[]*LocationMapping[]*MappingPeriodint64PeriodType*ValueTypeSample[]*SampleSampleType[]*ValueTypeTimeNanosint64commentX[]int64defaultSampleTypeXint64dropFramesXint64
The following fields are modified during encoding and copying,
so are protected by a Mutex.
keepFramesXint64stringTable[]string
Aggregate merges the locations in the profile into equivalence
classes preserving the request attributes. It also updates the
samples to point to the merged locations.
CheckValid tests whether the profile is valid. Checks include, but are
not limited to:
- len(Profile.Sample[n].value) == len(Profile.value_unit)
- Sample.id has a corresponding Profile.Location
Compact performs garbage collection on a profile to remove any
unreferenced fields. This is useful to reduce the size of a profile
after samples or locations have been removed.
Copy makes a fully independent copy of a profile.
FilterSamplesByName filters the samples in a profile and only keeps
samples where at least one frame matches focus but none match ignore.
Returns true is the corresponding regexp matched at least one sample.
FilterSamplesByTag removes all samples from the profile, except
those that match focus and do not match the ignore regular
expression.
FilterTagsByName filters the tags in a profile and only keeps
tags that match show and not hide.
HasFileLines determines if all locations in this profile have
symbolized file and line number information.
HasFunctions determines if all locations in this profile have
symbolized function information.
Normalize normalizes the source profile by multiplying each value in profile by the
ratio of the sum of the base profile's values of that sample type to the sum of the
source profile's value of that sample type.
NumLabelUnits returns a map of numeric label keys to the units
associated with those keys and a map of those keys to any units
that were encountered but not used.
Unit for a given key is the first encountered unit for that key. If multiple
units are encountered for values paired with a particular key, then the first
unit encountered is used and all other units are returned in sorted order
in map of ignored units.
If no units are encountered for a particular key, the unit is then inferred
based on the key.
ParseMemoryMap parses a memory map in the format of
/proc/self/maps, and overrides the mappings in the current profile.
It renumbers the samples and locations in the profile correspondingly.
ParseMemoryMapFromScanner parses a memory map in the format of
/proc/self/maps or a variety of legacy format, and overrides the
mappings in the current profile. It renumbers the samples and
locations in the profile correspondingly.
Prune removes all nodes beneath a node matching dropRx, and not
matching keepRx. If the root node of a Sample matches, the sample
will have an empty stack.
PruneFrom removes all nodes beneath the lowest node matching dropRx, not including itself.
Please see the example below to understand this method as well as
the difference from Prune method.
A sample contains Location of [A,B,C,B,D] where D is the top frame and there's no inline.
PruneFrom(A) returns [A,B,C,B,D] because there's no node beneath A.
Prune(A, nil) returns [B,C,B,D] by removing A itself.
PruneFrom(B) returns [B,C,B,D] by removing all nodes beneath the first B when scanning from the bottom.
Prune(B, nil) returns [D] because a matching node is found by scanning from the root.
RemoveLabel removes all labels associated with the specified key for all
samples in the profile.
RemoveUninteresting prunes and elides profiles using built-in
tables of uninteresting function names.
SampleIndexByName returns the appropriate index for a value of sample index.
If numeric, it returns the number, otherwise it looks up the text in the
profile sample types.
Scale multiplies all sample values in a profile by a constant.
ScaleN multiplies each sample values in a sample by a different amount.
SetLabel sets the specified key to the specified value for all samples in the
profile.
ShowFrom drops all stack frames above the highest matching frame and returns
whether a match was found. If showFrom is nil it returns false and does not
modify the profile.
Example: consider a sample with frames [A, B, C, B], where A is the root.
ShowFrom(nil) returns false and has frames [A, B, C, B].
ShowFrom(A) returns true and has frames [A, B, C, B].
ShowFrom(B) returns true and has frames [B, C, B].
ShowFrom(C) returns true and has frames [C, B].
ShowFrom(D) returns false and drops the sample because no frames remain.
String dumps a text representation of a profile. Intended mainly
for debugging purposes.
Write writes the profile as a gzip-compressed marshaled protobuf.
WriteUncompressed writes the profile as a marshaled protobuf.
(*T) addLegacyFrameInfo()
compatible determines if two profiles can be compared/merged.
returns nil if the profiles are compatible; otherwise an error with
details on the incompatibility.
(*T) decoder() []decoder(*T) encode(b *buffer)
massageMappings applies heuristic-based changes to the profile
mappings to account for quirks of some environments.
postDecode takes the unexported fields populated by decode (with
suffix X) and populates the corresponding exported fields.
The unexported fields are cleared up to facilitate testing.
preEncode populates the unexported fields to be used by encode
(with suffix X) from the corresponding exported fields. The
exported fields are cleared up to facilitate testing.
(*T) remapFunctionIDs()
remapLocationIDs ensures there is a location for each address
referenced by a sample, and remaps the samples to point to the new
location ids.
remapMappingIDs matches location addresses with existing mappings
and updates them appropriately. This is O(N*M), if this ever shows
up as a bottleneck, evaluate sorting the mappings and doing a
binary search, which would make it O(N*log(M)).
(*T) updateLocationMapping(from, to *Mapping)
*T : expvar.Var
*T : fmt.Stringer
*T : message
*T : context.stringer
*T : runtime.stringer
func Merge(srcs []*Profile) (*Profile, error)
func Parse(r io.Reader) (*Profile, error)
func ParseData(data []byte) (*Profile, error)
func ParseUncompressed(data []byte) (*Profile, error)
func (*Profile).Compact() *Profile
func (*Profile).Copy() *Profile
func combineHeaders(srcs []*Profile) (*Profile, error)
func cpuProfile(b []byte, period int64, parse func(b []byte) (uint64, []byte)) (*Profile, error)
func javaCPUProfile(b []byte, period int64, parse func(b []byte) (uint64, []byte)) (*Profile, error)
func parseContention(b []byte) (*Profile, error)
func parseCPU(b []byte) (*Profile, error)
func parseGoCount(b []byte) (*Profile, error)
func parseHeap(b []byte) (p *Profile, err error)
func parseJavaProfile(b []byte) (*Profile, error)
func parseLegacy(data []byte) (*Profile, error)
func parseThread(b []byte) (*Profile, error)
func cloud.google.com/go/profiler.allocProfile(forceGC bool) (*Profile, error)
func cloud.google.com/go/profiler.goHeapProfile() (*Profile, error)
func cloud.google.com/go/profiler.mutexProfile() (*Profile, error)
func Merge(srcs []*Profile) (*Profile, error)
func (*Profile).Normalize(pb *Profile) error
func cleanupDuplicateLocations(p *Profile)
func combineHeaders(srcs []*Profile) (*Profile, error)
func isProfileType(p *Profile, types [][]string) bool
func parseAdditionalSections(s *bufio.Scanner, p *Profile) error
func parseCPUSamples(b []byte, parse func(b []byte) (uint64, []byte), adjust bool, p *Profile) ([]byte, map[uint64]*Location, error)
func parseJavaHeader(pType string, b []byte, p *Profile) ([]byte, error)
func parseJavaLocations(b []byte, locs map[uint64]*Location, p *Profile) error
func parseJavaSamples(pType string, b []byte, p *Profile) ([]byte, map[uint64]*Location, error)
func sampleTypes(p *Profile) []string
func serialize(p *Profile) []byte
func (*Profile).compatible(pb *Profile) error
label corresponds to Profile.Label
keyXint64
// Integer value for this label
Exactly one of the two following values must be set
can be set if numX has value
( T) decoder() []decoder( T) encode(b *buffer)
T : message
Package-Level Functions (total 78, in which 5 are exported)
Merge merges all the profiles in profs into a single Profile.
Returns a new profile independent of the input profiles. The merged
profile is compacted to eliminate unused samples, locations,
functions and mappings. Profiles must have identical profile sample
and period types or the merge will fail. profile.Period of the
resulting profile will be the maximum of all profiles, and
profile.TimeNanos will be the earliest nonzero one.
Parse parses a profile and checks for its validity. The input
may be a gzip-compressed encoded protobuf or one of many legacy
profile formats which may be unsupported in the future.
ParseData parses a profile from a buffer and checks for its
validity.
ParseProcMaps parses a memory map in the format of /proc/self/maps.
ParseMemoryMap should be called after setting on a profile to
associate locations to the corresponding mapping based on their
address.
ParseUncompressed parses an uncompressed protobuf into a profile.
adjacent returns whether two mapping entries represent the same
mapping that has been split into two. Check that their addresses are adjacent,
and if the offsets match, if they are available.
combineHeaders checks that all profiles can be merged and returns
their combined profile.
cpuProfile returns a new Profile from C++ profilez data.
b is the profile bytes after the header, period is the profiling
period, and parse is a function to parse 8-byte chunks from the
profile in its native endianness.
equalValueType returns true if the two value types are semantically
equal. It ignores the internal fields used during encode/decode.
filterShowFromLocation tests a showFrom regex against a location, removes
lines after the last match and returns whether a match was found. If the
mapping is matched, then all lines are kept.
focusedAndNotIgnored looks up a slice of ids against a map of
focused/ignored locations. The map only contains locations that are
explicitly focused or ignored. Returns whether there is at least
one focused location but no ignored locations.
javaCPUProfile returns a new Profile from profilez data.
b is the profile bytes after the header, period is the profiling
period, and parse is a function to parse 8-byte chunks from the
profile in its native endianness.
labelsToString returns a string representation of a
map representing labels.
numLabelsToString returns a string representation of a map
representing numeric labels.
padStringArray pads arr with enough empty strings to make arr
length l when arr's length is less than l.
parseAdditionalSections parses any additional sections in the
profile, ignoring any unrecognized sections.
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.
parseContentionSample parses a single row from a contention profile
into a new Sample.
parseCPU parses a profilez legacy profile and returns a newly
populated Profile.
The general format for profilez samples is a sequence of words in
binary format. The first words are a header with the following data:
1st word -- 0
2nd word -- 3
3rd word -- 0 if a c++ application, 1 if a java application.
4th word -- Sampling period (in microseconds).
5th word -- Padding.
parseCPUSamples parses a collection of profilez samples from a
profile.
profilez samples are a repeated sequence of stack frames of the
form:
1st word -- The number of times this stack was encountered.
2nd word -- The size of the stack (StackSize).
3rd word -- The first address on the stack.
...
StackSize + 2 -- The last address on the stack
The last stack trace is of the form:
1st word -- 0
2nd word -- 1
3rd word -- 0
Addresses from stack traces may point to the next instruction after
each call. Optionally adjust by -1 to land somewhere on the actual
call (except for the leaf, which is not a call).
parseGoCount parses a Go count profile (e.g., threadcreate or
goroutine) and returns a new Profile.
parseHeap parses a heapz legacy or a growthz profile and
returns a newly populated Profile.
parseHeapSample parses a single row from a heap profile into a new Sample.
parseHexAddresses extracts hex numbers from a string, attempts to convert
each to an unsigned 64-bit number and returns the resulting numbers as a
slice, or an error if the string contains hex numbers which are too large to
handle (which means a malformed profile).
parseJavaHeader parses the attribute section on a java profile and
populates a profile. Returns the remainder of the buffer after all
attributes.
parseJavaLocations parses the location information in a java
profile and populates the Locations in a profile. It uses the
location addresses from the profile as both the ID of each
location.
parseJavaProfile returns a new profile from heapz or contentionz
data. b is the profile bytes after the header.
parseJavaSamples parses the samples from a java profile and
populates the Samples in a profile. Returns the remainder of the
buffer after the samples.
parseThread parses a Threadz profile and returns a new Profile.
parseThreadSample parses a symbolized or unsymbolized stack trace.
Returns the first line after the traceback, the sample (or nil if
it hits a 'same-as-previous' marker) and an error.
removeLoggingInfo detects and removes log prefix entries generated
by the glog package. If no logging prefix is detected, the string
is returned unmodified.
scaleHeapSample adjusts the data from a heapz Sample to
account for its probability of appearing in the collected
data. heapz profiles are a sampling of the memory allocations
requests in a program. We estimate the unsampled value by dividing
each collected sample by its probability of appearing in the
profile. heapz v2 profiles rely on a poisson process to determine
which samples to collect, based on the desired average collection
rate R. The probability of a sample of size S to appear in that
profile is 1-exp(-S/R).
Regular expressions to parse process mappings. Support the format used by Linux /proc/.../maps and other tools.
Recommended format:
Start End object file name offset(optional) linker build id
0x40000-0x80000 /path/to/binary (@FF00) abc123456
The pages are generated with Goldsv0.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.