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 skipReadHistory(PresentationTheme, Bool)
case crashOnSlowQueries(PresentationTheme, Bool)
case crashOnMemoryPressure(PresentationTheme, Bool)
case clearTips(PresentationTheme)
case resetNotifications
case crash(PresentationTheme)
@ -117,7 +118,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return DebugControllerSection.logs.rawValue
case .logToFile, .logToConsole, .redactSensitiveData:
return DebugControllerSection.logging.rawValue
case .keepChatNavigationStack, .skipReadHistory, .crashOnSlowQueries:
case .keepChatNavigationStack, .skipReadHistory, .crashOnSlowQueries, .crashOnMemoryPressure:
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:
return DebugControllerSection.experiments.rawValue
@ -166,8 +167,10 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return 15
case .crashOnSlowQueries:
return 16
case .clearTips:
case .crashOnMemoryPressure:
return 17
case .clearTips:
return 18
case .resetNotifications:
return 19
case .crash:
@ -933,6 +936,14 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return settings
}).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:
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
@ -1366,6 +1377,7 @@ private func debugControllerEntries(sharedContext: SharedAccountContext, present
#endif
}
entries.append(.crashOnSlowQueries(presentationData.theme, experimentalSettings.crashOnLongQueries))
entries.append(.crashOnMemoryPressure(presentationData.theme, experimentalSettings.crashOnMemoryPressure))
if isMainApp {
entries.append(.clearTips(presentationData.theme))
entries.append(.resetNotifications)

View File

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

View File

@ -52,6 +52,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
public var logLanguageRecognition: Bool
public var storiesExperiment: Bool
public var storiesJpegExperiment: Bool
public var crashOnMemoryPressure: Bool
public static var defaultSettings: ExperimentalUISettings {
return ExperimentalUISettings(
@ -81,7 +82,8 @@ public struct ExperimentalUISettings: Codable, Equatable {
disableBackgroundAnimation: false,
logLanguageRecognition: false,
storiesExperiment: false,
storiesJpegExperiment: false
storiesJpegExperiment: false,
crashOnMemoryPressure: false
)
}
@ -112,7 +114,8 @@ public struct ExperimentalUISettings: Codable, Equatable {
disableBackgroundAnimation: Bool,
logLanguageRecognition: Bool,
storiesExperiment: Bool,
storiesJpegExperiment: Bool
storiesJpegExperiment: Bool,
crashOnMemoryPressure: Bool
) {
self.keepChatNavigationStack = keepChatNavigationStack
self.skipReadHistory = skipReadHistory
@ -141,6 +144,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
self.logLanguageRecognition = logLanguageRecognition
self.storiesExperiment = storiesExperiment
self.storiesJpegExperiment = storiesJpegExperiment
self.crashOnMemoryPressure = crashOnMemoryPressure
}
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.storiesExperiment = try container.decodeIfPresent(Bool.self, forKey: "storiesExperiment") ?? 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 {
@ -205,6 +210,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
try container.encode(self.logLanguageRecognition, forKey: "logLanguageRecognition")
try container.encode(self.storiesExperiment, forKey: "storiesExperiment")
try container.encode(self.storiesJpegExperiment, forKey: "storiesJpegExperiment")
try container.encode(self.crashOnMemoryPressure, forKey: "crashOnMemoryPressure")
}
}