Skip to content

Commit 3de9971

Browse files
authored
ref(profiling): prepare for new public continuous API (#3833)
1 parent e8114e4 commit 3de9971

File tree

10 files changed

+107
-130
lines changed

10 files changed

+107
-130
lines changed

Sentry.xcodeproj/project.pbxproj

+2-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
03BCC38A27E1BF49003232C7 /* SentryTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 03BCC38927E1BF49003232C7 /* SentryTime.h */; };
1212
03BCC38C27E1C01A003232C7 /* SentryTime.mm in Sources */ = {isa = PBXBuildFile; fileRef = 03BCC38B27E1C01A003232C7 /* SentryTime.mm */; };
1313
03BCC38E27E2A377003232C7 /* SentryProfilingConditionals.h in Headers */ = {isa = PBXBuildFile; fileRef = 03BCC38D27E2A377003232C7 /* SentryProfilingConditionals.h */; settings = {ATTRIBUTES = (Public, ); }; };
14-
03F84D1D27DD414C008FE43F /* SentryProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 03F84D1127DD414C008FE43F /* SentryProfiler.h */; };
1514
03F84D1E27DD414C008FE43F /* SentryBacktrace.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 03F84D1227DD414C008FE43F /* SentryBacktrace.hpp */; };
1615
03F84D1F27DD414C008FE43F /* SentryAsyncSafeLogging.h in Headers */ = {isa = PBXBuildFile; fileRef = 03F84D1327DD414C008FE43F /* SentryAsyncSafeLogging.h */; };
1716
03F84D2027DD414C008FE43F /* SentryStackBounds.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 03F84D1427DD414C008FE43F /* SentryStackBounds.hpp */; };
@@ -672,7 +671,6 @@
672671
8489B8882A5F7905009A055A /* SentryThreadWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8489B8872A5F7905009A055A /* SentryThreadWrapperTests.swift */; };
673672
849AC40029E0C1FF00889C16 /* SentryFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849AC3FF29E0C1FF00889C16 /* SentryFormatterTests.swift */; };
674673
84A5D75B29D5170700388BFA /* TimeInterval+Sentry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */; };
675-
84A888FD28D9B11700C51DFD /* SentryProfiler+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A888FC28D9B11700C51DFD /* SentryProfiler+Private.h */; };
676674
84A8891C28DBD28900C51DFD /* SentryDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8891A28DBD28900C51DFD /* SentryDevice.h */; };
677675
84A8891D28DBD28900C51DFD /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8891B28DBD28900C51DFD /* SentryDevice.mm */; };
678676
84A8892128DBD8D600C51DFD /* SentryDeviceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */; };
@@ -926,7 +924,6 @@
926924
03BCC38927E1BF49003232C7 /* SentryTime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTime.h; path = Sources/Sentry/include/SentryTime.h; sourceTree = SOURCE_ROOT; };
927925
03BCC38B27E1C01A003232C7 /* SentryTime.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryTime.mm; path = Sources/Sentry/SentryTime.mm; sourceTree = SOURCE_ROOT; };
928926
03BCC38D27E2A377003232C7 /* SentryProfilingConditionals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryProfilingConditionals.h; path = ../Public/SentryProfilingConditionals.h; sourceTree = "<group>"; };
929-
03F84D1127DD414C008FE43F /* SentryProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryProfiler.h; path = Sources/Sentry/include/SentryProfiler.h; sourceTree = SOURCE_ROOT; };
930927
03F84D1227DD414C008FE43F /* SentryBacktrace.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = SentryBacktrace.hpp; path = Sources/Sentry/include/SentryBacktrace.hpp; sourceTree = SOURCE_ROOT; };
931928
03F84D1327DD414C008FE43F /* SentryAsyncSafeLogging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryAsyncSafeLogging.h; path = Sources/Sentry/include/SentryAsyncSafeLogging.h; sourceTree = SOURCE_ROOT; };
932929
03F84D1427DD414C008FE43F /* SentryStackBounds.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = SentryStackBounds.hpp; path = Sources/Sentry/include/SentryStackBounds.hpp; sourceTree = SOURCE_ROOT; };
@@ -1605,6 +1602,7 @@
16051602
840B7EEE2BBF2B23008B8120 /* .ruby-version */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".ruby-version"; sourceTree = "<group>"; };
16061603
840B7EEF2BBF2B2B008B8120 /* .spi.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .spi.yml; sourceTree = "<group>"; };
16071604
840B7EF02BBF2B5F008B8120 /* MIGRATION.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = MIGRATION.md; sourceTree = "<group>"; };
1605+
840B7EF22BBF83DF008B8120 /* SentryProfiler+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryProfiler+Private.h"; path = "Sources/Sentry/include/SentryProfiler+Private.h"; sourceTree = SOURCE_ROOT; };
16081606
8419C0C328C1889D001C8259 /* SentryProfilerSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryProfilerSwiftTests.swift; sourceTree = "<group>"; };
16091607
84281C422A578E5600EE88F2 /* SentryProfilerState.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryProfilerState.mm; sourceTree = "<group>"; };
16101608
84281C442A57905700EE88F2 /* SentrySample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySample.h; path = ../include/SentrySample.h; sourceTree = "<group>"; };
@@ -1663,7 +1661,6 @@
16631661
849472842971C41A002603DE /* SentryNSTimerFactoryTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSTimerFactoryTest.swift; sourceTree = "<group>"; };
16641662
849AC3FF29E0C1FF00889C16 /* SentryFormatterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryFormatterTests.swift; sourceTree = "<group>"; };
16651663
84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeInterval+Sentry.swift"; sourceTree = "<group>"; };
1666-
84A888FC28D9B11700C51DFD /* SentryProfiler+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "SentryProfiler+Private.h"; path = "Sources/Sentry/include/SentryProfiler+Private.h"; sourceTree = SOURCE_ROOT; };
16671664
84A8891A28DBD28900C51DFD /* SentryDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = include/SentryDevice.h; sourceTree = "<group>"; };
16681665
84A8891B28DBD28900C51DFD /* SentryDevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDevice.mm; sourceTree = "<group>"; };
16691666
84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDeviceTests.mm; sourceTree = "<group>"; };
@@ -3286,9 +3283,8 @@
32863283
8454CF8B293EAF9A006AC140 /* SentryMetricProfiler.mm */,
32873284
84AF45A429A7FFA500FBB177 /* SentryProfiledTracerConcurrency.h */,
32883285
84AF45A529A7FFA500FBB177 /* SentryProfiledTracerConcurrency.mm */,
3289-
03F84D1127DD414C008FE43F /* SentryProfiler.h */,
3286+
840B7EF22BBF83DF008B8120 /* SentryProfiler+Private.h */,
32903287
03F84D2B27DD4191008FE43F /* SentryProfiler.mm */,
3291-
84A888FC28D9B11700C51DFD /* SentryProfiler+Private.h */,
32923288
0354A22A2A134D9C003C3A04 /* SentryProfilerState.h */,
32933289
84281C422A578E5600EE88F2 /* SentryProfilerState.mm */,
32943290
84281C642A57D36100EE88F2 /* SentryProfilerState+ObjCpp.h */,
@@ -3647,7 +3643,6 @@
36473643
8E4E7C7425DAAB49006AB9E2 /* SentrySpanProtocol.h in Headers */,
36483644
8EC4CF4A25C38DAA0093DEE9 /* SentrySpanStatus.h in Headers */,
36493645
8ECC673D25C23996000E2BF6 /* SentrySpanId.h in Headers */,
3650-
03F84D1D27DD414C008FE43F /* SentryProfiler.h in Headers */,
36513646
03F84D2227DD414C008FE43F /* SentryStackFrame.hpp in Headers */,
36523647
8ECC673E25C23996000E2BF6 /* SentrySpanContext.h in Headers */,
36533648
8ECC674025C23996000E2BF6 /* SentryTransactionContext.h in Headers */,
@@ -3712,7 +3707,6 @@
37123707
62862B1C2B1DDBC8009B16E3 /* SentryDelayedFrame.h in Headers */,
37133708
627E7589299F6FE40085504D /* SentryInternalDefines.h in Headers */,
37143709
7BE3C77B2446111500A38442 /* SentryRateLimitParser.h in Headers */,
3715-
84A888FD28D9B11700C51DFD /* SentryProfiler+Private.h in Headers */,
37163710
7D0637032382B34300B30749 /* SentryScope.h in Headers */,
37173711
03F84D2727DD414C008FE43F /* SentryMachLogging.hpp in Headers */,
37183712
63295AF51EF3C7DB002D4490 /* SentryNSDictionarySanitize.h in Headers */,

Sources/Sentry/PrivateSentrySDKOnly.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "SentryMeta.h"
1111
#import "SentryOptions.h"
1212
#import "SentryProfiledTracerConcurrency.h"
13-
#import "SentryProfiler.h"
13+
#import "SentryProfiler+Private.h"
1414
#import "SentrySDK+Private.h"
1515
#import "SentrySerialization.h"
1616
#import "SentrySwift.h"

Sources/Sentry/Profiling/SentryLaunchProfiling.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# import "SentryInternalDefines.h"
99
# import "SentryLog.h"
1010
# import "SentryOptions.h"
11-
# import "SentryProfiler.h"
11+
# import "SentryProfiler+Private.h"
1212
# import "SentryRandom.h"
1313
# import "SentrySamplerDecision.h"
1414
# import "SentrySampling.h"

Sources/Sentry/SentryFramesTracker.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# import "SentryDispatchQueueWrapper.h"
99
# import "SentryDisplayLinkWrapper.h"
1010
# import "SentryLog.h"
11-
# import "SentryProfiler.h"
11+
# import "SentryProfiler+Private.h"
1212
# import "SentryProfilingConditionals.h"
1313
# import "SentrySwift.h"
1414
# import "SentryTime.h"

Sources/Sentry/SentryTracer.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#if SENTRY_TARGET_PROFILING_SUPPORTED
3737
# import "SentryLaunchProfiling.h"
3838
# import "SentryProfiledTracerConcurrency.h"
39-
# import "SentryProfiler.h"
39+
# import "SentryProfiler+Private.h"
4040
#endif // SENTRY_TARGET_PROFILING_SUPPORTED
4141

