Skip to content
Snippets Groups Projects
Commit 12f43d4c authored by George Nachman's avatar George Nachman
Browse files

Add an advanced pref to log restorable state size info to /tmp. Issue 5623.

parent 0e3ae7b5
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -45,6 +45,7 @@
- (NSDictionary *)dictionaryByRemovingObjectForKey:(KeyType)key;
 
- (NSData *)propertyListData;
- (NSString *)sizeInfo;
 
@end
 
Loading
Loading
Loading
Loading
@@ -27,6 +27,39 @@ static NSString *const kHotKeyKeyCode = @"keyCode";
static NSString *const kHotKeyModifiers = @"modifiers";
static NSString *const kHotKeyModifierActivation = @"modifier activation";
 
@interface NSArray(SizeEstimation)
@end
@implementation NSArray(SizeEstimation)
- (NSInteger)addSizeInfoToSizes:(NSMutableDictionary<NSString *, NSNumber *> *)sizes
counts:(NSCountedSet<NSString *> *)counts
keypath:(NSString *)keypath {
__block NSInteger total = 0;
NSString *path = [keypath stringByAppendingString:@"[*]"];
[self enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSInteger size;
if ([obj respondsToSelector:_cmd]) {
size = [(id)obj addSizeInfoToSizes:sizes counts:counts keypath:path];
} else if ([obj isKindOfClass:[NSString class]]) {
size = [(NSString *)obj length] * 2;
} else if ([obj isKindOfClass:[NSData class]]) {
size = [(NSData *)obj length];
} else {
// Enough space for an isa and a word. This is number, date, or null.
size = 16;
}
total += size;
NSNumber *n = sizes[path];
n = @(n.integerValue + size);
sizes[path] = n;
[counts addObject:path];
}];
return total;
}
@end
@implementation NSDictionary (iTerm)
 
+ (NSDictionary *)dictionaryWithGridCoord:(VT100GridCoord)coord {
Loading
Loading
@@ -177,6 +210,45 @@ static NSString *const kHotKeyModifierActivation = @"modifier activation";
return data;
}
 
- (NSString *)sizeInfo {
NSMutableDictionary<NSString *, NSNumber *> *sizes = [NSMutableDictionary dictionary];
NSCountedSet<NSString *> *counts = [[[NSCountedSet alloc] init] autorelease];
sizes[@""] = @([self addSizeInfoToSizes:sizes counts:counts keypath:@""]);
[counts addObject:@""];
NSMutableString *result = [NSMutableString string];
[sizes enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSNumber * _Nonnull obj, BOOL * _Nonnull stop) {
[result appendFormat:@"%@ %@ %@\n", obj, @([counts countForObject:key]), key];
}];
return result;
}
- (NSInteger)addSizeInfoToSizes:(NSMutableDictionary<NSString *, NSNumber *> *)sizes
counts:(NSCountedSet<NSString *> *)counts
keypath:(NSString *)keypath {
__block NSInteger total = 0;
[self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
NSInteger size;
NSString *path = [keypath stringByAppendingFormat:@".%@", key];
if ([obj respondsToSelector:_cmd]) {
size = [(id)obj addSizeInfoToSizes:sizes counts:counts keypath:path];
} else if ([obj isKindOfClass:[NSString class]]) {
size = [(NSString *)obj length] * 2;
} else if ([obj isKindOfClass:[NSData class]]) {
size = [(NSData *)obj length];
} else {
// Enough space for an isa and a word. This is number, date, or null.
size = 16;
}
total += size;
NSNumber *n = sizes[path];
n = @(n.integerValue + size);
sizes[path] = n;
[counts addObject:path];
}];
return total;
}
@end
 
@implementation NSDictionary(HotKey)
Loading
Loading
Loading
Loading
@@ -7486,7 +7486,12 @@ ITERM_WEAKLY_REFERENCEABLE
}
 
