Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nettop may occupy CPU abnormally #1854

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Modules/Net/readers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,22 @@
let task = Process()
task.launchPath = "/usr/bin/nettop"
task.arguments = ["-P", "-L", "1", "-n", "-k", "time,interface,state,rx_dupe,rx_ooo,re-tx,rtt_avg,rcvsize,tx_win,tc_class,tc_mgt,cc_algo,P,C,R,W,arch"]
task.environment = [
"NSUnbufferedIO": "YES",
"LC_ALL": "en_US.UTF-8",

Check warning on line 249 in Modules/Net/readers.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Comma Violation: Collection literals should not have trailing commas (trailing_comma)
]

let inputPipe = Pipe()
let outputPipe = Pipe()
let errorPipe = Pipe()

defer {
inputPipe.fileHandleForWriting.closeFile()
outputPipe.fileHandleForReading.closeFile()
errorPipe.fileHandleForReading.closeFile()
}

task.standardInput = inputPipe
task.standardOutput = outputPipe
task.standardError = errorPipe

Expand All @@ -275,7 +282,7 @@
var totalUpload: Int64 = 0
var totalDownload: Int64 = 0
var firstLine = false
output.enumerateLines { (line, _) -> Void in

Check warning on line 285 in Modules/Net/readers.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Redundant Void Return Violation: Returning Void in a function declaration is redundant (redundant_void_return)
if !firstLine {
firstLine = true
return
Expand Down Expand Up @@ -454,15 +461,22 @@
let task = Process()
task.launchPath = "/usr/bin/nettop"
task.arguments = ["-P", "-L", "1", "-n", "-k", "time,interface,state,rx_dupe,rx_ooo,re-tx,rtt_avg,rcvsize,tx_win,tc_class,tc_mgt,cc_algo,P,C,R,W,arch"]
task.environment = [
"NSUnbufferedIO": "YES",
"LC_ALL": "en_US.UTF-8",

Check warning on line 466 in Modules/Net/readers.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Comma Violation: Collection literals should not have trailing commas (trailing_comma)
]

let inputPipe = Pipe()
let outputPipe = Pipe()
let errorPipe = Pipe()

defer {
inputPipe.fileHandleForWriting.closeFile()
outputPipe.fileHandleForReading.closeFile()
errorPipe.fileHandleForReading.closeFile()
}

task.standardInput = inputPipe
task.standardOutput = outputPipe
task.standardError = errorPipe

Expand All @@ -484,7 +498,7 @@

var list: [Network_Process] = []
var firstLine = false
output.enumerateLines { (line, _) -> Void in

Check warning on line 501 in Modules/Net/readers.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Redundant Void Return Violation: Returning Void in a function declaration is redundant (redundant_void_return)
if !firstLine {
firstLine = true
return
Expand Down
Loading