mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Merge pull request #3981 from vector-im/3957_nse_memory_log
Memory: The memory logger has been moved to the SDK
This commit is contained in:
commit
68eb9e3553
3 changed files with 6 additions and 88 deletions
|
@ -936,8 +936,6 @@
|
|||
ECB5D98F255420F8000AD89C /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB5D98E255420F8000AD89C /* Keychain.swift */; };
|
||||
ECB5D9902554221F000AD89C /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB5D98E255420F8000AD89C /* Keychain.swift */; };
|
||||
ECDC15F224AF41D2003437CF /* FormattedBodyParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECDC15F124AF41D2003437CF /* FormattedBodyParser.swift */; };
|
||||
ECE36F7F258B578300122124 /* Memory.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECE36F7E258B578300122124 /* Memory.swift */; };
|
||||
ECE36F80258B579900122124 /* Memory.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECE36F7E258B578300122124 /* Memory.swift */; };
|
||||
ECF57A4425090C23004BBF9D /* CreateRoomCoordinatorBridgePresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF57A3825090C23004BBF9D /* CreateRoomCoordinatorBridgePresenter.swift */; };
|
||||
ECF57A4525090C23004BBF9D /* CreateRoomCoordinatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF57A3925090C23004BBF9D /* CreateRoomCoordinatorType.swift */; };
|
||||
ECF57A4625090C23004BBF9D /* CreateRoomCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF57A3A25090C23004BBF9D /* CreateRoomCoordinator.swift */; };
|
||||
|
@ -2200,7 +2198,6 @@
|
|||
ECB101352477D00700CF8C11 /* UniversalLink.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UniversalLink.m; sourceTree = "<group>"; };
|
||||
ECB5D98E255420F8000AD89C /* Keychain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = "<group>"; };
|
||||
ECDC15F124AF41D2003437CF /* FormattedBodyParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormattedBodyParser.swift; sourceTree = "<group>"; };
|
||||
ECE36F7E258B578300122124 /* Memory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Memory.swift; sourceTree = "<group>"; };
|
||||
ECF57A3825090C23004BBF9D /* CreateRoomCoordinatorBridgePresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateRoomCoordinatorBridgePresenter.swift; sourceTree = "<group>"; };
|
||||
ECF57A3925090C23004BBF9D /* CreateRoomCoordinatorType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateRoomCoordinatorType.swift; sourceTree = "<group>"; };
|
||||
ECF57A3A25090C23004BBF9D /* CreateRoomCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateRoomCoordinator.swift; sourceTree = "<group>"; };
|
||||
|
@ -5601,7 +5598,6 @@
|
|||
EC2B4EF024A1EEBD005EB739 /* DataProtectionHelper.swift */,
|
||||
ECDC15F124AF41D2003437CF /* FormattedBodyParser.swift */,
|
||||
B158E72025485B9E000A7F75 /* Base32Coder.swift */,
|
||||
ECE36F7E258B578300122124 /* Memory.swift */,
|
||||
);
|
||||
path = Utils;
|
||||
sourceTree = "<group>";
|
||||
|
@ -6321,7 +6317,6 @@
|
|||
EC9A3EC624E1632C00A8CFAE /* PushNotificationStore.swift in Sources */,
|
||||
EC31F0952521FC4600D407DA /* PinCodePreferences.swift in Sources */,
|
||||
32FD757424D2BEF700BA7B37 /* InfoPlist.swift in Sources */,
|
||||
ECE36F80258B579900122124 /* Memory.swift in Sources */,
|
||||
ECB5D9902554221F000AD89C /* Keychain.swift in Sources */,
|
||||
EC31F09C2524AE1400D407DA /* BiometricsAuthenticationPresenter.swift in Sources */,
|
||||
EC85D752247C0F52002C44C9 /* UNUserNotificationCenter.swift in Sources */,
|
||||
|
@ -6909,7 +6904,6 @@
|
|||
B1B5574720EE6C4D00210D55 /* UsersDevicesViewController.m in Sources */,
|
||||
B1098BFF21ECFE65000DDA48 /* PasswordStrengthView.swift in Sources */,
|
||||
ECFBD5D2250A7AAF00DD5F5A /* ShowDirectoryViewState.swift in Sources */,
|
||||
ECE36F7F258B578300122124 /* Memory.swift in Sources */,
|
||||
B1B558D220EF768F00210D55 /* RoomEncryptedDataBubbleCell.m in Sources */,
|
||||
B10A3E8F24FE4368007C380F /* Timeline_1.swift in Sources */,
|
||||
EC711BB024A63B58008F830C /* SecureBackupBannerCell.swift in Sources */,
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
//
|
||||
// Copyright 2020 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Util class to log memory footprint and allocate memory for debugging purposes.
|
||||
@objcMembers
|
||||
class Memory: NSObject {
|
||||
|
||||
/// Memory formatter, uses exact 2 fraction digits and no grouping
|
||||
private static var numberFormatter: NumberFormatter {
|
||||
let formatter = NumberFormatter()
|
||||
formatter.alwaysShowsDecimalSeparator = true
|
||||
formatter.decimalSeparator = "."
|
||||
formatter.groupingSeparator = ""
|
||||
formatter.maximumFractionDigits = 2
|
||||
formatter.minimumFractionDigits = 2
|
||||
return formatter
|
||||
}
|
||||
|
||||
/// Details: https://developer.apple.com/forums/thread/105088
|
||||
/// - Returns: Current memory footprint
|
||||
private static func memoryFootprint() -> Float? {
|
||||
// The `TASK_VM_INFO_COUNT` and `TASK_VM_INFO_REV1_COUNT` macros are too
|
||||
// complex for the Swift C importer, so we have to define them ourselves.
|
||||
let TASK_VM_INFO_COUNT = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<integer_t>.size)
|
||||
guard let offset = MemoryLayout.offset(of: \task_vm_info_data_t.min_address) else {
|
||||
return nil
|
||||
}
|
||||
let TASK_VM_INFO_REV1_COUNT = mach_msg_type_number_t(offset / MemoryLayout<integer_t>.size)
|
||||
var info = task_vm_info_data_t()
|
||||
var count = TASK_VM_INFO_COUNT
|
||||
let kr = withUnsafeMutablePointer(to: &info) { infoPtr in
|
||||
infoPtr.withMemoryRebound(to: integer_t.self, capacity: Int(count)) { intPtr in
|
||||
task_info(mach_task_self_, task_flavor_t(TASK_VM_INFO), intPtr, &count)
|
||||
}
|
||||
}
|
||||
guard kr == KERN_SUCCESS, count >= TASK_VM_INFO_REV1_COUNT else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return Float(info.phys_footprint)
|
||||
}
|
||||
|
||||
/// Formatted memory footprint for debugging purposes
|
||||
/// - Returns: Memory footprint in MBs as a readable string
|
||||
static func formattedMemoryFootprint() -> String {
|
||||
let usedBytes = UInt64(self.memoryFootprint() ?? 0)
|
||||
let usedMB = Double(usedBytes) / 1024 / 1024
|
||||
guard let formattedStr = numberFormatter.string(from: NSNumber(value: usedMB)) else {
|
||||
return ""
|
||||
}
|
||||
return "\(formattedStr) MB"
|
||||
}
|
||||
|
||||
/// Allocates some memory
|
||||
/// - Parameter numberOfBytes: Amount of memory to be allocated, in number of bytes
|
||||
static func allocateMemoryOfSize(numberOfBytes: Int) {
|
||||
var buffer = [UInt8](repeating: 0, count: numberOfBytes)
|
||||
for i in 0 ..< numberOfBytes {
|
||||
buffer[i] = UInt8(i % 7)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -111,6 +111,7 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
|
||||
deinit {
|
||||
NSLog("[NotificationService] deinit for \(self)");
|
||||
self.logMemory()
|
||||
NSLog(" ")
|
||||
}
|
||||
|
||||
|
@ -118,7 +119,7 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
// MARK: - Private
|
||||
|
||||
private func logMemory() {
|
||||
NSLog("[NotificationService] Memory footprint: \(Memory.formattedMemoryFootprint())")
|
||||
NSLog("[NotificationService] Memory: footprint: \(MXMemory.formattedMemoryFootprint()) - available: \(MXMemory.formattedMemoryAvailable())")
|
||||
}
|
||||
|
||||
private func setupLogger() {
|
||||
|
@ -136,7 +137,11 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
self.userAccount = MXKAccountManager.shared()?.activeAccounts.first
|
||||
if let userAccount = userAccount {
|
||||
if NotificationService.backgroundSyncService == nil {
|
||||
NSLog("[NotificationService] setup: MXBackgroundSyncService init: BEFORE")
|
||||
self.logMemory()
|
||||
NotificationService.backgroundSyncService = MXBackgroundSyncService(withCredentials: userAccount.mxCredentials)
|
||||
NSLog("[NotificationService] setup: MXBackgroundSyncService init: AFTER")
|
||||
self.logMemory()
|
||||
}
|
||||
completion()
|
||||
} else {
|
||||
|
@ -210,9 +215,6 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
self.contentHandlers.removeValue(forKey: event.eventId)
|
||||
self.bestAttemptContents.removeValue(forKey: event.eventId)
|
||||
|
||||
// log memory again at the end of the process
|
||||
self.logMemory()
|
||||
|
||||
// We are done for this push
|
||||
NSLog("--------------------------------------------------------------------------------")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue