Skip to content

Commit

Permalink
Update to v2.7.1 (#21)
Browse files Browse the repository at this point in the history
- Increase use of  `@autoreleasepool` to keep memory management tighter
 - Improve at launch perf by deferring the pruning of old files for `TLSRollingFileOutputStream`
 - Other miscellaneous bug fixes and cleanup
  • Loading branch information
NSProgrammer authored May 30, 2020
1 parent 8e251ca commit d42b485
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: objective-c
osx_image: xcode10.2
osx_image: xcode11.4
script:
./build.sh
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

## Info

**Document version:** 2.7.0
**Document version:** 2.7.1

**Last updated:** 06/28/2019
**Last updated:** 04/12/2020

**Author:** Nolan O'Brien

## History

### 2.7.1 (04/12/2020)

- Increase use of `@autoreleasepool` to keep memory management tighter
- Improve at launch perf by deferring the pruning of old files for `TLSRollingFileOutputStream`
- Other miscellaneous bug fixes and cleanup

### 2.7.0 (06/28/2019)

- Add support for capturing `os_log` logs executed within a running app.
Expand Down
2 changes: 1 addition & 1 deletion Classes/TLSDeclarations.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ - (NSString *)composeFormattedMessageWithOptions:(TLSComposeLogMessageInfoOption
}

// LEVEL
if (options & TLSComposeLogMessageInfoLogChannel) {
if (options & TLSComposeLogMessageInfoLogLevel) {
[mComposedMessage appendFormat:@"[%@]", TLSLogLevelToString(level)];
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/TLSLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class TLSLog {
line: Int = #line)
{
if (!TLSCanLog(nil, level, channel, context)) {
return;
return
}

TLSLogString(nil,
Expand Down
86 changes: 53 additions & 33 deletions Classes/TLSLoggingService.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,13 @@ static void _nonquickFilter_resetQuickFilter(SELF_ARG,
}

#if TLSCANLOGMODE == TLSCANLOGMODE_CHECKCACHED
dispatch_sync(self->_quickFilterQueue, ^{
self->_quickFilterLevels = SANITIZED_LEVEL(TLSLogLevelMaskAll);
[self->_quickFilterOffChannelsM removeAllObjects];
self->_quickFilterOutputStreamCount = outputStreamCount;
});
@autoreleasepool {
dispatch_sync(self->_quickFilterQueue, ^{
self->_quickFilterLevels = SANITIZED_LEVEL(TLSLogLevelMaskAll);
[self->_quickFilterOffChannelsM removeAllObjects];
self->_quickFilterOutputStreamCount = outputStreamCount;
});
}
#endif
}

Expand Down Expand Up @@ -317,21 +319,25 @@ static void _transaction_logExecute(SELF_ARG,
}
if (permittedStreams.count > 0) {
dispatch_async(self->_loggingQueue, ^{
for (id<TLSOutputStream> stream in permittedStreams) {
[stream tls_outputLogInfo:info];
@autoreleasepool {
for (id<TLSOutputStream> stream in permittedStreams) {
[stream tls_outputLogInfo:info];
}
}
});
}
#if TLSCANLOGMODE == TLSCANLOGMODE_CHECKCACHED
else if (exclusiveFiltering.streamEncountered && (exclusiveFiltering.channel || exclusiveFiltering.level)) {
dispatch_sync(self->_quickFilterQueue, ^{
if (exclusiveFiltering.channel) {
[self->_quickFilterOffChannelsM addObject:channel];
}
if (exclusiveFiltering.level) {
self->_quickFilterLevels &= ~(1 << level);
}
});
@autoreleasepool {
dispatch_sync(self->_quickFilterQueue, ^{
if (exclusiveFiltering.channel) {
[self->_quickFilterOffChannelsM addObject:channel];
}
if (exclusiveFiltering.level) {
self->_quickFilterLevels &= ~(1 << level);
}
});
}
}
#endif
}
Expand Down Expand Up @@ -376,11 +382,13 @@ static BOOL _canLog(SELF_ARG,

__block BOOL canLog = (nil != channel);
if (canLog) {
dispatch_sync(self->_quickFilterQueue, ^{
canLog = (self->_quickFilterOutputStreamCount > 0)
&& TLS_BITMASK_HAS_SUBSET_FLAGS(self->_quickFilterLevels, (1 << level))
&& ![self->_quickFilterOffChannelsM containsObject:channel];
});
@autoreleasepool {
dispatch_sync(self->_quickFilterQueue, ^{
canLog = (self->_quickFilterOutputStreamCount > 0)
&& TLS_BITMASK_HAS_SUBSET_FLAGS(self->_quickFilterLevels, (1 << level))
&& ![self->_quickFilterOffChannelsM containsObject:channel];
});
}
}
return canLog;

Expand Down Expand Up @@ -437,8 +445,10 @@ - (void)removeOutputStream:(id<TLSOutputStream>)stream
_nonquickFilter_resetQuickFilter(self, self->_streamsM.count);

dispatch_async(self->_loggingQueue, ^{
if ([stream respondsToSelector:@selector(tls_flush)]) {
[stream tls_flush];
@autoreleasepool {
if ([stream respondsToSelector:@selector(tls_flush)]) {
[stream tls_flush];
}
}
});
}
Expand Down Expand Up @@ -473,12 +483,18 @@ - (void)updateOutputStream:(id<TLSOutputStream>)stream

- (void)dispatchSynchronousTransaction:(dispatch_block_t)block
{
dispatch_sync(_transactionQueue, block);
@autoreleasepool {
dispatch_sync(_transactionQueue, block);
}
}

- (void)dispatchAsynchronousTransaction:(dispatch_block_t)block
{
dispatch_async(_transactionQueue, block);
dispatch_async(_transactionQueue, ^{
@autoreleasepool {
block();
}
});
}

- (void)flush
Expand All @@ -491,13 +507,15 @@ - (void)flush
}];

// get all log messages off the logging queue and then flush all output streams
dispatch_sync(_loggingQueue, ^{
for (id<TLSOutputStream> stream in streams) {
if ([stream respondsToSelector:@selector(tls_flush)]) {
[stream tls_flush];
@autoreleasepool {
dispatch_sync(_loggingQueue, ^{
for (id<TLSOutputStream> stream in streams) {
if ([stream respondsToSelector:@selector(tls_flush)]) {
[stream tls_flush];
}
}
}
});
});
}

/*
Expand Down Expand Up @@ -549,9 +567,11 @@ - (NSData *)retrieveLoggedDataFromOutputStream:(id<TLSOutputStream, TLSDataRetri
}

__block NSData *data;
dispatch_sync(_loggingQueue, ^{
data = [stream tls_retrieveLoggedData:maxBytes];
});
@autoreleasepool {
dispatch_sync(_loggingQueue, ^{
data = [stream tls_retrieveLoggedData:maxBytes];
});
}
return data;
}

Expand Down
21 changes: 15 additions & 6 deletions Classes/TLSRollingFileOutputStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ @interface TLSRollingFileOutputStream (Private)
@end

@implementation TLSRollingFileOutputStream
{
BOOL _hasRunPrune;
}

- (instancetype)initWithOutError:(NSError **)errorOut
{
Expand Down Expand Up @@ -149,10 +152,10 @@ - (instancetype)initWithLogFileDirectoryPath:(NSString *)logFileDirectoryPath
_maxBytesPerLogFile = maxBytesPerLogFile;
_maxLogFiles = maxLogFiles;
_logFilePrefix = [logFilePrefix copy];
_hasRunPrune = NO;

_purgeOldLogsIfNeeded(self);
[self tls_fileOutputEventFinished:TLSRollingFileOutputEventInitialize
info:@{ TLSRollingFileOutputEventKeyNewLogFilePath : _logFilePath }];
info:@{ TLSRollingFileOutputEventKeyNewLogFilePath : _logFilePath }];

} else if (!error) {
NSString *exceptionName = NSDestinationInvalidException;
Expand Down Expand Up @@ -194,7 +197,7 @@ - (void)outputLogData:(NSData *)data

[self tls_fileOutputEventFinished:TLSRollingFileOutputEventOutputLogData
info:info];
if (_rolloverIfNeeded(self)) {
if (_rolloverIfNeeded(self) || !_hasRunPrune) {
_purgeOldLogsIfNeeded(self);
}
}
Expand Down Expand Up @@ -354,6 +357,7 @@ static BOOL _purgeOldLogsIfNeeded(SELF_ARG)
return NO;
}

self->_hasRunPrune = YES;
NSArray<NSString *>* logs = _GetLogFiles(self);
BOOL purgeMade = NO;

Expand All @@ -364,15 +368,17 @@ static BOOL _purgeOldLogsIfNeeded(SELF_ARG)
NSCAssert(maxLogFiles > 0, @"Must have maximum number of log files be at least 1");
#endif

NSString *root = self.logFileDirectoryPath;
NSString *currentFile = self.logFilePath;

[self tls_fileOutputEventBegan:TLSRollingFileOutputEventPruneLogs
info:nil];

NSFileManager *fm = [NSFileManager defaultManager];
NSString *root = self.logFileDirectoryPath;
NSUInteger filesToDelete = logFileCount - maxLogFiles;
for (NSUInteger i = 0; i < logFileCount && 0 != filesToDelete; i++) {
NSString* nextLog = [root stringByAppendingPathComponent:[logs objectAtIndex:i]];
if ([nextLog isEqualToString:self.logFilePath]) {
if ([nextLog isEqualToString:currentFile]) {
// Ran out of logs to purge
break;
}
Expand Down Expand Up @@ -403,7 +409,10 @@ static BOOL _purgeOldLogsIfNeeded(SELF_ARG)
errInfo = errInfoM;
}
[self tls_fileOutputEventFailed:TLSRollingFileOutputEventPurgeLog
info:eventInfo error:[NSError errorWithDomain:domain code:code userInfo:errInfo]];
info:eventInfo
error:[NSError errorWithDomain:domain
code:code
userInfo:errInfo]];
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ AND the given log *channel* has not been cached as a known to be an *always off*

# License

Copyright 2013-2018 Twitter, Inc.
Copyright 2013-2020 Twitter, Inc.

Licensed under the Apache License, Version 2.0: https://www.apache.org/licenses/LICENSE-2.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// TwitterLoggingService.xcconfig
// TwitterLoggingService
//
// Copyright © 2018 Twitter. All rights reserved.
// Copyright © 2020 Twitter. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,3 +36,15 @@
// Arhitectures

ONLY_ACTIVE_ARCH = YES

//
// Build Options

// no need for dSYM when building Debug Configuration
DEBUG_INFORMATION_FORMAT = dwarf

//
// Swift Compiler Flags - Custom Flags

// when building for DEBUG, the DEBUG flag should be set
SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) DEBUG
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

APPLICATION_EXTENSION_API_ONLY = YES

// FB7419630 - unless dwarf-with-dsym explicitly set, no dSYM will be generated for mac catalyst build
DEBUG_INFORMATION_FORMAT[sdk=macosx*] = dwarf-with-dsym


//
// Deployment
Expand All @@ -49,9 +52,6 @@ SKIP_INSTALL = YES
DYLIB_INSTALL_NAME_BASE = @rpath
LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks

// necessary for ignoring undefined Crashlytics symbols that will be linked later
OTHER_LDFLAGS = $(inherited) "-Wl,-U,_CLSLog"


//
// Packaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// TwitterLoggingService.xcconfig
// TwitterLoggingService
//
// Copyright © 2018 Twitter. All rights reserved.
// Copyright © 2020 Twitter. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0

LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks

// necessary for ignoring undefined Crashlytics symbols that this Test target doesn't need
OTHER_LDFLAGS = $(inherited) "-Wl,-U,_CLSLog"


//
// Packaging
Expand All @@ -72,6 +69,13 @@ INFOPLIST_FILE = ${PRODUCT_NAME}/${PRODUCT_NAME}-Info.plist
PRODUCT_BUNDLE_IDENTIFIER = com.twitter.${PRODUCT_NAME:rfc1034identifier}
PRODUCT_NAME = ${TARGET_NAME}


// Signing

// This is the result of setting "Sign to run locally" in "Signing & Capabilities" for mac (catalyst)
CODE_SIGN_IDENTITY[sdk=macosx*] = -


//
// Swift Compiler - General

Expand Down
6 changes: 2 additions & 4 deletions TwitterLoggingService.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@
attributes = {
CLASSPREFIX = TLS;
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 1100;
LastUpgradeCheck = 1140;
ORGANIZATIONNAME = Twitter;
TargetAttributes = {
8B31CCEE1858CBC6008B0BF1 = {
Expand Down Expand Up @@ -1065,7 +1065,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3D82FF9E1E8DB3DC00D01B05 /* TwitterLoggingService.framework.xcconfig */;
buildSettings = {
DEBUG_INFORMATION_FORMAT = dwarf;
"DEBUG_INFORMATION_FORMAT[sdk=macosx*]" = dwarf;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
Expand Down Expand Up @@ -1101,7 +1101,6 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_VERSION = A;
MACOSX_DEPLOYMENT_TARGET = 10.10;
PUBLIC_HEADERS_FOLDER_PATH = "$(CONTENTS_FOLDER_PATH)/Headers";
Expand Down Expand Up @@ -1139,7 +1138,6 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "${PRODUCT_NAME}/${PRODUCT_NAME}-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1100"
LastUpgradeVersion = "1140"
version = "1.3">
<BuildAction
parallelizeBuildables = "NO"
Expand Down
Loading

0 comments on commit d42b485

Please sign in to comment.