Kaynağa Gözat

track durations of the last 16 background fetches (#1508)

bjoern 3 yıl önce
ebeveyn
işleme
af7d3a216d

+ 18 - 2
deltachat-ios/AppDelegate.swift

@@ -444,19 +444,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in
             logger.info("⬅️ finishing fetch")
-
             guard let self = self else {
                 completionHandler(.failed)
                 return
             }
+
             if !self.appIsInForeground() {
                 self.dcAccounts.stopIo()
             }
 
             // to avoid 0xdead10cc exceptions, scheduled jobs need to be done before we get suspended;
             // we increase the probabilty that this happens by waiting a moment before calling completionHandler()
-            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
+            DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
                 logger.info("⬅️ fetch done")
+                guard let self = self else {
+                    completionHandler(.failed)
+                    return
+                }
+
+                self.pushToDebugArray(name: "notify-fetch-durations", value: Double(Date().timeIntervalSince1970)-nowTimestamp)
                 completionHandler(.newData)
 
                 if backgroundTask != .invalid {
@@ -563,6 +569,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         }
     }
 
+    private func pushToDebugArray(name: String, value: Double) {
+        let values = UserDefaults.standard.array(forKey: name)
+        var slidingValues = [Double]()
+        if values != nil, let values = values as? [Double] {
+            slidingValues = values.suffix(16)
+        }
+        slidingValues.append(value)
+        UserDefaults.standard.set(slidingValues, forKey: name)
+    }
+
     private func setStockTranslations() {
         let dcContext = dcAccounts.getSelected()
         dcContext.setStockTranslation(id: DC_STR_NOMESSAGES, localizationKey: "chat_no_messages")

+ 9 - 0
deltachat-ios/Controller/SettingsController.swift

@@ -698,6 +698,15 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
             info += "\(name)=\(cnt)x\(startStr)\(timestampStr)\n"
         }
 
+        info += "notify-fetch-durations="
+        let fetchDurations = UserDefaults.standard.array(forKey: "notify-fetch-durations")  as? [Double]
+        if let fetchDurations = fetchDurations {
+            for fetchDuration in fetchDurations {
+                info += String(format: "%.3fs ", fetchDuration)
+            }
+        }
+        info += "\n"
+
         var val = "?"
         switch UIApplication.shared.backgroundRefreshStatus {
         case .restricted: val = "restricted"