Skip to content

Commit

Permalink
feat: monitor for new metric values via sampling and notifications (#…
Browse files Browse the repository at this point in the history
…2493)

* feat: monitor for new metric values via sampling and notifications
* wrap syscalls/NSProcess and NSTimer APIs with tests/mocks
* typedef system type to SentryRAMBytes for better understandability
* split slow/frozen GPU frame render timestamps; use singular unit names
* wrap bare nanosecond conversions in function
* add slow/frozen frames to test case, test amount of GPU frame render timestamps recorded for profiling metrics, using mock in test
* fix typo "TestDiplayLinkWrapper"; simplify lazy property init
  • Loading branch information
armcknight committed Jan 18, 2023
1 parent 621ba9b commit b2f82fa
Show file tree
Hide file tree
Showing 40 changed files with 1,236 additions and 431 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# Changelog

## Unreleased

### Features

- Gather profiling timeseries metrics for CPU usage and memory footprint, and thermal and memory pressure events (#2493)

## 8.0.0

### Features

This version adds a dependency on Swift.
This version adds a dependency on Swift. We renamed the default branch from `master` to `main`. We are going to keep the `master` branch for backwards compatibility for package managers pointing to the `master` branch.

### Features
Expand Down
152 changes: 98 additions & 54 deletions Sentry.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Sources/Sentry/Public/SentryError.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ typedef NS_ENUM(NSInteger, SentryError) {
kSentryErrorRequestError = 106,
kSentryErrorEventNotSent = 107,
kSentryErrorFileIO = 108,
kSentryErrorKernel = 109,
};

SENTRY_EXTERN NSError *_Nullable NSErrorFromSentryError(SentryError error, NSString *description);
SENTRY_EXTERN NSError *_Nullable NSErrorFromSentryErrorWithUnderlyingError(
SentryError error, NSString *description, NSError *underlyingError);
SENTRY_EXTERN NSError *_Nullable NSErrorFromSentryErrorWithException(
SentryError error, NSString *description, NSException *exception);
SENTRY_EXTERN NSError *_Nullable NSErrorFromSentryErrorWithKernelError(
SentryError error, NSString *description, kern_return_t kernelErrorCode);

SENTRY_EXTERN NSString *const SentryErrorDomain;

Expand Down
10 changes: 10 additions & 0 deletions Sources/Sentry/SentryError.m → Sources/Sentry/SentryError.mm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "SentryError.h"
#import "SentryMachLogging.hpp"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -25,6 +26,15 @@
});
}

SENTRY_EXTERN NSError *_Nullable NSErrorFromSentryErrorWithKernelError(
SentryError error, NSString *description, kern_return_t kernelErrorCode)
{
return _SentryError(error, @ {
NSLocalizedDescriptionKey : [NSString stringWithFormat:@"%@ (%s)", description,
sentry::kernelReturnCodeDescription(kernelErrorCode)],
});
}

NSError *_Nullable NSErrorFromSentryError(SentryError error, NSString *description)
{
return _SentryError(error, @ { NSLocalizedDescriptionKey : description });
Expand Down
21 changes: 14 additions & 7 deletions Sources/Sentry/SentryFramesTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
@property (nonatomic, strong, readonly) SentryDisplayLinkWrapper *displayLinkWrapper;
@property (nonatomic, assign) CFTimeInterval previousFrameTimestamp;
# if SENTRY_TARGET_PROFILING_SUPPORTED
@property (nonatomic, readwrite) SentryMutableFrameInfoTimeSeries *frameTimestamps;
@property (nonatomic, readwrite) SentryMutableFrameInfoTimeSeries *frozenFrameTimestamps;
@property (nonatomic, readwrite) SentryMutableFrameInfoTimeSeries *slowFrameTimestamps;
@property (nonatomic, readwrite) SentryMutableFrameInfoTimeSeries *frameRateTimestamps;
# endif // SENTRY_TARGET_PROFILING_SUPPORTED

Expand Down Expand Up @@ -91,7 +92,8 @@ - (void)resetFrames
# if SENTRY_TARGET_PROFILING_SUPPORTED
- (void)resetProfilingTimestamps
{
self.frameTimestamps = [SentryMutableFrameInfoTimeSeries array];
self.frozenFrameTimestamps = [SentryMutableFrameInfoTimeSeries array];
self.slowFrameTimestamps = [SentryMutableFrameInfoTimeSeries array];
self.frameRateTimestamps = [SentryMutableFrameInfoTimeSeries array];
}
# endif // SENTRY_TARGET_PROFILING_SUPPORTED
Expand Down Expand Up @@ -157,12 +159,16 @@ - (void)displayLinkCallback
if (frameDuration > slowFrameThreshold && frameDuration <= SentryFrozenFrameThreshold) {
atomic_fetch_add_explicit(&_slowFrames, 1, SentryFramesMemoryOrder);
# if SENTRY_TARGET_PROFILING_SUPPORTED
[self recordTimestampStart:@(self.previousFrameTimestamp) end:@(thisFrameTimestamp)];
[self recordTimestampStart:@(self.previousFrameTimestamp)
end:@(thisFrameTimestamp)
array:self.slowFrameTimestamps];
# endif // SENTRY_TARGET_PROFILING_SUPPORTED
} else if (frameDuration > SentryFrozenFrameThreshold) {
atomic_fetch_add_explicit(&_frozenFrames, 1, SentryFramesMemoryOrder);
# if SENTRY_TARGET_PROFILING_SUPPORTED
[self recordTimestampStart:@(self.previousFrameTimestamp) end:@(thisFrameTimestamp)];
[self recordTimestampStart:@(self.previousFrameTimestamp)
end:@(thisFrameTimestamp)
array:self.frozenFrameTimestamps];
# endif // SENTRY_TARGET_PROFILING_SUPPORTED
}

Expand All @@ -171,14 +177,14 @@ - (void)displayLinkCallback
}

# if SENTRY_TARGET_PROFILING_SUPPORTED
- (void)recordTimestampStart:(NSNumber *)start end:(NSNumber *)end
- (void)recordTimestampStart:(NSNumber *)start end:(NSNumber *)end array:(NSMutableArray *)array
{
BOOL shouldRecord = [SentryProfiler isRunning];
# if defined(TEST) || defined(TESTCI)
shouldRecord = YES;
# endif
if (shouldRecord) {
[self.frameTimestamps addObject:@{ @"start_timestamp" : start, @"end_timestamp" : end }];
[array addObject:@{ @"start_timestamp" : start, @"end_timestamp" : end }];
}
}
# endif // SENTRY_TARGET_PROFILING_SUPPORTED
Expand All @@ -193,7 +199,8 @@ - (SentryScreenFrames *)currentFrames
return [[SentryScreenFrames alloc] initWithTotal:total
frozen:frozen
slow:slow
frameTimestamps:self.frameTimestamps
slowFrameTimestamps:self.slowFrameTimestamps
frozenFrameTimestamps:self.frozenFrameTimestamps
frameRateTimestamps:self.frameRateTimestamps];
# else
return [[SentryScreenFrames alloc] initWithTotal:total frozen:frozen slow:slow];
Expand Down

0 comments on commit b2f82fa

Please sign in to comment.