* Bump the RustSDK to v25.03.11 * Replace oidc login prompt with nil following the changes from https://github.com/matrix-org/matrix-rust-sdk/pull/4761 ``` /// * `prompt` - The desired user experience in the web UI. No value means /// that the user wishes to login into an existing account, and a value of /// `Create` means that the user wishes to register a new account. ``` * Fix trailing closure warnings * Update the client proxy after making `getNotificationSettings()` and `cachedAvatarUrl()` async (they used to be blocking on the rust side). * Move `Room.isEncrypted` to the info publisher and manually update the encryption state when creating the room. * Bump the SDK again to v25.03.12 - This introduces a new way to configure the tokio runtime that we can use to have extensions use less memory - introduce a new Target struct that takes care of setting up rust services (tracing and tokio) for our various targets - cleanup MXLog and friends * Address PR comments * Bump the SDK again, switch back to using `.consent` as the OIDC login prompt (which was reintroduced in matrix-org/matrix-rust-sdk/pull/4791)
71 lines
2.7 KiB
Swift
71 lines
2.7 KiB
Swift
//
|
|
// Copyright 2022-2024 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Foundation
|
|
import MatrixRustSDK
|
|
|
|
enum ExtensionLogger {
|
|
/// 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
|
|
}
|
|
|
|
private static var formattedMemoryAvailable: String {
|
|
let freeBytes = os_proc_available_memory()
|
|
let freeMB = Double(freeBytes) / 1024 / 1024
|
|
guard let formattedStr = numberFormatter.string(from: NSNumber(value: freeMB)) else {
|
|
return ""
|
|
}
|
|
return "\(formattedStr) MB"
|
|
}
|
|
|
|
/// Details: https://developer.apple.com/forums/thread/105088
|
|
/// - Returns: Current memory footprint
|
|
private static var 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 var formattedMemoryFootprint: String {
|
|
let usedBytes = UInt64(memoryFootprint ?? 0)
|
|
let usedMB = Double(usedBytes) / 1024 / 1024
|
|
guard let formattedStr = numberFormatter.string(from: NSNumber(value: usedMB)) else {
|
|
return ""
|
|
}
|
|
return "\(formattedStr) MB"
|
|
}
|
|
|
|
static func logMemory(with tag: String) {
|
|
MXLog.info("\(tag) Memory: footprint: \(formattedMemoryFootprint) - available: \(formattedMemoryAvailable)")
|
|
}
|
|
}
|