perf(monitors): 复用网络接口元数据并一致读取路径状态
This commit is contained in:
@@ -2,7 +2,28 @@ import Foundation
|
||||
import Darwin
|
||||
|
||||
@main struct NetworkAddressChecks {
|
||||
static func checkBaselineChanges() {
|
||||
var monitor = NetworkMonitor()
|
||||
var time: TimeInterval = 0
|
||||
func next(_ metadata: NetworkMonitor.InterfaceMetadata) -> NetworkInterfaceMetrics {
|
||||
time += 1
|
||||
let bytes = UInt64(time) * 10
|
||||
return monitor.update(counters: ["en0": (bytes, bytes * 2)], metadata: ["en0": metadata], at: time)[0]
|
||||
}
|
||||
|
||||
for metadata in [NetworkMonitor.InterfaceMetadata(index: 1, addresses: ["192.0.2.1"], active: true),
|
||||
.init(index: 1, addresses: ["192.0.2.2"], active: true),
|
||||
.init(index: 2, addresses: ["192.0.2.2"], active: true),
|
||||
.init(index: 2, addresses: ["192.0.2.2"], active: false)] {
|
||||
let changed = next(metadata)
|
||||
precondition(changed.download == nil && changed.upload == nil)
|
||||
let stable = next(metadata)
|
||||
precondition(stable.download == 10 && stable.upload == 20)
|
||||
}
|
||||
}
|
||||
|
||||
static func main() {
|
||||
checkBaselineChanges()
|
||||
var buffer = [CChar](repeating: 0, count: Int(NI_MAXHOST))
|
||||
func check(_ address: UnsafePointer<sockaddr>) {
|
||||
var original = [CChar](repeating: 0, count: Int(NI_MAXHOST))
|
||||
|
||||
Reference in New Issue
Block a user