Skip to content

Commit

Permalink
ref(profiling): rename SentryLegacyProfiler -> SentryTraceProfiler (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed May 16, 2024
1 parent f1d1166 commit 37372a6
Show file tree
Hide file tree
Showing 27 changed files with 214 additions and 228 deletions.
28 changes: 14 additions & 14 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@
8431EFD329B27B1100D8DC56 /* Resources in Resources */ = {isa = PBXBuildFile; fileRef = 630C01951EC341D600C52CEF /* Resources */; };
8431EFDC29B27B5300D8DC56 /* SentryProfilerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 03F9D37B2819A65C00602916 /* SentryProfilerTests.mm */; };
8431EFDD29B27B5300D8DC56 /* SentrySamplingProfilerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 035E73CB27D575B3005EEB11 /* SentrySamplingProfilerTests.mm */; };
8431EFDE29B27B5300D8DC56 /* SentryLegacyProfilerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8419C0C328C1889D001C8259 /* SentryLegacyProfilerTests.swift */; };
8431EFDE29B27B5300D8DC56 /* SentryTraceProfilerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8419C0C328C1889D001C8259 /* SentryTraceProfilerTests.swift */; };
8431EFDF29B27B5300D8DC56 /* SentryThreadHandleTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 035E73C927D57398005EEB11 /* SentryThreadHandleTests.mm */; };
8431EFE029B27B5300D8DC56 /* SentryBacktraceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 035E73C727D56757005EEB11 /* SentryBacktraceTests.mm */; };
8431EFE129B27B5300D8DC56 /* SentryThreadMetadataCacheTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 035E73CD27D5790A005EEB11 /* SentryThreadMetadataCacheTests.mm */; };
Expand Down Expand Up @@ -682,8 +682,8 @@
848A451E2BBF9504006AAAEC /* SentryProfilerTestHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 848A451B2BBF9504006AAAEC /* SentryProfilerTestHelpers.h */; };
849AC40029E0C1FF00889C16 /* SentryFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849AC3FF29E0C1FF00889C16 /* SentryFormatterTests.swift */; };
84A305492BC7328400D84283 /* SentryAppLaunchProfilingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A305472BC72A0A00D84283 /* SentryAppLaunchProfilingTests.swift */; };
84A305572BC9EF8C00D84283 /* SentryLegacyProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A305552BC9EF8C00D84283 /* SentryLegacyProfiler.h */; };
84A305582BC9EF8C00D84283 /* SentryLegacyProfiler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A305562BC9EF8C00D84283 /* SentryLegacyProfiler.mm */; };
84A305572BC9EF8C00D84283 /* SentryTraceProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A305552BC9EF8C00D84283 /* SentryTraceProfiler.h */; };
84A305582BC9EF8C00D84283 /* SentryTraceProfiler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A305562BC9EF8C00D84283 /* SentryTraceProfiler.mm */; };
84A5D75B29D5170700388BFA /* TimeInterval+Sentry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */; };
84A8891C28DBD28900C51DFD /* SentryDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8891A28DBD28900C51DFD /* SentryDevice.h */; };
84A8891D28DBD28900C51DFD /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8891B28DBD28900C51DFD /* SentryDevice.mm */; };
Expand Down Expand Up @@ -1654,7 +1654,7 @@
840B7EF02BBF2B5F008B8120 /* MIGRATION.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = MIGRATION.md; sourceTree = "<group>"; };
840B7EF22BBF83DF008B8120 /* SentryProfiler+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryProfiler+Private.h"; path = "Sources/Sentry/include/SentryProfiler+Private.h"; sourceTree = SOURCE_ROOT; };
841325C42BF49EC40029228F /* SentryLaunchProfiling+Tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SentryLaunchProfiling+Tests.h"; sourceTree = "<group>"; };
8419C0C328C1889D001C8259 /* SentryLegacyProfilerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryLegacyProfilerTests.swift; sourceTree = "<group>"; };
8419C0C328C1889D001C8259 /* SentryTraceProfilerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTraceProfilerTests.swift; sourceTree = "<group>"; };
84281C422A578E5600EE88F2 /* SentryProfilerState.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryProfilerState.mm; sourceTree = "<group>"; };
84281C442A57905700EE88F2 /* SentrySample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySample.h; path = ../include/SentrySample.h; sourceTree = "<group>"; };
84281C452A57905700EE88F2 /* SentrySample.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySample.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1722,9 +1722,9 @@
849472842971C41A002603DE /* SentryNSTimerFactoryTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSTimerFactoryTest.swift; sourceTree = "<group>"; };
849AC3FF29E0C1FF00889C16 /* SentryFormatterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryFormatterTests.swift; sourceTree = "<group>"; };
84A305472BC72A0A00D84283 /* SentryAppLaunchProfilingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryAppLaunchProfilingTests.swift; sourceTree = "<group>"; };
84A305552BC9EF8C00D84283 /* SentryLegacyProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryLegacyProfiler.h; path = ../include/SentryLegacyProfiler.h; sourceTree = "<group>"; };
84A305562BC9EF8C00D84283 /* SentryLegacyProfiler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryLegacyProfiler.mm; sourceTree = "<group>"; };
84A305592BC9FD1600D84283 /* SentryLegacyProfiler+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryLegacyProfiler+Test.h"; sourceTree = "<group>"; };
84A305552BC9EF8C00D84283 /* SentryTraceProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTraceProfiler.h; path = ../include/SentryTraceProfiler.h; sourceTree = "<group>"; };
84A305562BC9EF8C00D84283 /* SentryTraceProfiler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryTraceProfiler.mm; sourceTree = "<group>"; };
84A305592BC9FD1600D84283 /* SentryTraceProfiler+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryTraceProfiler+Test.h"; sourceTree = "<group>"; };
84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeInterval+Sentry.swift"; sourceTree = "<group>"; };
84A8891A28DBD28900C51DFD /* SentryDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = include/SentryDevice.h; sourceTree = "<group>"; };
84A8891B28DBD28900C51DFD /* SentryDevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDevice.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2457,7 +2457,7 @@
62872B602BA1B84400A4FA7D /* Swift */,
7B3878E92490D90400EBDEA2 /* SentryClient+TestInit.h */,
D8BC83BA2AFCF08C00A662B7 /* SentryUIApplication+Private.h */,
84A305592BC9FD1600D84283 /* SentryLegacyProfiler+Test.h */,
84A305592BC9FD1600D84283 /* SentryTraceProfiler+Test.h */,
7B569DFE2590EEF600B653FC /* SentryScope+Equality.h */,
7B569E052590F04700B653FC /* SentryScope+Properties.h */,
7B9421C4260CA393001F9349 /* SentrySDK+Tests.h */,
Expand Down Expand Up @@ -3361,8 +3361,8 @@
840B7EF22BBF83DF008B8120 /* SentryProfiler+Private.h */,
8431D4612BE1B534009EAEC1 /* SentryProfilerDefines.h */,
03F84D2B27DD4191008FE43F /* SentryProfiler.mm */,
84A305552BC9EF8C00D84283 /* SentryLegacyProfiler.h */,
84A305562BC9EF8C00D84283 /* SentryLegacyProfiler.mm */,
84A305552BC9EF8C00D84283 /* SentryTraceProfiler.h */,
84A305562BC9EF8C00D84283 /* SentryTraceProfiler.mm */,
848A451B2BBF9504006AAAEC /* SentryProfilerTestHelpers.h */,
848A451C2BBF9504006AAAEC /* SentryProfilerTestHelpers.m */,
848A45172BBF8D33006AAAEC /* SentryContinuousProfiler.h */,
Expand Down Expand Up @@ -3406,7 +3406,7 @@
035E73CD27D5790A005EEB11 /* SentryThreadMetadataCacheTests.mm */,
03F9D37B2819A65C00602916 /* SentryProfilerTests.mm */,
84A305472BC72A0A00D84283 /* SentryAppLaunchProfilingTests.swift */,
8419C0C328C1889D001C8259 /* SentryLegacyProfilerTests.swift */,
8419C0C328C1889D001C8259 /* SentryTraceProfilerTests.swift */,
8446F5182BE172290040D57E /* SentryContinuousProfilerTests.swift */,
8431D4522BE1741E009EAEC1 /* SentryProfileTestFixture.swift */,
);
Expand Down Expand Up @@ -3999,7 +3999,7 @@
62A456E12B03704A003F19A1 /* SentryUIEventTrackerMode.h in Headers */,
03F84D2327DD414C008FE43F /* SentryThreadHandle.hpp in Headers */,
7B6C5EE0264E8E050010D138 /* SentryFramesTracker.h in Headers */,
84A305572BC9EF8C00D84283 /* SentryLegacyProfiler.h in Headers */,
84A305572BC9EF8C00D84283 /* SentryTraceProfiler.h in Headers */,
63FE715720DA4C1100CDBAE8 /* SentryCrashThread.h in Headers */,
7BF9EF862722D10600B5BBEF /* SentryTestObjCRuntimeWrapper.h in Headers */,
15360CD2243277A000112302 /* SentrySessionTracker.h in Headers */,
Expand Down Expand Up @@ -4507,7 +4507,7 @@
63FE70E120DA4C1000CDBAE8 /* SentryCrashMonitor_CPPException.cpp in Sources */,
D8F6A2472885512100320515 /* SentryPredicateDescriptor.m in Sources */,
A839D89A24864BA8003B7AFD /* SentrySystemEventBreadcrumbs.m in Sources */,
84A305582BC9EF8C00D84283 /* SentryLegacyProfiler.mm in Sources */,
84A305582BC9EF8C00D84283 /* SentryTraceProfiler.mm in Sources */,
7D082B8323C628790029866B /* SentryMeta.m in Sources */,
D8CAC02F2BA0663E00E38F34 /* SentryVideoInfo.swift in Sources */,
63FE710720DA4C1000CDBAE8 /* SentryCrashStackCursor_SelfThread.m in Sources */,
Expand Down Expand Up @@ -4966,7 +4966,7 @@
8431EFE829B27BAD00D8DC56 /* SentrySystemWrapperTests.swift in Sources */,
84A305492BC7328400D84283 /* SentryAppLaunchProfilingTests.swift in Sources */,
8431EFE529B27BAD00D8DC56 /* SentryNSProcessInfoWrapperTests.swift in Sources */,
8431EFDE29B27B5300D8DC56 /* SentryLegacyProfilerTests.swift in Sources */,
8431EFDE29B27B5300D8DC56 /* SentryTraceProfilerTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions SentryTestUtils/ClearTestState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class TestCleanup: NSObject {
SentryTracer.resetAppStartMeasurementRead()

#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
SentryLegacyProfiler.getCurrentProfiler()?.stop(for: SentryProfilerTruncationReason.normal)
SentryLegacyProfiler.resetConcurrencyTracking()
SentryTraceProfiler.getCurrentProfiler()?.stop(for: SentryProfilerTruncationReason.normal)
SentryTraceProfiler.resetConcurrencyTracking()
SentryContinuousProfiler.stop()
removeAppLaunchProfilingConfigFile()
sentry_stopAndDiscardLaunchProfileTracer()
Expand Down
2 changes: 1 addition & 1 deletion SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#if SENTRY_TARGET_PROFILING_SUPPORTED
# import "SentryContinuousProfiler.h"
# import "SentryLaunchProfiling.h"
# import "SentryLegacyProfiler+Test.h"
# import "SentryProfiler+Private.h"
# import "SentryTraceProfiler+Test.h"
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

#import "PrivateSentrySDKOnly.h"
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/PrivateSentrySDKOnly.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#import <SentryUser.h>

#if SENTRY_TARGET_PROFILING_SUPPORTED
# import "SentryLegacyProfiler.h"
# import "SentryProfiledTracerConcurrency.h"
# import "SentryProfilerSerialization.h"
# import "SentryTraceProfiler.h"
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

@implementation PrivateSentrySDKOnly
Expand Down Expand Up @@ -134,7 +134,7 @@ + (NSDictionary *)getExtraContext
#if SENTRY_TARGET_PROFILING_SUPPORTED
+ (uint64_t)startProfilerForTrace:(SentryId *)traceId;
{
[SentryLegacyProfiler startWithTracer:traceId];
[SentryTraceProfiler startWithTracer:traceId];
return SentryDependencyContainer.sharedInstance.dateProvider.systemTime;
}

Expand Down
32 changes: 12 additions & 20 deletions Sources/Sentry/Profiling/SentryContinuousProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,10 @@

namespace {
/** @warning: Must be used from a synchronized context. */
std::mutex _unsafe_gContinuousProfilerLock;
std::mutex _threadUnsafe_gContinuousProfilerLock;

