-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(profiling): move test helpers to separate code unit (#3873)
- Loading branch information
1 parent
6e31b7c
commit 42f4107
Showing
10 changed files
with
125 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#import "SentryProfilerTestHelpers.h" | ||
|
||
#if SENTRY_TARGET_PROFILING_SUPPORTED | ||
|
||
# import "SentryFileManager.h" | ||
# import "SentryInternalDefines.h" | ||
# import "SentryLaunchProfiling.h" | ||
# import "SentrySerialization.h" | ||
|
||
BOOL | ||
sentry_threadSanitizerIsPresent(void) | ||
{ | ||
# if defined(__has_feature) | ||
# if __has_feature(thread_sanitizer) | ||
return YES; | ||
# pragma clang diagnostic push | ||
# pragma clang diagnostic ignored "-Wunreachable-code" | ||
# endif // __has_feature(thread_sanitizer) | ||
# endif // defined(__has_feature) | ||
|
||
return NO; | ||
} | ||
|
||
# if defined(TEST) || defined(TESTCI) || defined(DEBUG) | ||
|
||
void | ||
sentry_writeProfileFile(NSDictionary<NSString *, id> *payload) | ||
{ | ||
NSData *data = [SentrySerialization dataWithJSONObject:payload]; | ||
NSFileManager *fm = [NSFileManager defaultManager]; | ||
NSString *appSupportDirPath = sentryApplicationSupportPath(); | ||
|
||
if (![fm fileExistsAtPath:appSupportDirPath]) { | ||
SENTRY_LOG_DEBUG(@"Creating app support directory."); | ||
NSError *error; | ||
if (!SENTRY_CASSERT_RETURN([fm createDirectoryAtPath:appSupportDirPath | ||
withIntermediateDirectories:NO | ||
attributes:nil | ||
error:&error], | ||
@"Failed to create sentry app support directory")) { | ||
return; | ||
} | ||
} else { | ||
SENTRY_LOG_DEBUG(@"App support directory already exists."); | ||
} | ||
|
||
NSString *pathToWrite; | ||
if (sentry_isTracingAppLaunch) { | ||
SENTRY_LOG_DEBUG(@"Writing app launch profile."); | ||
pathToWrite = [appSupportDirPath stringByAppendingPathComponent:@"launchProfile"]; | ||
} else { | ||
SENTRY_LOG_DEBUG(@"Overwriting last non-launch profile."); | ||
pathToWrite = [appSupportDirPath stringByAppendingPathComponent:@"profile"]; | ||
} | ||
|
||
if ([fm fileExistsAtPath:pathToWrite]) { | ||
SENTRY_LOG_DEBUG(@"Already a %@ profile file present; make sure to remove them right after " | ||
@"using them, and that tests clean state in between so there isn't " | ||
@"leftover config producing one when it isn't expected.", | ||
sentry_isTracingAppLaunch ? @" launch" : @""); | ||
return; | ||
} | ||
|
||
SENTRY_LOG_DEBUG(@"Writing%@ profile to file.", sentry_isTracingAppLaunch ? @" launch" : @""); | ||
|
||
NSError *error; | ||
if (![data writeToFile:pathToWrite options:NSDataWritingAtomic error:&error]) { | ||
SENTRY_LOG_ERROR(@"Failed to write data to path %@: %@", pathToWrite, error); | ||
} | ||
} | ||
|
||
# endif // defined(TEST) || defined(TESTCI) || defined(DEBUG) | ||
|
||
#endif // SENTRY_TARGET_PROFILING_SUPPORTED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* These declarations are needed in both SDK and test code, for use with various testing scenarios. | ||
*/ | ||
|
||
#import "SentryProfilingConditionals.h" | ||
|
||
#if SENTRY_TARGET_PROFILING_SUPPORTED | ||
|
||
# import "SentryDefines.h" | ||
# import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* Disable profiling when running with TSAN because it produces a TSAN false positive, similar to | ||
* the situation described here: https://github.com/envoyproxy/envoy/issues/2561 | ||
*/ | ||
SENTRY_EXTERN BOOL sentry_threadSanitizerIsPresent(void); | ||
|
||
# if defined(TEST) || defined(TESTCI) || defined(DEBUG) | ||
|
||
/** | ||
* Write a file to application support containing the profile data. This is an affordance for UI | ||
* tests to be able to validate the contents of a profile. | ||
*/ | ||
SENTRY_EXTERN void sentry_writeProfileFile(NSDictionary<NSString *, id> *payload); | ||
|
||
# endif // defined(TEST) || defined(TESTCI) || defined(DEBUG) | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif // SENTRY_TARGET_PROFILING_SUPPORTED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters