Skip to content

Commit

Permalink
fix: fixed nettop CPU abnormal usage in some cases (#1854)
Browse files Browse the repository at this point in the history
  • Loading branch information
caobug authored Mar 24, 2024
1 parent 74462eb commit 5b51ef1
Showing 1 changed file with 14 additions and 0 deletions.
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 @@ internal class UsageReader: Reader<Network_Usage> {
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 Down Expand Up @@ -454,15 +461,22 @@ public class ProcessReader: Reader<[Network_Process]> {
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 Down

0 comments on commit 5b51ef1

Please sign in to comment.