Skip to content

Commit

Permalink
Update AppGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Feb 25, 2024
1 parent c5be89b commit 8a145a4
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// AppGraph.swift
// OpenSwiftUI
//
// Created by Kyle on 2023/9/22.
// Lastest Version: iOS 15.5
// Status: WIP
// ID: A363922CEBDF47986D9772B903C8737A

#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif os(WASI)
import WASILibc
#endif

final class AppGraph: GraphHost {
static var shared: AppGraph? = nil
static var delegateBox: AnyFallbackDelegateBox? = nil

private struct LaunchProfileOptions: OptionSet {
let rawValue: Int32

static var enable: LaunchProfileOptions { .init(rawValue: 1 << 1) }
}

private lazy var launchProfileOptions: LaunchProfileOptions = {
let env = getenv("SWIFTUI_PROFILE_LAUNCH")
if let env {
return .init(rawValue: atoi(env))
} else {
return []
}
}()

var didCollectLaunchProfile: Bool = false

init(app _: some App) {}

func extendedLaunchTestName() -> String? { nil }

func startProfilingIfNecessary() {
guard !didCollectLaunchProfile else {
return
}

if launchProfileOptions.contains(.enable) {
// AGGraphStartProfiling
}
}

func stopProfilingIfNecessary() {
guard !didCollectLaunchProfile else {
return
}
didCollectLaunchProfile = true

if launchProfileOptions.contains(.enable) {
// AGGraphStopProfiling
}

if launchProfileOptions.rawValue != 0 {
// AGGraphArchiveJSON
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// FinishLaunchTestAction.swift
// OpenSwiftUI
//
// Created by Kyle on 2024/2/25.
// Lastest Version: iOS 15.5
// Status: Complete

#if os(iOS)
import UIKit
#elseif os(macOS)
import AppKit
#endif

struct FinishLaunchTestAction {
func callAsFunction() {
AppGraph.shared?.stopProfilingIfNecessary()
#if os(iOS)
UIApplication.shared.finishedTest(UIApplication.shared._launchTestName())
#else
fatalError("Unimplemented for other platform")
#endif
}
}

extension EnvironmentValues {
var finishLaunchTest: FinishLaunchTestAction {
FinishLaunchTestAction()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Lastest Version: iOS 15.5
// Status: WIP

#if canImport(Darwin)
import Foundation
#if OPENSWIFTUI_OPENCOMBINE
import OpenCombine
Expand Down Expand Up @@ -39,6 +38,10 @@ class FallbackDelegateBox<Delegate: NSObject>: AnyFallbackDelegateBox {
}

override var delegate: NSObject? {
// FIXME: error: constructing an object of class type 'Delegate' with a metatype value must use a 'required' initializer
#if !canImport(Darwin)
return nil
#else
switch storage {
case let .type(type):
let delegate = type.init()
Expand All @@ -47,6 +50,6 @@ class FallbackDelegateBox<Delegate: NSObject>: AnyFallbackDelegateBox {
case let .instance(delegate):
return delegate
}
#endif
}
}
#endif
12 changes: 9 additions & 3 deletions Sources/OpenSwiftUI/Test/_PerformanceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,30 @@ extension _BenchmarkHost {
public func _started(test: _PerformanceTest) {
#if os(iOS)
UIApplication.shared.startedTest(test.name)
#elseif os(macOS)
NSApplication.shared.startedTest(test.name)
#else
fatalError("TODO")
fatalError("Unimplemented for other platform")
#endif
}

public func _finished(test: _PerformanceTest) {
#if os(iOS)
UIApplication.shared.finishedTest(test.name)
#elseif os(macOS)
NSApplication.shared.finishedTest(test.name)
#else
fatalError("TODO")
fatalError("Unimplemented for other platform")
#endif
}

public func _failed(test: _PerformanceTest) {
#if os(iOS)
UIApplication.shared.failedTest(test.name, withFailure: nil)
#elseif os(macOS)
NSApplication.shared.failedTest(test.name, withFailure: nil)
#else
fatalError("TODO")
fatalError("Unimplemented for other platform")
#endif
}
}
10 changes: 8 additions & 2 deletions Sources/OpenSwiftUIShims/include/OpenSwiftUI_SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
- (void)startedTest:(nullable NSString *)name;
- (void)finishedTest:(nullable NSString *)name;
- (void)failedTest:(nullable NSString *)name withFailure:(nullable NSError*)failure;
- (nullable NSString *)_launchTestName;
@end
#elif __has_include(<AppKit/AppKit.h>)
#import <AppKit/AppKit.h>
@interface NSApplication (OpenSwiftUI_SPI)
- (void)startedTest:(nullable NSString *)name;
- (void)finishedTest:(nullable NSString *)name;
- (void)failedTest:(nullable NSString *)name withFailure:(nullable NSError*)failure;
@end
#else

#endif

#endif /* OpenSwiftUI_SPI_h */

0 comments on commit 8a145a4

Please sign in to comment.