Skip to content

Commit

Permalink
Adds public methods to start / stop recording programmatically (witho…
Browse files Browse the repository at this point in the history
…ut tapping button)
  • Loading branch information
Christian Menschel committed Apr 15, 2016
1 parent bab6656 commit 1962c0c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
6 changes: 6 additions & 0 deletions HeapInspector/HINSPDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ NS_ASSUME_NONNULL_BEGIN
/// Stops the HeapInspector and removes the inspector's view
+ (void)stop;

// Shows HeapInspector (if not visible yet) and starts the record immediately
+ (void)startRecord;

// Stops record - but does not hide the HeapInspector
+ (void)stopRecord;

/// Add some (or only one) class prefix like `UI` OR `MK` to record classes that match the prefix only.
/// It's highly recommended to record a specific class or prefix -
/// otherwise all Cocoa classes will be recorded, which slows down the performance.
Expand Down
14 changes: 14 additions & 0 deletions HeapInspector/HINSPDebug.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ - (HINSPHeapStackTableViewController *)heapStackControllerWithHeapStack:(NSArray

- (void)stopRecord
{
_window.recordButton.isRecording = NO;
_recordedHeap = [HINSPHeapStackInspector recordedHeap];
[self showInfoLabel];
[NSObject endSnapshot];
Expand All @@ -128,6 +129,7 @@ - (void)beginRecord
_recordedHeap = nil;
[self resetInfoLabel];
[NSObject beginSnapshot];
_window.recordButton.isRecording = YES;
[HINSPHeapStackInspector performHeapShot];
}

Expand All @@ -138,6 +140,14 @@ + (void)start
twDebug = [[HINSPDebug alloc] init];
}

+ (void)startRecord
{
if (!twDebug) {
[self start];
}
[twDebug beginRecord];
}

+ (void)stop
{
[NSObject endSnapshot];
Expand All @@ -146,6 +156,10 @@ + (void)stop
twDebug = nil;
}

+ (void)stopRecord {
[twDebug stopRecord];
}

+ (void)addClassPrefixesToRecord:(NSArray <NSString *> *)classPrefixes
{
if (classPrefixes) {
Expand Down
2 changes: 1 addition & 1 deletion HeapInspector/HINSPRecordButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
#import <UIKit/UIKit.h>

@interface HINSPRecordButton : UIControl

@property (nonatomic) BOOL isRecording;
@end
20 changes: 12 additions & 8 deletions HeapInspector/HINSPRecordButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@


@interface HINSPRecordButton ()

@property (nonatomic) BOOL isRecording;
@property (nonatomic, weak) CAShapeLayer *shapeLayer;
@end

Expand All @@ -31,13 +29,19 @@ - (instancetype)initWithFrame:(CGRect)frame
- (void)tapped:(id)sender
{
self.isRecording = !self.isRecording;
UIColor *color = nil;
if (self.isRecording) {
color = [self recordingColor];
} else {
color = [self defaultColor];
}

- (void)setIsRecording:(BOOL)isRecording {
if (_isRecording != isRecording) {
_isRecording = isRecording;
UIColor *color = nil;
if (isRecording) {
color = [self recordingColor];
} else {
color = [self defaultColor];
}
_shapeLayer.fillColor = color.CGColor;
}
_shapeLayer.fillColor = color.CGColor;
}

#pragma mark - Setter
Expand Down

0 comments on commit 1962c0c

Please sign in to comment.