/** @warning: Must be used from a synchronized context. */
SentryProfiler *_Nullable _unsafe_gContinuousCurrentProfiler;

/** @warning: Must be called from a synchronized context. */
BOOL
_unsafe_isRunning(void)
{
return _unsafe_gContinuousCurrentProfiler != nil &&
[_unsafe_gContinuousCurrentProfiler isRunning];
}
SentryProfiler *_Nullable _threadUnsafe_gContinuousCurrentProfiler;
} // namespace

@implementation SentryContinuousProfiler
Expand All @@ -30,44 +22,44 @@ @implementation SentryContinuousProfiler

+ (void)start
{
std::lock_guard<std::mutex> l(_unsafe_gContinuousProfilerLock);
std::lock_guard<std::mutex> l(_threadUnsafe_gContinuousProfilerLock);

if (_unsafe_isRunning()) {
if ([_threadUnsafe_gContinuousCurrentProfiler isRunning]) {
SENTRY_LOG_DEBUG(@"A continuous profiler is already running.");
return;
}

if (!(_unsafe_gContinuousCurrentProfiler =
if (!(_threadUnsafe_gContinuousCurrentProfiler =
[[SentryProfiler alloc] initWithMode:SentryProfilerModeContinuous])) {
SENTRY_LOG_WARN(@"Continuous profiler was unable to be initialized.");
}
}

+ (BOOL)isCurrentlyProfiling
{
std::lock_guard<std::mutex> l(_unsafe_gContinuousProfilerLock);
return _unsafe_isRunning();
std::lock_guard<std::mutex> l(_threadUnsafe_gContinuousProfilerLock);
return [_threadUnsafe_gContinuousCurrentProfiler isRunning];
}

+ (void)stop
{
std::lock_guard<std::mutex> l(_unsafe_gContinuousProfilerLock);
std::lock_guard<std::mutex> l(_threadUnsafe_gContinuousProfilerLock);

if (!_unsafe_isRunning()) {
if (![_threadUnsafe_gContinuousCurrentProfiler isRunning]) {
SENTRY_LOG_DEBUG(@"No continuous profiler is currently running.");
return;
}

[_unsafe_gContinuousCurrentProfiler stopForReason:SentryProfilerTruncationReasonNormal];
[_threadUnsafe_gContinuousCurrentProfiler stopForReason:SentryProfilerTruncationReasonNormal];
}

# pragma mark - Testing

# if defined(TEST) || defined(TESTCI) || defined(DEBUG)
+ (nullable SentryProfiler *)profiler
{
std::lock_guard<std::mutex> l(_unsafe_gContinuousProfilerLock);
return _unsafe_gContinuousCurrentProfiler;
std::lock_guard<std::mutex> l(_threadUnsafe_gContinuousProfilerLock);
return _threadUnsafe_gContinuousCurrentProfiler;
}
# endif // defined(TEST) || defined(TESTCI) || defined(DEBUG)

Expand Down
8 changes: 5 additions & 3 deletions Sources/Sentry/Profiling/SentryLaunchProfiling.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

NS_ASSUME_NONNULL_BEGIN

BOOL isProfilingAppLaunch;
NSString *const kSentryLaunchProfileConfigKeyTracesSampleRate = @"traces";
NSString *const kSentryLaunchProfileConfigKeyProfilesSampleRate = @"profiles";
NSString *const kSentryLaunchProfileConfigKeyContinuousProfiling = @"continuous-profiling";
static SentryTracer *_Nullable launchTracer;

# pragma mark - Private

Expand All @@ -46,7 +48,7 @@

typedef struct {
BOOL shouldProfile;
/** Only needed for legacy launch profiling; unused with continuous profiling. */
/** Only needed for trace launch profiling; unused with continuous profiling. */
SentrySamplerDecision *_Nullable tracesDecision;
SentrySamplerDecision *_Nullable profilesDecision;
} SentryLaunchProfileConfig;
Expand Down Expand Up @@ -81,11 +83,11 @@
SentrySamplerDecision *profilesSamplerDecision
= sentry_sampleTraceProfile(context, tracesSamplerDecision, options);
if (profilesSamplerDecision.decision != kSentrySampleDecisionYes) {
SENTRY_LOG_DEBUG(@"Sampling out the launch legacy profile.");
SENTRY_LOG_DEBUG(@"Sampling out the launch trace profile.");
return (SentryLaunchProfileConfig) { NO, nil, nil };
}

SENTRY_LOG_DEBUG(@"Will start legacy profile next launch.");
SENTRY_LOG_DEBUG(@"Will start trace profile next launch.");
return (SentryLaunchProfileConfig) { YES, tracesSamplerDecision, profilesSamplerDecision };
}

Expand Down
93 changes: 0 additions & 93 deletions Sources/Sentry/Profiling/SentryLegacyProfiler.mm

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/Sentry/Profiling/SentryProfilerDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, SentryProfilerMode) {
SentryProfilerModeLegacy,
SentryProfilerModeTrace,
SentryProfilerModeContinuous,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SENTRY_EXTERN NSString *sentry_profilerTruncationReasonName(SentryProfilerTrunca
* will have different structures/objects available, these parameters are the common elements
* needed to construct the payload dictionary.
*/
SENTRY_EXTERN NSMutableDictionary<NSString *, id> *sentry_serializedProfileDataLegacy(
SENTRY_EXTERN NSMutableDictionary<NSString *, id> *sentry_serializedTraceProfileData(
NSDictionary<NSString *, id> *profileData, uint64_t startSystemTime, uint64_t endSystemTime,
NSString *truncationReason, NSDictionary<NSString *, id> *serializedMetrics,
NSArray<SentryDebugMeta *> *debugMeta, SentryHub *hub
Expand Down

0 comments on commit 37372a6

Please sign in to comment.