checkAggregation verifies that the profile remained consistent with its aggregation.
(prof *Profile, a *aggTest)
| 671 | // checkAggregation verifies that the profile remained consistent |
| 672 | // with its aggregation. |
| 673 | func checkAggregation(prof *Profile, a *aggTest) error { |
| 674 | // Check that the total number of samples for the rows was preserved. |
| 675 | total := int64(0) |
| 676 | |
| 677 | samples := make(map[string]bool) |
| 678 | for _, sample := range prof.Sample { |
| 679 | tb := locationHash(sample) |
| 680 | samples[tb] = true |
| 681 | total += sample.Value[0] |
| 682 | } |
| 683 | |
| 684 | if total != totalSamples { |
| 685 | return fmt.Errorf("sample total %d, want %d", total, totalSamples) |
| 686 | } |
| 687 | |
| 688 | // Check the number of unique sample locations |
| 689 | if a.rows != len(samples) { |
| 690 | return fmt.Errorf("number of samples %d, want %d", len(samples), a.rows) |
| 691 | } |
| 692 | |
| 693 | // Check that all mappings have the right detail flags. |
| 694 | for _, m := range prof.Mapping { |
| 695 | if m.HasFunctions != a.function { |
| 696 | return fmt.Errorf("unexpected mapping.HasFunctions %v, want %v", m.HasFunctions, a.function) |
| 697 | } |
| 698 | if m.HasFilenames != a.fileline { |
| 699 | return fmt.Errorf("unexpected mapping.HasFilenames %v, want %v", m.HasFilenames, a.fileline) |
| 700 | } |
| 701 | if m.HasLineNumbers != a.fileline { |
| 702 | return fmt.Errorf("unexpected mapping.HasLineNumbers %v, want %v", m.HasLineNumbers, a.fileline) |
| 703 | } |
| 704 | if m.HasInlineFrames != a.inlineFrame { |
| 705 | return fmt.Errorf("unexpected mapping.HasInlineFrames %v, want %v", m.HasInlineFrames, a.inlineFrame) |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | // Check that aggregation has removed finer resolution data. |
| 710 | for _, l := range prof.Location { |
| 711 | if !a.inlineFrame && len(l.Line) > 1 { |
| 712 | return fmt.Errorf("found %d lines on location %d, want 1", len(l.Line), l.ID) |
| 713 | } |
| 714 | |
| 715 | for _, ln := range l.Line { |
| 716 | if !a.column && ln.Column != 0 { |
| 717 | return fmt.Errorf("found column %d on location %d, want:0", ln.Column, l.ID) |
| 718 | } |
| 719 | if !a.fileline && (ln.Function.Filename != "" || ln.Line != 0) { |
| 720 | return fmt.Errorf("found line %s:%d on location %d, want :0", |
| 721 | ln.Function.Filename, ln.Line, l.ID) |
| 722 | } |
| 723 | if !a.function && (ln.Function.Name != "") { |
| 724 | return fmt.Errorf(`found file %s location %d, want ""`, |
| 725 | ln.Function.Name, l.ID) |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | return nil |
no test coverage detected
searching dependent graphs…