-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Graph and DebugServer API (#1)
* Update Graph and DebugServer API * Update DemoApp * Add DebugClientApp * DebugServer + graph/description complete * Update DebugServerMode * Update Package.swift * Add output info area * Update README
- Loading branch information
Showing
19 changed files
with
630 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// DebugServer.swift | ||
// | ||
// | ||
// Created by Kyle on 2024/1/21. | ||
// | ||
|
||
private import AttributeGraph | ||
import Foundation | ||
|
||
public final class DebugServer { | ||
private var server: UnsafeRawPointer? | ||
|
||
public static let shared = DebugServer() | ||
|
||
public func start(_ mode: Mode = .local) { | ||
server = debugServerStart(mode.rawValue) | ||
} | ||
|
||
public func stop() { | ||
debugServerStop() | ||
server = nil | ||
} | ||
|
||
public func run(timeout: Int) { | ||
guard let _ = server else { return } | ||
debugServerRun(timeout) | ||
} | ||
|
||
public var url: URL? { | ||
guard let _ = server, | ||
let url = debugServerCopyURL() as? URL | ||
else { return nil } | ||
return url | ||
} | ||
|
||
/// A Bool value indicating whether the server has been started successfully | ||
/// | ||
/// To make AttributeGraph start debugServer successfully, we need to pass its internal diagnostics check. | ||
/// In debug mode, add a symbolic breakpoint on `_ZN2AG11DebugServer5startEj`, run `start(_:)` and | ||
/// executable `reg write w0 1` after `os_variant_has_internal_diagnostics` call. | ||
public var startSuccess: Bool { | ||
server != nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// DebugServerCommand.swift | ||
// | ||
// | ||
// Created by Kyle on 2024/1/22. | ||
// | ||
|
||
extension DebugServer { | ||
public enum Command: String, CaseIterable, Hashable, Identifiable { | ||
case graphDescription = "graph/description" | ||
case profilerStart = "profiler/start" | ||
case profilerStop = "profiler/stop" | ||
case profilerReset = "profiler/reset" | ||
case profilerMark = "profiler/mark" | ||
|
||
public var id: String { rawValue } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Sources/AGDebugKit/DebugServer/DebugServerMessageHeader.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// DebugServerMessageHeader.swift | ||
// | ||
// | ||
// Created by Kyle on 2024/1/22. | ||
// | ||
|
||
extension DebugServer { | ||
public struct MessageHeader: Codable { | ||
public var token: UInt32 | ||
public var reserved: UInt32 | ||
public var length: UInt32 | ||
public var reserved2: UInt32 | ||
public init(token: UInt32, length: UInt32) { | ||
self.token = token | ||
self.reserved = 0 | ||
self.length = length | ||
self.reserved2 = 0 | ||
} | ||
|
||
public static var size: Int { MemoryLayout<Self>.size } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// DebugServerMode.swift | ||
// | ||
// | ||
// Created by Kyle on 2024/1/22. | ||
// | ||
|
||
extension DebugServer { | ||
/// The run mode of DebugServer | ||
/// | ||
public struct Mode: RawRepresentable, Hashable { | ||
public let rawValue: UInt | ||
|
||
public init(rawValue: UInt) { | ||
self.rawValue = rawValue | ||
} | ||
|
||
/// Localhost mode: example host is `127.0.0.1` | ||
public static let local = Mode(rawValue: 1) | ||
|
||
/// Network mode: example host is `192.168.8.230` | ||
public static let network = Mode(rawValue: 3) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Graph.swift | ||
// | ||
// | ||
// Created by Kyle on 2024/1/21. | ||
// | ||
|
||
private import AttributeGraph | ||
import Foundation | ||
|
||
/// A wrapper class for AGGraph | ||
public final class Graph { | ||
let graph: UnsafeRawPointer? | ||
|
||
public init() { | ||
graph = nil | ||
} | ||
|
||
public init(_ pointer: UnsafeRawPointer?) { | ||
graph = graphCreateShared(pointer) | ||
} | ||
|
||
public var dict: NSDictionary? { | ||
let options = ["format": "graph/dict"] as NSDictionary | ||
guard let description = graphDescription(options: options) else { | ||
return nil | ||
} | ||
return Unmanaged<NSDictionary>.fromOpaque(description).takeUnretainedValue() | ||
} | ||
|
||
public var dot: String? { | ||
let options = ["format": "graph/dot"] as NSDictionary | ||
guard let graph, | ||
let description = graphDescription(graph, options: options) | ||
else { | ||
return nil | ||
} | ||
return Unmanaged<NSString>.fromOpaque(description).takeUnretainedValue() as String | ||
} | ||
|
||
/// Archive the current AGGraph's state to temporary directory | ||
/// | ||
/// After calling the method, you will see the following message on Xcode console: | ||
/// | ||
/// Wrote graph data to "`$NSTemporaryDirectory()`+`name`". | ||
/// | ||
/// You can then consume the exported JSON file directly or via | ||
/// [GraphConverter](https://github.com/OpenSwiftUIProject/GraphConverter) | ||
public static func archiveGraph(name: String) { | ||
name.withCString { graphArchiveJSON($0) } | ||
} | ||
} |
Oops, something went wrong.