Skip to content

Commit

Permalink
Merge branch 'main' into armcknight/fix/profiling-metric-collection-s…
Browse files Browse the repository at this point in the history
…tart-end
  • Loading branch information
armcknight committed Sep 18, 2023
2 parents 359e03a + bef2003 commit d81067c
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 70 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Fixes

- Remove warning about non-portable path to file "SentryDsn.h" (#3270)
- Privacy manifest collection purposes type (#3276)
- Fix how profiles were identified in the backend for grouping and issue correlation purposes (#3282)
- Ensure GPU frame data is always sent with profiles even if `enableAutoPerformanceTracing` is `NO` (#3273)
- Gather metric readings fully covering the duration of a profile (#3272)

### Features
Expand Down
110 changes: 58 additions & 52 deletions Sources/Resources/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,63 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyCollectedDataTypes</key>
<array>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeCrashData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypePerformanceData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeOtherDiagnosticData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</dict>
</array>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>35F9.1</string>
</array>
</dict>
</array>
<key>NSPrivacyCollectedDataTypes</key>
<array>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeCrashData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypePerformanceData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeOtherDiagnosticData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
</array>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>35F9.1</string>
</array>
</dict>
</array>
</dict>
</plist>
4 changes: 2 additions & 2 deletions Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
void
_unsafe_cleanUpProfiler(SentryProfiler *profiler, NSString *tracerKey)
{
const auto profilerKey = profiler.profileId.sentryIdString;
const auto profilerKey = profiler.profilerId.sentryIdString;

[_gTracersToProfilers removeObjectForKey:tracerKey];
_gProfilersToTracers[profilerKey] = @(_gProfilersToTracers[profilerKey].unsignedIntValue - 1);
Expand All @@ -58,7 +58,7 @@
{
std::lock_guard<std::mutex> l(_gStateLock);

const auto profilerKey = profiler.profileId.sentryIdString;
const auto profilerKey = profiler.profilerId.sentryIdString;
const auto tracerKey = traceId.sentryIdString;

SENTRY_LOG_DEBUG(
Expand Down
30 changes: 23 additions & 7 deletions Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# import "SentryEnvelopeItemType.h"
# import "SentryEvent+Private.h"
# import "SentryFormatter.h"
# import "SentryFramesTracker.h"
# import "SentryHub+Private.h"
# import "SentryId.h"
# import "SentryInternalDefines.h"
Expand All @@ -26,6 +27,7 @@
# import "SentryProfileTimeseries.h"
# import "SentryProfiledTracerConcurrency.h"
# import "SentryProfilerState+ObjCpp.h"
# import "SentrySDK+Private.h"
# import "SentrySample.h"
# import "SentrySamplingProfiler.hpp"
# import "SentryScope+Private.h"
Expand Down Expand Up @@ -153,10 +155,10 @@
}

NSMutableDictionary<NSString *, id> *
serializedProfileData(NSDictionary<NSString *, id> *profileData, uint64_t startSystemTime,
uint64_t endSystemTime, SentryId *profileID, NSString *truncationReason,
NSDictionary<NSString *, id> *serializedMetrics, NSArray<SentryDebugMeta *> *debugMeta,
SentryHub *hub
serializedProfileData(
NSDictionary<NSString *, id> *profileData, uint64_t startSystemTime, uint64_t endSystemTime,
NSString *truncationReason, NSDictionary<NSString *, id> *serializedMetrics,
NSArray<SentryDebugMeta *> *debugMeta, SentryHub *hub
# if SENTRY_HAS_UIKIT
,
SentryScreenFrames *gpuData
Expand Down Expand Up @@ -211,7 +213,7 @@
@"model" : isEmulated ? sentry_getSimulatorDeviceModel() : sentry_getDeviceModel()
};

payload[@"profile_id"] = profileID.sentryIdString;
payload[@"profile_id"] = [[[SentryId alloc] init] sentryIdString];
payload[@"truncation_reason"] = truncationReason;
payload[@"environment"] = hub.scope.environmentString ?: hub.getClient.options.environment;
payload[@"release"] = hub.getClient.options.releaseName;
Expand Down Expand Up @@ -270,10 +272,16 @@ - (instancetype)init
return nil;
}

_profileId = [[SentryId alloc] init];
_profilerId = [[SentryId alloc] init];

SENTRY_LOG_DEBUG(@"Initialized new SentryProfiler %@", self);
_debugImageProvider = [SentryDependencyContainer sharedInstance].debugImageProvider;

# if SENTRY_HAS_UIKIT
// the frame tracker may not be running if SentryOptions.enableAutoPerformanceTracing is NO
[SentryDependencyContainer.sharedInstance.framesTracker start];
# endif // SENTRY_HAS_UIKIT

[self start];
[self scheduleTimeoutTimer];

Expand Down Expand Up @@ -426,7 +434,7 @@ + (void)updateProfilePayload:(NSMutableDictionary<NSString *, id> *)payload
onHub:(SentryHub *)hub;
{
return serializedProfileData([self._state copyProfilingData], startSystemTime, endSystemTime,
self.profileId, profilerTruncationReasonName(_truncationReason),
profilerTruncationReasonName(_truncationReason),
[_metricProfiler serializeBetween:startSystemTime and:endSystemTime],
[_debugImageProvider getDebugImagesCrashed:NO], hub
# if SENTRY_HAS_UIKIT
Expand Down Expand Up @@ -469,6 +477,14 @@ - (void)stopForReason:(SentryProfilerTruncationReason)reason
return;
}

# if SENTRY_HAS_UIKIT
// if SentryOptions.enableAutoPerformanceTracing is NO, then we need to stop the frames tracker
// from running outside of profiles because it isn't needed for anything else
if (![[[[SentrySDK currentHub] getClient] options] enableAutoPerformanceTracing]) {
[SentryDependencyContainer.sharedInstance.framesTracker stop];
}
# endif // SENTRY_HAS_UIKIT

_profiler->stopSampling();
SENTRY_LOG_DEBUG(@"Stopped profiler %@.", self);
}
Expand Down
5 changes: 2 additions & 3 deletions Sources/Sentry/include/SentryProfiler+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ NS_ASSUME_NONNULL_BEGIN

NSMutableDictionary<NSString *, id> *serializedProfileData(
NSDictionary<NSString *, id> *profileData, uint64_t startSystemTime, uint64_t endSystemTime,
SentryId *profileID, NSString *truncationReason,
NSDictionary<NSString *, id> *serializedMetrics, NSArray<SentryDebugMeta *> *debugMeta,
SentryHub *hub
NSString *truncationReason, NSDictionary<NSString *, id> *serializedMetrics,
NSArray<SentryDebugMeta *> *debugMeta, SentryHub *hub
# if SENTRY_HAS_UIKIT
,
SentryScreenFrames *gpuData
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentryProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SENTRY_EXTERN_C_END
*/
@interface SentryProfiler : NSObject

@property (strong, nonatomic) SentryId *profileId;
@property (strong, nonatomic) SentryId *profilerId;

/**
* Start a profiler, if one isn't already running.
Expand Down
1 change: 0 additions & 1 deletion Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ class SentryProfilerSwiftTests: XCTestCase {
spans.removeAll()
#if !os(macOS)
fixture.resetGPUExpectations()
fixture.displayLinkWrapper.call()
#endif

try createConcurrentSpansWithMetrics()
Expand Down
7 changes: 3 additions & 4 deletions Tests/SentryProfilerTests/SentryProfilerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,9 @@ - (void)testProfilerMutationDuringSerialization
// serialize the data as if it were captured in a transaction envelope
const auto profileData = [state copyProfilingData];

const auto profileID = [[SentryId alloc] init];
const auto serialization = serializedProfileData(profileData, 1, 2, profileID,
profilerTruncationReasonName(SentryProfilerTruncationReasonNormal), @{}, @[],
[[SentryHub alloc] initWithClient:nil andScope:nil]
const auto serialization = serializedProfileData(
profileData, 1, 2, profilerTruncationReasonName(SentryProfilerTruncationReasonNormal), @{},
@[], [[SentryHub alloc] initWithClient:nil andScope:nil]
# if SENTRY_HAS_UIKIT
,
[[SentryScreenFrames alloc] initWithTotal:5
Expand Down

0 comments on commit d81067c

Please sign in to comment.