Skip to content

Commit

Permalink
fix: Compare the duration of the frame to the minimum duration (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops authored Sep 26, 2023
1 parent 4e6e57e commit 59f9ab6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**Bug Fixes**

- Close remaining open events in Android profiles. ([#316](https://github.com/getsentry/vroom/pull/316))
- Enforce minimum frame duration for frame drop issue. ([#319](https://github.com/getsentry/vroom/pull/319))

**Internal**

Expand Down
4 changes: 2 additions & 2 deletions internal/occurrence/frame_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func newFrozenFrameStats(endNS uint64, durationNS float64) frozenFrameStats {
// nodeStackIfValid returns the nodeStack if we consider it valid as
// a frame drop cause.
func (s *frozenFrameStats) IsNodeStackValid(ns *nodeStack) bool {
return s.startNS <= ns.n.StartNS &&
return ns.n.StartNS >= s.startNS &&
ns.n.EndNS <= s.endNS &&
s.minDurationNS <= s.durationNS &&
ns.n.DurationNS >= s.minDurationNS &&
ns.n.StartNS <= s.startLimitNS &&
ns.n.IsApplication
}
Expand Down
64 changes: 51 additions & 13 deletions internal/occurrence/frame_drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestFindFrameDrop(t *testing.T) {
Unit: "nanosecond",
Values: []measurements.MeasurementValue{
{
ElapsedSinceStartNs: uint64(500 * time.Millisecond),
Value: float64(300 * time.Millisecond),
ElapsedSinceStartNs: uint64(400 * time.Millisecond),
Value: float64(200 * time.Millisecond),
},
},
},
Expand Down Expand Up @@ -178,8 +178,8 @@ func TestFindFrameDrop(t *testing.T) {
Unit: "nanosecond",
Values: []measurements.MeasurementValue{
{
ElapsedSinceStartNs: uint64(500 * time.Millisecond),
Value: float64(300 * time.Millisecond),
ElapsedSinceStartNs: uint64(400 * time.Millisecond),
Value: float64(200 * time.Millisecond),
},
},
},
Expand Down Expand Up @@ -400,8 +400,8 @@ func TestFindFrameDrop(t *testing.T) {
Unit: "nanosecond",
Values: []measurements.MeasurementValue{
{
ElapsedSinceStartNs: uint64(500 * time.Millisecond),
Value: float64(450 * time.Millisecond),
ElapsedSinceStartNs: uint64(400 * time.Millisecond),
Value: float64(300 * time.Millisecond),
},
},
},
Expand Down Expand Up @@ -628,8 +628,8 @@ func TestFindFrameDrop(t *testing.T) {
callTrees: map[uint64][]*nodetree.Node{
1: {
{
DurationNS: uint64(500 * time.Millisecond),
EndNS: uint64(500 * time.Millisecond),
DurationNS: uint64(1000 * time.Millisecond),
EndNS: uint64(1000 * time.Millisecond),
IsApplication: false,
Name: "root",
Package: "package",
Expand Down Expand Up @@ -671,8 +671,8 @@ func TestFindFrameDrop(t *testing.T) {
},
Children: []*nodetree.Node{
{
DurationNS: uint64(200 * time.Millisecond),
EndNS: uint64(300 * time.Millisecond),
DurationNS: uint64(250 * time.Millisecond),
EndNS: uint64(350 * time.Millisecond),
IsApplication: true,
Name: "child2-1",
Package: "package",
Expand All @@ -688,13 +688,13 @@ func TestFindFrameDrop(t *testing.T) {
},
},
{
DurationNS: uint64(200 * time.Millisecond),
DurationNS: uint64(250 * time.Millisecond),
EndNS: uint64(500 * time.Millisecond),
IsApplication: true,
Name: "child3",
Package: "package",
Path: "path",
StartNS: uint64(300 * time.Millisecond),
StartNS: uint64(250 * time.Millisecond),
Frame: frame.Frame{
Function: "child3",
InApp: &testutil.True,
Expand Down Expand Up @@ -734,7 +734,7 @@ func TestFindFrameDrop(t *testing.T) {
Tags: map[string]string{},
},
EvidenceData: map[string]interface{}{
"frame_duration_ns": uint64(200000000),
"frame_duration_ns": uint64(250000000),
"frame_module": "",
"frame_name": "child2-1",
"frame_package": "package",
Expand Down Expand Up @@ -777,3 +777,41 @@ func TestFindFrameDrop(t *testing.T) {
})
}
}

func TestIsNodeStackValid(t *testing.T) {
tests := []struct {
name string
stats frozenFrameStats
nodestack *nodeStack
valid bool
}{
{
name: "frame too short",
stats: frozenFrameStats{
startLimitNS: 0,
durationNS: 1000,
minDurationNS: 500,
startNS: 0,
endNS: 1000,
},
nodestack: &nodeStack{
n: &nodetree.Node{
StartNS: 100,
EndNS: 200,
IsApplication: true,
DurationNS: 100,
},
},
valid: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
output := tt.stats.IsNodeStackValid(tt.nodestack)
if output != tt.valid {
t.Fatalf("Didn't expect this value: %v", output)
}
})
}
}

0 comments on commit 59f9ab6

Please sign in to comment.