Add switch for memory pressure crash

This commit is contained in:
Ilya Laktyushin 2023-09-16 13:39:38 +04:00
parent 5ecb819963
commit 0eddafb9c2
3 changed files with 25 additions and 5 deletions

View File

@ -71,6 +71,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
case keepChatNavigationStack(PresentationTheme, Bool) case keepChatNavigationStack(PresentationTheme, Bool)
case skipReadHistory(PresentationTheme, Bool) case skipReadHistory(PresentationTheme, Bool)
case crashOnSlowQueries(PresentationTheme, Bool) case crashOnSlowQueries(PresentationTheme, Bool)
case crashOnMemoryPressure(PresentationTheme, Bool)
case clearTips(PresentationTheme) case clearTips(PresentationTheme)
case resetNotifications case resetNotifications
case crash(PresentationTheme) case crash(PresentationTheme)
@ -117,7 +118,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return DebugControllerSection.logs.rawValue return DebugControllerSection.logs.rawValue
case .logToFile, .logToConsole, .redactSensitiveData: case .logToFile, .logToConsole, .redactSensitiveData:
return DebugControllerSection.logging.rawValue return DebugControllerSection.logging.rawValue
case .keepChatNavigationStack, .skipReadHistory, .crashOnSlowQueries: case .keepChatNavigationStack, .skipReadHistory, .crashOnSlowQueries, .crashOnMemoryPressure:
return DebugControllerSection.experiments.rawValue return DebugControllerSection.experiments.rawValue
case .clearTips, .resetNotifications, .crash, .resetData, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .reindexUnread, .resetCacheIndex, .reindexCache, .resetBiometricsData, .resetWebViewCache, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .storiesExperiment, .storiesJpegExperiment, .playlistPlayback, .enableQuickReactionSwitch, .voiceConference, .experimentalCompatibility, .enableDebugDataDisplay, .acceleratedStickers, .inlineForums, .localTranscription, .enableReactionOverrides, .restorePurchases: case .clearTips, .resetNotifications, .crash, .resetData, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .reindexUnread, .resetCacheIndex, .reindexCache, .resetBiometricsData, .resetWebViewCache, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .storiesExperiment, .storiesJpegExperiment, .playlistPlayback, .enableQuickReactionSwitch, .voiceConference, .experimentalCompatibility, .enableDebugDataDisplay, .acceleratedStickers, .inlineForums, .localTranscription, .enableReactionOverrides, .restorePurchases:
return DebugControllerSection.experiments.rawValue return DebugControllerSection.experiments.rawValue
@ -166,8 +167,10 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return 15 return 15
case .crashOnSlowQueries: case .crashOnSlowQueries:
return 16 return 16
case .clearTips: case .crashOnMemoryPressure:
return 17 return 17
case .clearTips:
return 18
case .resetNotifications: case .resetNotifications:
return 19 return 19
case .crash: case .crash:
@ -933,6 +936,14 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return settings return settings
}).start() }).start()
}) })
case let .crashOnMemoryPressure(_, value):
return ItemListSwitchItem(presentationData: presentationData, title: "Crash on memory pressure", value: value, sectionId: self.section, style: .blocks, updated: { value in
let _ = updateExperimentalUISettingsInteractively(accountManager: arguments.sharedContext.accountManager, { settings in
var settings = settings
settings.crashOnMemoryPressure = value
return settings
}).start()
})
case .clearTips: case .clearTips:
return ItemListActionItem(presentationData: presentationData, title: "Clear Tips", kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { return ItemListActionItem(presentationData: presentationData, title: "Clear Tips", kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
let _ = (arguments.sharedContext.accountManager.transaction { transaction -> Void in let _ = (arguments.sharedContext.accountManager.transaction { transaction -> Void in
@ -1366,6 +1377,7 @@ private func debugControllerEntries(sharedContext: SharedAccountContext, present
#endif #endif
} }
entries.append(.crashOnSlowQueries(presentationData.theme, experimentalSettings.crashOnLongQueries)) entries.append(.crashOnSlowQueries(presentationData.theme, experimentalSettings.crashOnLongQueries))
entries.append(.crashOnMemoryPressure(presentationData.theme, experimentalSettings.crashOnMemoryPressure))
if isMainApp { if isMainApp {
entries.append(.clearTips(presentationData.theme)) entries.append(.clearTips(presentationData.theme))
entries.append(.resetNotifications) entries.append(.resetNotifications)

View File

@ -1488,7 +1488,9 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
#if targetEnvironment(simulator) #if targetEnvironment(simulator)
print("Debug memory") print("Debug memory")
#else #else
preconditionFailure() if self.contextValue?.context.sharedContext.immediateExperimentalUISettings.crashOnMemoryPressure == true {
preconditionFailure()
}
#endif #endif
} }
} }

View File

@ -52,6 +52,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
public var logLanguageRecognition: Bool public var logLanguageRecognition: Bool
public var storiesExperiment: Bool public var storiesExperiment: Bool
public var storiesJpegExperiment: Bool public var storiesJpegExperiment: Bool
public var crashOnMemoryPressure: Bool
public static var defaultSettings: ExperimentalUISettings { public static var defaultSettings: ExperimentalUISettings {
return ExperimentalUISettings( return ExperimentalUISettings(
@ -81,7 +82,8 @@ public struct ExperimentalUISettings: Codable, Equatable {
disableBackgroundAnimation: false, disableBackgroundAnimation: false,
logLanguageRecognition: false, logLanguageRecognition: false,
storiesExperiment: false, storiesExperiment: false,
storiesJpegExperiment: false storiesJpegExperiment: false,
crashOnMemoryPressure: false
) )
} }
@ -112,7 +114,8 @@ public struct ExperimentalUISettings: Codable, Equatable {
disableBackgroundAnimation: Bool, disableBackgroundAnimation: Bool,
logLanguageRecognition: Bool, logLanguageRecognition: Bool,
storiesExperiment: Bool, storiesExperiment: Bool,
storiesJpegExperiment: Bool storiesJpegExperiment: Bool,
crashOnMemoryPressure: Bool
) { ) {
self.keepChatNavigationStack = keepChatNavigationStack self.keepChatNavigationStack = keepChatNavigationStack
self.skipReadHistory = skipReadHistory self.skipReadHistory = skipReadHistory
@ -141,6 +144,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
self.logLanguageRecognition = logLanguageRecognition self.logLanguageRecognition = logLanguageRecognition
self.storiesExperiment = storiesExperiment self.storiesExperiment = storiesExperiment
self.storiesJpegExperiment = storiesJpegExperiment self.storiesJpegExperiment = storiesJpegExperiment
self.crashOnMemoryPressure = crashOnMemoryPressure
} }
public init(from decoder: Decoder) throws { public init(from decoder: Decoder) throws {
@ -173,6 +177,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
self.logLanguageRecognition = try container.decodeIfPresent(Bool.self, forKey: "logLanguageRecognition") ?? false self.logLanguageRecognition = try container.decodeIfPresent(Bool.self, forKey: "logLanguageRecognition") ?? false
self.storiesExperiment = try container.decodeIfPresent(Bool.self, forKey: "storiesExperiment") ?? false self.storiesExperiment = try container.decodeIfPresent(Bool.self, forKey: "storiesExperiment") ?? false
self.storiesJpegExperiment = try container.decodeIfPresent(Bool.self, forKey: "storiesJpegExperiment") ?? false self.storiesJpegExperiment = try container.decodeIfPresent(Bool.self, forKey: "storiesJpegExperiment") ?? false
self.crashOnMemoryPressure = try container.decodeIfPresent(Bool.self, forKey: "crashOnMemoryPressure") ?? false
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -205,6 +210,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
try container.encode(self.logLanguageRecognition, forKey: "logLanguageRecognition") try container.encode(self.logLanguageRecognition, forKey: "logLanguageRecognition")
try container.encode(self.storiesExperiment, forKey: "storiesExperiment") try container.encode(self.storiesExperiment, forKey: "storiesExperiment")
try container.encode(self.storiesJpegExperiment, forKey: "storiesJpegExperiment") try container.encode(self.storiesJpegExperiment, forKey: "storiesJpegExperiment")
try container.encode(self.crashOnMemoryPressure, forKey: "crashOnMemoryPressure")
} }
} }