Skip to content

Commit

Permalink
Added logger, fixed notification related memory issue
Browse files Browse the repository at this point in the history
  • Loading branch information
deszip committed Mar 1, 2020
1 parent f257f48 commit 3096daf
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 72 deletions.
6 changes: 6 additions & 0 deletions Bitrise.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
D97355442402F980003FCE9B /* JetBrainsMono-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D973553C2402F980003FCE9B /* JetBrainsMono-Regular.ttf */; };
D97355452402F980003FCE9B /* JetBrainsMono-ExtraBold-Italic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D973553D2402F980003FCE9B /* JetBrainsMono-ExtraBold-Italic.ttf */; };
D9B2E7F123F94F5600C211F5 /* AMR_ANSIEscapeHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = D9B2E7F023F94F5600C211F5 /* AMR_ANSIEscapeHelper.m */; };
D9E44BA2240C2CCB00DE96A6 /* BRLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = D9E44BA1240C2CCB00DE96A6 /* BRLogger.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -333,6 +334,8 @@
D973553D2402F980003FCE9B /* JetBrainsMono-ExtraBold-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JetBrainsMono-ExtraBold-Italic.ttf"; sourceTree = "<group>"; };
D9B2E7EF23F94F5600C211F5 /* AMR_ANSIEscapeHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMR_ANSIEscapeHelper.h; sourceTree = "<group>"; };
D9B2E7F023F94F5600C211F5 /* AMR_ANSIEscapeHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMR_ANSIEscapeHelper.m; sourceTree = "<group>"; };
D9E44BA0240C2CCA00DE96A6 /* BRLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BRLogger.h; sourceTree = "<group>"; };
D9E44BA1240C2CCB00DE96A6 /* BRLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BRLogger.m; sourceTree = "<group>"; };
EB550FAE0B12AA5E5BBED2E8 /* libPods-Bitrise.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Bitrise.a"; sourceTree = BUILT_PRODUCTS_DIR; };
EDCC38F36C8ABB179E968B54 /* libPods-BitriseTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BitriseTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -643,6 +646,8 @@
isa = PBXGroup;
children = (
0E9F413720FEFA6A0083D646 /* BRMacro.h */,
D9E44BA0240C2CCA00DE96A6 /* BRLogger.h */,
D9E44BA1240C2CCB00DE96A6 /* BRLogger.m */,
0EDC5DDE21BBBB0A00AD41FE /* Queue */,
0EE1B85121B4363D005D5140 /* Collection Extensions */,
);
Expand Down Expand Up @@ -1032,6 +1037,7 @@
0E02C9AE22103ED100FCFE17 /* BRLogsDataSource.m in Sources */,
0EFB325C22020B5E0045C376 /* BRLogObserver.m in Sources */,
0E4AD0892205F9D200257E8E /* BRLogsRequest.m in Sources */,
D9E44BA2240C2CCB00DE96A6 /* BRLogger.m in Sources */,
0EBA9D6C2217F9EF007234EB /* BRLogInfo.m in Sources */,
0E52AB802242A4A60020A943 /* BRLogStorage.m in Sources */,
0EE1B85E21B4363D005D5140 /* NSSet+FRP.m in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Bitrise/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "AppDelegate.h"

#import "BRLogger.h"
#import "BRAnalytics.h"
#import "BRSyncCommand.h"
#import "BRMainController.h"
Expand All @@ -33,6 +34,7 @@ - (instancetype)init {
if (self = [super init]) {

#if DEBUG
[[BRLogger defaultLogger] setCurrentLogLevel:LL_VERBOSE];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints"];
#endif

Expand Down
6 changes: 4 additions & 2 deletions Bitrise/Container/BRContainerBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "BRContainerBuilder.h"

#import "BRLogger.h"

@implementation BRContainerBuilder

- (NSPersistentContainer *)buildContainer {
Expand All @@ -25,7 +27,7 @@ - (NSPersistentContainer *)buildContainerOfType:(NSString *)type {
NSError *error;
BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath:appDirectoryURL.path withIntermediateDirectories:NO attributes:nil error:&error];
if (!result) {
NSLog(@"Failed to create app directory: %@", error);
BRLog(LL_WARN, LL_STORAGE, @"Failed to create app directory: %@", error);
return nil;
}
}
Expand All @@ -37,7 +39,7 @@ - (NSPersistentContainer *)buildContainerOfType:(NSString *)type {
container.persistentStoreDescriptions = @[storeDescription];
[container loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
if (!storeDescription) {
NSLog(@"Failed to load store: %@", error);
BRLog(LL_WARN, LL_STORAGE, @"Failed to load store: %@", error);
}
}];

Expand Down
2 changes: 0 additions & 2 deletions Bitrise/Controller/Logs/BRLogsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ - (void)setBuildSlug:(NSString *)buildSlug {

[self.logDataSource bindTextView:self.logTextView];
[self.logDataSource fetch:self.buildSlug];

NSLog(@"Controller: %@, observer: %@", self, self.logObserver);
}

@end
2 changes: 1 addition & 1 deletion Bitrise/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1134</string>
<string>1148</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
11 changes: 4 additions & 7 deletions Bitrise/Networking/Commands/BRSyncCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
@interface BRSyncCommand ()

@property (strong, nonatomic, readonly) BRSyncEngine *syncEngine;
@property (strong, nonatomic, readonly) BRLogObserver *logObserver;
@property (strong, nonatomic, readonly) BREnvironment *environment;

@end

Expand All @@ -27,14 +25,13 @@ - (instancetype)initSyncEngine:(BRSyncEngine *)engine
environment:(BREnvironment *)environment {
if (self = [super init]) {
_syncEngine = engine;
_logObserver = logObserver;
_environment = environment;

__weak BRSyncCommand *weakSelf = self;
_syncEngine.syncCallback = ^(BRSyncResult *result) {
// Notifications
NSArray *builds = [result.diff.started arrayByAddingObjectsFromArray:result.diff.finished];
[weakSelf.environment postNotifications:builds forApp:result.app];
if (builds.count > 0) {
[environment postNotifications:builds forApp:result.app];
}

#if FEATURE_LIVE_LOG
// Logs observing
Expand All @@ -44,7 +41,7 @@ - (instancetype)initSyncEngine:(BRSyncEngine *)engine
}]];

[runningBuildsSlugs enumerateObjectsUsingBlock:^(NSString *buildSlug, BOOL *stop) {
[weakSelf.logObserver startObservingBuild:buildSlug];
[logObserver startObservingBuild:buildSlug];
}];
#endif

Expand Down
14 changes: 8 additions & 6 deletions Bitrise/Networking/LogObserver/ASLogLoadingOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "ASLogLoadingOperation.h"

#import "BRLogger.h"

#import "BRMacro.h"
#import "ASLogObservingOperation.h"
#import "BRBuildInfo.h"
Expand Down Expand Up @@ -52,7 +54,7 @@ - (void)start {
NSError *fetchError;
BRBuild *build = [self.storage buildWithSlug:self.buildSlug error:&fetchError];
if (!build) {
NSLog(@"ASLogLoadingOperation: failed to get build: %@", fetchError);
BRLog(LL_WARN, LL_STORAGE, @"ASLogLoadingOperation: failed to get build: %@", fetchError);
[self finish];
return;
}
Expand Down Expand Up @@ -83,7 +85,7 @@ - (void)finish {
}

- (void)loadLogs:(BRBuild *)build {
NSLog(@"ASLogLoadingOperation: fetching log: %@", self.buildSlug);
BRLog(LL_DEBUG, LL_STORAGE, @"ASLogLoadingOperation: fetching log: %@", self.buildSlug);
BRLogsRequest *request = [[BRLogsRequest alloc] initWithToken:build.app.account.token
appSlug:build.app.slug
buildSlug:build.slug since:[build.log.timestamp timeIntervalSince1970]];
Expand Down Expand Up @@ -111,7 +113,7 @@ - (void)loadLogs:(BRBuild *)build {

// Clean pervious logs
if (![self.storage cleanLogs:build error:&cleanError]) {
NSLog(@"Failed to clean build logs: %@", cleanError);
BRLog(LL_WARN, LL_STORAGE, @"Failed to clean build logs: %@", cleanError);
[self finish];
return;
}
Expand All @@ -123,9 +125,9 @@ - (void)loadLogs:(BRBuild *)build {
BOOL logMarked = [self.storage markBuildLog:build.log loaded:YES error:&markError];

if (metadataSaved && logSaved && logMarked) {
NSLog(@"ASLogLoadingOperation: %@ - log saved", self.buildSlug);
BRLog(LL_DEBUG, LL_STORAGE, @"ASLogLoadingOperation: %@ - log saved", self.buildSlug);
} else {
NSLog(@"ASLogLoadingOperation: Read log : %@\nSave log : %@\nMark loaded: %@", readingError, saveError, markError);
BRLog(LL_DEBUG, LL_STORAGE, @"ASLogLoadingOperation: Read log : %@\nSave log : %@\nMark loaded: %@", readingError, saveError, markError);
}

[self finish];
Expand All @@ -144,7 +146,7 @@ - (NSURL *)moveLogFile:(NSURL *)tmpURL {
targetURL = [targetURL URLByAppendingPathComponent:tmpURL.lastPathComponent];
BOOL moveResult = [[NSFileManager defaultManager] moveItemAtURL:tmpURL toURL:targetURL error:&moveError];
if (!moveResult) {
NSLog(@"Failed to move log file: %@", moveError);
BRLog(LL_WARN, LL_STORAGE, @"Failed to move log file: %@", moveError);
[super finish];
return nil;
}
Expand Down
14 changes: 8 additions & 6 deletions Bitrise/Networking/LogObserver/ASLogObservingOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "ASLogObservingOperation.h"

#import "BRLogger.h"

#import "BRBuild+CoreDataClass.h"
#import "BRBuildLog+CoreDataClass.h"
#import "BRLogsRequest.h"
Expand Down Expand Up @@ -71,7 +73,7 @@ - (void)fetchLogs {
NSError *fetchError;
BRBuild *build = [self.storage buildWithSlug:self.buildSlug error:&fetchError];
if (!build) {
NSLog(@"ASLogObservingOperation: failed to get build: %@", fetchError);
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: failed to get build: %@", fetchError);
[self finish];
return;
}
Expand All @@ -80,7 +82,7 @@ - (void)fetchLogs {
BRLogsRequest *request = [[BRLogsRequest alloc] initWithToken:build.app.account.token
appSlug:build.app.slug
buildSlug:build.slug since:fetchTime];
NSLog(@"ASLogObservingOperation: %@, request timestamp: %f", self, fetchTime);
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: %@, request timestamp: %f", self, fetchTime);
[self.api loadLogs:request completion:^(BRLogInfo *logInfo, NSError *error) {
if (logInfo.rawLog) {
NSError *saveError;
Expand All @@ -93,17 +95,17 @@ - (void)fetchLogs {

[self.receivedChunks addIndexes:[logInfo chunkPositions]];

NSLog(@"ASLogObservingOperation: got chunks: %lu, filtered: %lu", [logInfo.rawLog[@"log_chunks"] count], chunks.count);
NSLog(@"ASLogObservingOperation: got timestamp: %@", logInfo.rawLog[@"timestamp"]);
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: got chunks: %lu, filtered: %lu", [logInfo.rawLog[@"log_chunks"] count], chunks.count);
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: got timestamp: %@", logInfo.rawLog[@"timestamp"]);
}

if (build.log.archived) {
NSLog(@"ASLogObservingOperation: build log archived, build finished, stopping observing...");
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: build log archived, build finished, stopping observing...");
[self finish];
}

NSTimeInterval endTime = [[NSDate date] timeIntervalSince1970];
NSLog(@"ASLogObservingOperation: fetch time: %f sec.", endTime - startTime);
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: fetch time: %f sec.", endTime - startTime);
}];
}];
}
Expand Down
11 changes: 6 additions & 5 deletions Bitrise/Networking/LogObserver/BRLogObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "BRLogObserver.h"

#import "BRLogger.h"
#import "NSArray+FRP.h"

#import "ASQueue.h"
Expand Down Expand Up @@ -37,23 +38,23 @@ - (instancetype)initWithAPI:(BRBitriseAPI *)api storage:(BRStorage *)storage {

- (void)startObservingBuild:(NSString *)buildSlug {
@synchronized (self) {
NSLog(@"Observer: %@, build %@, started...", self, buildSlug);
BRLog(LL_DEBUG, LL_LOGSYNC, @"Observer: %@, build %@, started...", self, buildSlug);

if ([[self operationsForBuild:buildSlug] count] > 0) {
NSLog(@"BRLogObserver: has observing operation: %@, skipping...", buildSlug);
BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: has observing operation: %@, skipping...", buildSlug);
return;
}

ASLogObservingOperation *operation = [[ASLogObservingOperation alloc] initWithStorage:self.storage api:self.API buildSlug:buildSlug];
[self.queue addOperation:operation];
NSLog(@"BRLogObserver: added observing operation: %@", buildSlug);
BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: added observing operation: %@", buildSlug);
}
}

- (void)stopObservingBuild:(NSString *)buildSlug {
@synchronized (self) {
[[self operationsForBuild:buildSlug] enumerateObjectsUsingBlock:^(ASOperation <ASLogOperation> *operation, NSUInteger idx, BOOL *stop) {
NSLog(@"BRLogObserver: cancelling observing operation: %@", buildSlug);
BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: cancelling observing operation: %@", buildSlug);
[operation cancel];
}];
}
Expand All @@ -64,7 +65,7 @@ - (void)loadLogsForBuild:(NSString *)buildSlug callback:(BRLogLoadingCallback)ca
ASLogLoadingOperation *operation = [[ASLogLoadingOperation alloc] initWithStorage:self.storage api:self.API buildSlug:buildSlug];
[operation setLoadingCallback:callback];
[self.queue addOperation:operation];
NSLog(@"BRLogObserver: added load operation: %@", buildSlug);
BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: added load operation: %@", buildSlug);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Bitrise/Storage/BRStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import <EasyMapping/EasyMapping.h>

#import "BRLogger.h"
#import "NSArray+FRP.h"
#import "BRMacro.h"

Expand Down Expand Up @@ -197,7 +198,7 @@ - (BOOL)saveBuilds:(NSArray <BRBuildInfo *> *)buildsInfo forApp:(NSString *)appS
}];
result = [self saveContext:self.context error:error];
} else {
NSLog(@"Failed to save builds: %@", *error);
BRLog(LL_WARN, LL_STORAGE, @"Failed to save builds: %@", *error);
result = NO;
}

Expand Down
4 changes: 3 additions & 1 deletion Bitrise/Storage/Data Sources/BRAccountsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "BRAccountsDataSource.h"

#import "BRLogger.h"

#import <CoreData/CoreData.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "BTRAccount+CoreDataClass.h"
Expand Down Expand Up @@ -48,7 +50,7 @@ - (void)bind:(NSOutlineView *)outlineView {
- (void)fetch {
NSError *fetchError = nil;
if (![self.accountsFRC performFetch:&fetchError]) {
NSLog(@"Failed to fetch apps: %@", fetchError);
BRLog(LL_WARN, LL_STORAGE, @"Failed to fetch apps: %@", fetchError);
}
[self.outlineView reloadData];
}
Expand Down
4 changes: 3 additions & 1 deletion Bitrise/Storage/Data Sources/BRAppsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#import <CoreData/CoreData.h>

#import "BRLogger.h"

#import "BRAppCellView.h"
#import "BRBuildCellView.h"

Expand Down Expand Up @@ -63,7 +65,7 @@ - (NSFetchedResultsController *)buildBuildsFRC:(NSManagedObjectContext *)context
- (void)fetch {
NSError *fetchError = nil;
if (![self.buildsFRC performFetch:&fetchError]) {
NSLog(@"Failed to fetch builds: %@", fetchError);
BRLog(LL_WARN, LL_STORAGE, @"Failed to fetch builds: %@", fetchError);
}
[self.outlineView reloadData];
}
Expand Down
3 changes: 2 additions & 1 deletion Bitrise/Storage/Data Sources/BRLogsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import "BRLogsDataSource.h"

#import "BRLogger.h"
#import "BRMacro.h"
#import "BRLogLine+CoreDataClass.h"
#import "BRLogStep+CoreDataClass.h"
Expand Down Expand Up @@ -60,7 +61,7 @@ - (void)fetch:(NSString *)buildSlug {

NSError *fetchError = nil;
if (![self.logFRC performFetch:&fetchError]) {
NSLog(@"Failed to fetch logs: %@ - %@", buildSlug, fetchError);
BRLog(LL_WARN, LL_STORAGE, @"Failed to fetch logs: %@ - %@", buildSlug, fetchError);
}

[self updateContent];
Expand Down
Loading

0 comments on commit 3096daf

Please sign in to comment.