4242
#if SENTRY_HAS_UIKIT

Sources/Sentry/include/SentryProfiler+Private.h

+85-17
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,106 @@
1-
#import "SentryProfiler.h"
21
#import "SentryProfilingConditionals.h"
32

43
#if SENTRY_TARGET_PROFILING_SUPPORTED
54

6-
@class SentryDebugMeta;
7-
@class SentryId;
8-
@class SentryProfilerState;
9-
@class SentrySample;
5+
# import "SentryCompiler.h"
6+
# import "SentrySpan.h"
7+
# import <Foundation/Foundation.h>
8+
9+
@class SentryEnvelopeItem;
1010
@class SentryHub;
11+
@class SentryProfilerState;
12+
@class SentryTransaction;
13+
1114
# if SENTRY_HAS_UIKIT
15+
@class SentryFramesTracker;
1216
@class SentryScreenFrames;
1317
# endif // SENTRY_HAS_UIKIT
14-
@class SentryTransaction;
18+
19+
typedef NS_ENUM(NSUInteger, SentryProfilerTruncationReason) {
20+
SentryProfilerTruncationReasonNormal,
21+
SentryProfilerTruncationReasonTimeout,
22+
SentryProfilerTruncationReasonAppMovedToBackground,
23+
};
1524

1625
NS_ASSUME_NONNULL_BEGIN
1726

18-
NSMutableDictionary<NSString *, id> *serializedProfileData(
19-
NSDictionary<NSString *, id> *profileData, uint64_t startSystemTime, uint64_t endSystemTime,
20-
NSString *truncationReason, NSDictionary<NSString *, id> *serializedMetrics,
21-
NSArray<SentryDebugMeta *> *debugMeta, SentryHub *hub
22-
# if SENTRY_HAS_UIKIT
23-
,
24-
SentryScreenFrames *gpuData
25-
# endif // SENTRY_HAS_UIKIT
26-
);
27+
SENTRY_EXTERN const int kSentryProfilerFrequencyHz;
28+
29+
SENTRY_EXTERN NSString *const kSentryProfilerSerializationKeySlowFrameRenders;
30+
SENTRY_EXTERN NSString *const kSentryProfilerSerializationKeyFrozenFrameRenders;
31+
SENTRY_EXTERN NSString *const kSentryProfilerSerializationKeyFrameRates;
32+
33+
SENTRY_EXTERN_C_BEGIN
2734

28-
@interface
29-
SentryProfiler ()
35+
/**
36+
* Disable profiling when running with TSAN because it produces a TSAN false positive, similar to
37+
* the situation described here: https://github.com/envoyproxy/envoy/issues/2561
38+
*/
39+
BOOL threadSanitizerIsPresent(void);
40+
41+
NSString *profilerTruncationReasonName(SentryProfilerTruncationReason reason);
42+
43+
SENTRY_EXTERN_C_END
44+
45+
/**
46+
* A wrapper around the low-level components used to gather sampled backtrace profiles.
47+
* @warning A main assumption is that profile start/stop must be contained within range of time of
48+
* the first concurrent transaction's start time and last one's end time.
49+
*/
50+
@interface SentryProfiler : NSObject
51+
52+
@property (strong, nonatomic) SentryId *profilerId;
3053

