Skip to content

Commit

Permalink
Update OpenGraph to add profile support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Feb 25, 2024
1 parent 8a145a4 commit bc0b3c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
"state" : {
"branch" : "main",
"revision" : "6133e9f737077b5c75ff33dee1c2c969cb5d91b4"
"revision" : "45bd9b86eb917e1bd56ead3ef51ca82beca94a70"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import Glibc
#elseif os(WASI)
import WASILibc
#endif
internal import OpenGraphShims

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) }
static var profile: LaunchProfileOptions { .init(rawValue: 1 << 1) }
}

private lazy var launchProfileOptions: LaunchProfileOptions = {
let env = getenv("SWIFTUI_PROFILE_LAUNCH")
let env = getenv("OPENSWIFTUI_PROFILE_LAUNCH")
if let env {
return .init(rawValue: atoi(env))
} else {
Expand All @@ -44,9 +44,8 @@ final class AppGraph: GraphHost {
guard !didCollectLaunchProfile else {
return
}

if launchProfileOptions.contains(.enable) {
// AGGraphStartProfiling
if launchProfileOptions.contains(.profile) {
OGGraph.startProfiling()
}
}

Expand All @@ -55,13 +54,12 @@ final class AppGraph: GraphHost {
return
}
didCollectLaunchProfile = true

if launchProfileOptions.contains(.enable) {
// AGGraphStopProfiling
if launchProfileOptions.contains(.profile) {
OGGraph.stopProfiling()
}

if launchProfileOptions.rawValue != 0 {
// AGGraphArchiveJSON
if !launchProfileOptions.isEmpty {
// /tmp/graph.ag-gzon
OGGraph.archiveJSON(name: nil)
}
}
}

0 comments on commit bc0b3c7

Please sign in to comment.