- (void)window:(NSWindow *)window didDecodeRestorableState:(NSCoder *)state {
[self loadArrangement:[state decodeObjectForKey:kTerminalWindowStateRestorationWindowArrangementKey]
NSDictionary *arrangement = [state decodeObjectForKey:kTerminalWindowStateRestorationWindowArrangementKey];
if ([iTermAdvancedSettingsModel logRestorableStateSize]) {
NSString *log = [arrangement sizeInfo];
[log writeToFile:[NSString stringWithFormat:@"/tmp/statesize.window-%p.txt", self] atomically:NO encoding:NSUTF8StringEncoding error:nil];
}
[self loadArrangement:arrangement
sessions:nil];
self.restorableStateDecodePending = NO;
}
Loading
Loading
Loading
Loading
@@ -181,5 +181,6 @@
+ (BOOL)fullHeightCursor;
+ (BOOL)drawOutlineAroundCursor;
+ (double)underlineCursorOffset;
+ (BOOL)logRestorableStateSize;
 
@end
Loading
Loading
@@ -168,6 +168,7 @@ DEFINE_BOOL(performDNSLookups, YES, @"Semantic History: Perform DNS lookups to c
#pragma mark - Debugging
DEFINE_BOOL(startDebugLoggingAutomatically, NO, @"Debugging: Start debug logging automatically when iTerm2 is launched.");
DEFINE_BOOL(logDrawingPerformance, NO, @"Debugging: Log stats about text drawing performance to console.\nUsed for performance testing.");
DEFINE_BOOL(logRestorableStateSize, NO, @"Debugging: Log restorable state size info to /tmp/statesize.*.txt.");
 
#pragma mark - Session
DEFINE_BOOL(runJobsInServers, YES, @"Session: Enable session restoration.\nSession restoration runs jobs in separate processes. They will survive crashes, force quits, and upgrades.\nYou must restart iTerm2 for this change to take effect.");
Loading
Loading
Loading
Loading
@@ -790,15 +790,17 @@ static const NSTimeInterval kOneMonth = 30 * 24 * 60 * 60;
[[iTermURLStore sharedInstance] loadFromDictionary:urlStoreState];
}
 
NSArray *hotkeyWindowsStates = nil;
NSDictionary *legacyState = nil;
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"NSQuitAlwaysKeepsWindows"]) {
NSArray *hotkeyWindowsStates = [coder decodeObjectForKey:kHotkeyWindowsRestorableStates];
hotkeyWindowsStates = [coder decodeObjectForKey:kHotkeyWindowsRestorableStates];
if (hotkeyWindowsStates) {
// We have to create the hotkey window now because we need to attach to servers before
// launch finishes; otherwise any running hotkey window jobs will be treated as orphans.
[[iTermHotKeyController sharedInstance] createHiddenWindowsFromRestorableStates:hotkeyWindowsStates];
} else {
// Restore hotkey window from pre-3.1 version.
NSDictionary *legacyState = [coder decodeObjectForKey:kHotkeyWindowRestorableState];
legacyState = [coder decodeObjectForKey:kHotkeyWindowRestorableState];
if (legacyState) {
[[iTermHotKeyController sharedInstance] createHiddenWindowFromLegacyRestorableState:legacyState];
}
Loading
Loading
@@ -808,6 +810,15 @@ static const NSTimeInterval kOneMonth = 30 * 24 * 60 * 60;
if (finishedLaunching_) {
[self restoreBuriedSessionsState];
}
if ([iTermAdvancedSettingsModel logRestorableStateSize]) {
NSDictionary *dict = @{ kScreenCharRestorableStateKey: screenCharState ?: @{},
kURLStoreRestorableStateKey: urlStoreState ?: @{},
kHotkeyWindowsRestorableStates: hotkeyWindowsStates ?: @[],
kHotkeyWindowRestorableState: legacyState ?: @{},
iTermBuriedSessionState: _buriedSessionsState ?: @[] };
NSString *log = [dict sizeInfo];
[log writeToFile:[NSString stringWithFormat:@"/tmp/statesize.app-%p.txt", self] atomically:NO encoding:NSUTF8StringEncoding error:nil];
}
}
 
- (void)applicationDidResignActive:(NSNotification *)aNotification {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment