Skip to content

Commit

Permalink
fix(profiles): Use the duration reported by the profiler (#4058)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops authored Sep 23, 2024
1 parent eb7dc1d commit aa151d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Bug Fixes**:

- Report invalid spans with appropriate outcome reason. ([#4051](https://github.com/getsentry/relay/pull/4051))
- Use the duration reported by the profiler instead of the transaction. ([#4058](https://github.com/getsentry/relay/pull/4058))

**Features:**

Expand Down
7 changes: 4 additions & 3 deletions relay-profiling/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl AndroidProfilingEvent {
}

fn has_transaction_metadata(&self) -> bool {
!self.metadata.transaction_name.is_empty() && self.metadata.duration_ns > 0
!self.metadata.transaction_name.is_empty()
}
}

Expand All @@ -170,7 +170,6 @@ fn parse_profile(payload: &[u8]) -> Result<AndroidProfilingEvent, ProfileError>

// this is for compatibility
profile.metadata.active_thread_id = transaction.active_thread_id;
profile.metadata.duration_ns = transaction.duration_ns();
profile.metadata.trace_id = transaction.trace_id;
profile.metadata.transaction_id = transaction.id;
profile
Expand Down Expand Up @@ -207,6 +206,9 @@ fn parse_profile(payload: &[u8]) -> Result<AndroidProfilingEvent, ProfileError>
return Err(ProfileError::DurationIsTooLong);
}

// Use duration given by the profiler and not reported by the SDK.
profile.metadata.duration_ns = profile.profile.elapsed_time.as_nanos() as u64;

Ok(profile)
}

Expand Down Expand Up @@ -320,7 +322,6 @@ mod tests {
);
assert_eq!(profile.metadata.active_thread_id, 12345);
assert_eq!(profile.metadata.transaction_name, "transaction1");
assert_eq!(profile.metadata.duration_ns, 1000000000);
}

#[test]
Expand Down
4 changes: 0 additions & 4 deletions relay-profiling/src/transaction_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ impl TransactionMetadata {
pub fn valid(&self) -> bool {
!self.id.is_nil() && !self.name.is_empty() && !self.trace_id.is_nil()
}

pub fn duration_ns(&self) -> u64 {
self.relative_end_ns.saturating_sub(self.relative_start_ns)
}
}

#[cfg(test)]
Expand Down

0 comments on commit aa151d2

Please sign in to comment.