Skip to content

Commit bcb3d9a

Browse files
committed
Merge pull request ReactiveCocoa#1114 from ReactiveCocoa/signal-naming-envvar
Change RAC_DEBUG_SIGNAL_NAMES into an environment variable
2 parents 2a6caf4 + 381a366 commit bcb3d9a

File tree

8 files changed

+22
-26
lines changed

8 files changed

+22
-26
lines changed

Instruments/README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ To get started with a template, simply double-click it.
55

66
### Signal Names
77

8-
The `name` property of `RACSignal` is currently only functional in `DEBUG`
9-
builds, which means that you won't have access to meaningful names in
10-
Instruments if you're profiling a Release build.
8+
The `name` property of `RACSignal` requires that the `RAC_DEBUG_SIGNAL_NAMES`
9+
environment variable be set, which means that you won't have access to
10+
meaningful names in Instruments by default.
1111

12-
As a workaround, you can do one of the following:
13-
14-
1. Run your application (instead of using the Profile action), then ask
15-
Instruments to attach to the running process.
16-
2. In your application's scheme, set the Profile action to use the "Debug"
17-
configuration, then profile normally.
12+
To add signal names, open your application's scheme in Xcode, select the Profile
13+
action, and add `RAC_DEBUG_SIGNAL_NAMES` with a value of `1` to the list of
14+
environment variables.

ReactiveCocoaFramework/ReactiveCocoa/NSObject+RACDescription.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
@interface NSObject (RACDescription)
1212

13-
/// A simplified description of the receiver for Debug builds, which does not
14-
/// invoke -description (and thus should be much faster in many cases).
13+
/// A simplified description of the receiver, which does not invoke -description
14+
/// (and thus should be much faster in many cases).
1515
///
16-
/// This method will return a constant string in Release builds, skipping any
17-
/// work.
16+
/// This is for debugging purposes only, and will return a constant string
17+
/// unless the RAC_DEBUG_SIGNAL_NAMES environment variable is set.
1818
- (NSString *)rac_description;
1919

2020
@end

ReactiveCocoaFramework/ReactiveCocoa/NSObject+RACDescription.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
@implementation NSObject (RACDescription)
1313

1414
- (NSString *)rac_description {
15-
#ifdef DEBUG
16-
return [[NSString alloc] initWithFormat:@"<%@: %p>", self.class, self];
17-
#else
18-
return @"(description skipped)";
19-
#endif
15+
if (getenv("RAC_DEBUG_SIGNAL_NAMES") != NULL) {
16+
return [[NSString alloc] initWithFormat:@"<%@: %p>", self.class, self];
17+
} else {
18+
return @"(description skipped)";
19+
}
2020
}
2121

2222
@end

ReactiveCocoaFramework/ReactiveCocoa/NSObject+RACLifting.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ - (RACSignal *)rac_liftSelector:(SEL)selector withSignalsFromArray:(NSArray *)si
4343
return invocation.rac_returnValue;
4444
}]
4545
replayLast]
46-
setNameWithFormat:@"%@ -rac_liftSelector: %@ withSignalsFromArray: %@", [self rac_description], NSStringFromSelector(selector), signals];
46+
setNameWithFormat:@"%@ -rac_liftSelector: %s withSignalsFromArray: %@", [self rac_description], sel_getName(selector), signals];
4747
}
4848

4949
- (RACSignal *)rac_liftSelector:(SEL)selector withSignals:(RACSignal *)firstSignal, ... {
@@ -62,7 +62,7 @@ - (RACSignal *)rac_liftSelector:(SEL)selector withSignals:(RACSignal *)firstSign
6262

6363
return [[self
6464
rac_liftSelector:selector withSignalsFromArray:signals]
65-
setNameWithFormat:@"%@ -rac_liftSelector: %@ withSignals: %@", [self rac_description], NSStringFromSelector(selector), signals];
65+
setNameWithFormat:@"%@ -rac_liftSelector: %s withSignals: %@", [self rac_description], sel_getName(selector), signals];
6666
}
6767

6868
@end

ReactiveCocoaFramework/ReactiveCocoa/NSObject+RACSelectorSignal.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static void RACCheckTypeEncoding(const char *typeEncoding) {
181181
Class class = RACSwizzleClass(self);
182182
NSCAssert(class != nil, @"Could not swizzle class of %@", self);
183183

184-
subject = [[RACSubject subject] setNameWithFormat:@"%@ -rac_signalForSelector: %@", self.rac_description, NSStringFromSelector(selector)];
184+
subject = [[RACSubject subject] setNameWithFormat:@"%@ -rac_signalForSelector: %s", self.rac_description, sel_getName(selector)];
185185
objc_setAssociatedObject(self, aliasSelector, subject, OBJC_ASSOCIATION_RETAIN);
186186

187187
[self.rac_deallocDisposable addDisposable:[RACDisposable disposableWithBlock:^{

ReactiveCocoaFramework/ReactiveCocoa/RACScheduler.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ - (void)scheduleRecursiveBlock:(RACSchedulerRecursiveBlock)recursiveBlock adding
154154
// This doesn't actually need to be __block qualified, but Clang
155155
// complains otherwise. :C
156156
__block NSLock *lock = [[NSLock alloc] init];
157-
lock.name = [NSString stringWithFormat:@"%@ %@", self, NSStringFromSelector(_cmd)];
157+
lock.name = [NSString stringWithFormat:@"%@ %s", self, sel_getName(_cmd)];
158158

159159
__block NSUInteger rescheduleCount = 0;
160160

ReactiveCocoaFramework/ReactiveCocoa/RACStream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef RACStream * (^RACStreamBindBlock)(id value, BOOL *stop);
8282
/// Sets the name of the receiver to the given format string.
8383
///
8484
/// This is for debugging purposes only, and won't do anything unless the
85-
/// RAC_DEBUG_SIGNAL_NAMES preprocessor macro is defined.
85+
/// RAC_DEBUG_SIGNAL_NAMES environment variable is set.
8686
///
8787
/// Returns the receiver, for easy method chaining.
8888
- (instancetype)setNameWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2);

ReactiveCocoaFramework/ReactiveCocoa/RACStream.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ - (instancetype)zipWith:(RACStream *)stream {
4848
#pragma mark Naming
4949

5050
- (instancetype)setNameWithFormat:(NSString *)format, ... {
51-
#ifdef RAC_DEBUG_SIGNAL_NAMES
51+
if (getenv("RAC_DEBUG_SIGNAL_NAMES") == NULL) return self;
52+
5253
NSCParameterAssert(format != nil);
5354

5455
va_list args;
@@ -58,8 +59,6 @@ - (instancetype)setNameWithFormat:(NSString *)format, ... {
5859
va_end(args);
5960

6061
self.name = str;
61-
#endif
62-
6362
return self;
6463
}
6564

0 commit comments

Comments
 (0)