(p *Profiling, samples map[uint64]T, start time.Time, duration time.Duration, sampleType []*profile.ValueType, ratios []float64)
| 439 | } |
| 440 | |
| 441 | func buildProfile[T sampleType](p *Profiling, samples map[uint64]T, start time.Time, duration time.Duration, sampleType []*profile.ValueType, ratios []float64) *profile.Profile { |
| 442 | prof := &profile.Profile{ |
| 443 | SampleType: sampleType, |
| 444 | Sample: make([]*profile.Sample, 0, len(samples)), |
| 445 | TimeNanos: start.UnixNano(), |
| 446 | DurationNanos: int64(duration), |
| 447 | } |
| 448 | |
| 449 | locationID := uint64(1) |
| 450 | locationCache := make(map[locationKey]*profile.Location) |
| 451 | functionCache := make(map[string]*profile.Function) |
| 452 | |
| 453 | for _, sample := range samples { |
| 454 | stack := sample.sampleLocation() |
| 455 | location := make([]*profile.Location, stack.len()) |
| 456 | |
| 457 | for i := range location { |
| 458 | fn := stack.fns[i] |
| 459 | pc := stack.pcs[i] |
| 460 | |
| 461 | def := fn.Definition() |
| 462 | key := makeLocationKey(def, pc) |
| 463 | loc := locationCache[key] |
| 464 | if loc == nil { |
| 465 | loc = locationForCall(p, fn, pc, functionCache) |
| 466 | loc.ID = locationID |
| 467 | locationID++ |
| 468 | locationCache[key] = loc |
| 469 | } |
| 470 | |
| 471 | location[i] = loc |
| 472 | } |
| 473 | |
| 474 | prof.Sample = append(prof.Sample, &profile.Sample{ |
| 475 | Location: location, |
| 476 | Value: sample.sampleValue()[:len(sampleType)], |
| 477 | }) |
| 478 | } |
| 479 | |
| 480 | prof.Location = make([]*profile.Location, len(locationCache)) |
| 481 | prof.Function = make([]*profile.Function, len(functionCache)) |
| 482 | |
| 483 | for _, loc := range locationCache { |
| 484 | prof.Location[loc.ID-1] = loc |
| 485 | } |
| 486 | |
| 487 | for _, fn := range functionCache { |
| 488 | prof.Function[fn.ID-1] = fn |
| 489 | } |
| 490 | |
| 491 | if err := prof.ScaleN(ratios[:len(sampleType)]); err != nil { |
| 492 | panic(err) |
| 493 | } |
| 494 | return prof |
| 495 | } |
no test coverage detected