Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

malloc: refinements #18897

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions pkg/common/malloc/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Profiler[T any, P interface {
type SampleInfo[T any] struct {
Values T
Locations []*profile.Location
Scale int64
}

type SampleValues interface {
Expand Down Expand Up @@ -94,7 +95,7 @@ func (p *Profiler[T, P]) Sample(
// full stack
var pcs _PCs
runtime.Callers(skip, pcs[:])
return p.getSampleValueFromPCs(pcs)
return p.getSampleValueFromPCs(pcs, int64(fullStackFraction))
}

func (p *Profiler[T, P]) getLocation(frame runtime.Frame) *profile.Location {
Expand Down Expand Up @@ -182,7 +183,7 @@ func (p *Profiler[T, P]) getMockFunction(label string) *profile.Function {
return v.(*profile.Function)
}

func (p *Profiler[T, P]) getSampleValueFromPCs(pcs _PCs) P {
func (p *Profiler[T, P]) getSampleValueFromPCs(pcs _PCs, scale int64) P {
key := SampleKey{
PCs: pcs,
}
Expand All @@ -196,6 +197,7 @@ func (p *Profiler[T, P]) getSampleValueFromPCs(pcs _PCs) P {
v, _ := p.samples.LoadOrStore(key, &SampleInfo[P]{
Values: &value,
Locations: p.getLocationsFromPCs(pcs),
Scale: scale,
})

return v.(*SampleInfo[P]).Values
Expand Down Expand Up @@ -241,19 +243,18 @@ func (p *Profiler[T, P]) Write(w io.Writer) error {

p.samples.Range(func(k, v any) bool {
info := v.(*SampleInfo[P])
values := info.Values.Values()
for i := range values {
values[i] *= info.Scale
}
sample := &profile.Sample{
Location: info.Locations,
Value: info.Values.Values(),
Value: values,
}
prof.Sample = append(prof.Sample, sample)
return true
})

prof.Sample = append(prof.Sample, &profile.Sample{
Location: p.stackOmittedSample.Locations,
Value: P(&p.stackOmittedSample.Values).Values(),
})

p.locations.Range(func(k, v any) bool {
location := v.(*profile.Location)
prof.Location = append(prof.Location, copyLocation(location))
Expand Down
Loading