diff --git a/examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Sources/App/ContentView.swift b/examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Sources/App/ContentView.swift index f4788bdd31..9005a20d1a 100644 --- a/examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Sources/App/ContentView.swift +++ b/examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Sources/App/ContentView.swift @@ -33,7 +33,7 @@ struct ContentView: View { TopBar(title: "ExecuTorch Demo") ClassificationLabelView(controller: classificationController) Spacer() - ClassificationTimeView(controller: classificationController).hidden() + ClassificationTimeView(controller: classificationController) ModeSelector(controller: classificationController) } } diff --git a/examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Sources/MobileNet/MobileNetClassifier.swift b/examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Sources/MobileNet/MobileNetClassifier.swift index 15e680045e..b7a6e30a28 100644 --- a/examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Sources/MobileNet/MobileNetClassifier.swift +++ b/examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Sources/MobileNet/MobileNetClassifier.swift @@ -6,9 +6,12 @@ * LICENSE file in the root directory of this source tree. */ +import ExecuTorch import ImageClassification import UIKit +import os.log + public enum MobileNetClassifierError: Error { case inputPointer case rawData @@ -43,6 +46,16 @@ public class MobileNetClassifier: ImageClassification { mobileNetClassifier = ETMobileNetClassifier(filePath: modelFilePath) rawDataBuffer = [UInt8](repeating: 0, count: Int(Self.cropSize * Self.cropSize) * 4) normalizedBuffer = [Float](repeating: 0, count: rawDataBuffer.count / 4 * 3) + + #if DEBUG + Log.shared.add(sink: self) + #endif + } + + deinit { + #if DEBUG + Log.shared.remove(sink: self) + #endif } public func classify(image: UIImage) throws -> [Classification] { @@ -133,3 +146,24 @@ public class MobileNetClassifier: ImageClassification { return expInput.map { $0 / sumExpInput } } } + +#if DEBUG +extension MobileNetClassifier: LogSink { + public func log(level: LogLevel, timestamp: TimeInterval, filename: String, line: UInt, message: String) { + let logMessage = "executorch:\(filename):\(line) \(message)" + + switch level { + case .debug: + os_log(.debug, "%{public}@", logMessage) + case .info: + os_log(.info, "%{public}@", logMessage) + case .error: + os_log(.error, "%{public}@", logMessage) + case .fatal: + os_log(.fault, "%{public}@", logMessage) + default: + os_log("%{public}@", logMessage) + } + } +} +#endif diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchLog.h b/extension/apple/ExecuTorch/Exported/ExecuTorchLog.h index 9b6e77ff96..a71591c7ba 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchLog.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchLog.h @@ -59,14 +59,14 @@ NS_SWIFT_NAME(Log) * * @param sink The log sink to add. */ -- (void)addSink:(id)sink; +- (void)addSink:(id)sink NS_SWIFT_NAME(add(sink:)); /** * Removes a previously added log sink. * * @param sink The log sink to remove. */ -- (void)removeSink:(id)sink; +- (void)removeSink:(id)sink NS_SWIFT_NAME(remove(sink:)); + (instancetype)new NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;