3154
@property (strong, nonatomic) SentryProfilerState *_state;
55+
3256
# if SENTRY_HAS_UIKIT
3357
@property (strong, nonatomic) SentryScreenFrames *_screenFrameData;
3458
# endif // SENTRY_HAS_UIKIT
3559

60+
/**
61+
* Start a profiler, if one isn't already running.
62+
*/
63+
+ (BOOL)startWithTracer:(SentryId *)traceId;
64+
65+
/**
66+
* Stop the profiler if it is running.
67+
*/
68+
- (void)stopForReason:(SentryProfilerTruncationReason)reason;
69+
70+
/**
71+
* Whether the profiler instance is currently running. If not, then it probably timed out or aborted
72+
* due to app backgrounding and is being kept alive while its associated transactions finish so they
73+
* can query for its profile data. */
74+
- (BOOL)isRunning;
75+
76+
/**
77+
* Whether there is any profiler that is currently running. A convenience method to query for this
78+
* information from other SDK components that don't have access to specific @c SentryProfiler
79+
* instances.
80+
*/
81+
+ (BOOL)isCurrentlyProfiling;
82+
83+
/**
84+
* Immediately record a sample of profiling metrics. Helps get full coverage of concurrent spans
85+
* when they're ended.
86+
*/
87+
+ (void)recordMetrics;
88+
89+
/**
90+
* Given a transaction, return an envelope item containing any corresponding profile data to be
91+
* attached to the transaction envelope.
92+
* */
93+
+ (nullable SentryEnvelopeItem *)createProfilingEnvelopeItemForTransaction:
94+
(SentryTransaction *)transaction
95+
startTimestamp:startTimestamp;
96+
97+
/**
98+
* Collect profile data corresponding with the given traceId and time period.
99+
* */
100+
+ (nullable NSMutableDictionary<NSString *, id> *)collectProfileBetween:(uint64_t)startSystemTime
101+
and:(uint64_t)endSystemTime
102+
forTrace:(SentryId *)traceId
103+
onHub:(SentryHub *)hub;
36104
@end
37105

38106
NS_ASSUME_NONNULL_END

Sources/Sentry/include/SentryProfiler.h

-98
This file was deleted.

Tests/SentryProfilerTests/SentryProfilerTests.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
using namespace sentry::profiling;
1717

18-
# import "SentryProfiler.h"
18+
# import "SentryProfiler+Private.h"
1919
# import <XCTest/XCTest.h>
2020
# import <execinfo.h>
2121

Tests/SentryTests/SentryProfiler+Test.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
#import "SentryProfiler.h"
21
#import "SentryProfilingConditionals.h"
32

43
#if SENTRY_TARGET_PROFILING_SUPPORTED
54

5+
# import "SentryProfiler+Private.h"
6+
7+
@class SentryDebugMeta;
8+
69
NS_ASSUME_NONNULL_BEGIN
710

811
@interface
912
SentryProfiler ()
1013

14+
NSMutableDictionary<NSString *, id> *serializedProfileData(
15+
NSDictionary<NSString *, id> *profileData, uint64_t startSystemTime, uint64_t endSystemTime,
16+
NSString *truncationReason, NSDictionary<NSString *, id> *serializedMetrics,
17+
NSArray<SentryDebugMeta *> *debugMeta, SentryHub *hub
18+
# if SENTRY_HAS_UIKIT
19+
,
20+
SentryScreenFrames *gpuData
21+
# endif // SENTRY_HAS_UIKIT
22+
);
23+
1124
+ (SentryProfiler *)getCurrentProfiler;
1225

1326
+ (void)resetConcurrencyTracking;

Tests/SentryTests/Transaction/SentryTracerObjCTests.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <XCTest/XCTest.h>
1010

1111
#if SENTRY_TARGET_PROFILING_SUPPORTED
12-
# import "SentryProfiler.h"
12+
# import "SentryProfiler+Private.h"
1313
#endif // SENTRY_TARGET_PROFILING_SUPPORTED
1414

1515
@interface SentryTracerObjCTests : XCTestCase

0 commit comments

Comments
 (0)