Skip to content

Commit c5e6878

Browse files
Update
1 parent a129c0f commit c5e6878

File tree

3 files changed

+51
-30
lines changed

3 files changed

+51
-30
lines changed

Project.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
1111

1212
[weakdeps]
1313
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
14-
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
1514
MacOSIOReport = "27799fc1-e272-4181-9793-a9e1fcba685b"
1615

1716
[extensions]
1817
TerminalSystemMonitorCUDAExt = "CUDA"
19-
TerminalSystemMonitorMetalExt = ["Metal"]
20-
21-
[sources]
22-
MacOSIOReport = {url = "https://github.com/AtelierArith/MacOSIOReport.jl", rev="main"}
18+
TerminalSystemMonitorMacOSIOReportExt = "MacOSIOReport"
2319

2420
[compat]
2521
Aqua = "0.8.9"
@@ -28,15 +24,13 @@ Dates = "1"
2824
JET = "0.9.12"
2925
MLDataDevices = "1.5.3"
3026
MacOSIOReport = "0.1.0"
31-
Metal = "1.5.1"
3227
ReTestItems = "1.29.0"
3328
Term = "2.0.6"
3429
Test = "1"
3530
UnicodePlots = "3.7.0"
3631
julia = "1.10"
3732

3833
[extras]
39-
MacOSIOReport = "27799fc1-e272-4181-9793-a9e1fcba685b"
4034
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
4135
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
4236
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"

ext/TerminalSystemMonitorMetalExt/TerminalSystemMonitorMetalExt.jl renamed to ext/TerminalSystemMonitorMacOSIOReportExt/TerminalSystemMonitorMacOSIOReportExt.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
module TerminalSystemMonitorMetalExt
1+
module TerminalSystemMonitorMacOSIOReportExt
22

33
using MLDataDevices: MetalDevice
44
using UnicodePlots: barplot
55
import TerminalSystemMonitor
6-
using Metal: MTLDevice
7-
using MacOSIOReport: Sampler, get_metrics
6+
using MacOSIOReport: Sampler, get_metrics, MTLDevice
87
using TerminalSystemMonitor: extract_number_and_unit
98

109
function _plot_cpu_utilization_rates(id, usage)
@@ -40,4 +39,4 @@ function TerminalSystemMonitor.plot_gpu_utilization_rates(::Type{MetalDevice})
4039
return plts
4140
end
4241

43-
end # module TerminalSystemMonitorCUDAExt
42+
end # module TerminalSystemMonitorMacOSIOReportExt

src/TerminalSystemMonitor.jl

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,22 @@ function main(dummyargs...)
143143
try
144144
_, cols = displaysize(stdout)
145145
t1 = @async begin
146-
plts = []
147-
append!(plts, plot_cpu_utilization_rates(CPUDevice))
148-
n = max(1, cols ÷ 25)
149-
chunks = collect(Iterators.partition(plts, n))
150-
f = foldl(/, map(c -> prod(UnicodePlots.panel.(c)), chunks))
151-
152-
f /= prod(UnicodePlots.panel.(plot_cpu_memory_utilization(CPUDevice)))
153-
f
146+
try
147+
plts = []
148+
append!(plts, plot_cpu_utilization_rates(CPUDevice))
149+
n = max(1, cols ÷ 25)
150+
chunks = collect(Iterators.partition(plts, n))
151+
f = foldl(/, map(c -> prod(UnicodePlots.panel.(c)), chunks))
152+
153+
f /= prod(UnicodePlots.panel.(plot_cpu_memory_utilization(CPUDevice)))
154+
return f
155+
catch e
156+
if e isa InterruptException
157+
return nothing
158+
else
159+
rethrow(e)
160+
end
161+
end
154162
end
155163

156164
if isdefined(Main, :CUDA) &&
@@ -167,16 +175,39 @@ function main(dummyargs...)
167175
end
168176
gpuchunks = collect(Iterators.partition(cudaplts, n))
169177
f /= foldl(/, map(c -> prod(UnicodePlots.panel.(c)), gpuchunks))
170-
elseif isdefined(Main, :Metal) && Sys.isapple() && Sys.ARCH == :aarch64
178+
elseif isdefined(Main, :MacOSIOReport) && Sys.isapple() && Sys.ARCH == :aarch64
171179
metalplts = []
172180
n = max(1, cols ÷ 50)
173-
t2 = @async plot_cpu_utilization_rates(MetalDevice)
174-
t3 = @async plot_gpu_utilization_rates(MetalDevice)
181+
t2 = @async begin
182+
try
183+
return plot_cpu_utilization_rates(MetalDevice)
184+
catch e
185+
if e isa InterruptException
186+
return nothing
187+
else
188+
rethrow(e)
189+
end
190+
end
191+
end
192+
t3 = @async begin
193+
try
194+
return plot_gpu_utilization_rates(MetalDevice)
195+
catch e
196+
if e isa InterruptException
197+
return nothing
198+
else
199+
rethrow(e)
200+
end
201+
end
202+
end
175203
wait(t1)
176204
wait(t2)
177205
wait(t3)
178206
plts1 = fetch(t2)
179207
plts2 = fetch(t3)
208+
if isnothing(plts1) || isnothing(plts2)
209+
break
210+
end
180211
for i in eachindex(plts1)
181212
push!(metalplts, plts1[i])
182213
end
@@ -188,21 +219,18 @@ function main(dummyargs...)
188219
else
189220
wait(t1)
190221
f = fetch(t1)
222+
if isnothing(f)
223+
break
224+
end
191225
end
192226
clearlinesall()
193227
display(f)
194228
catch e
195229
unhidecursor() # unhide cursor
196-
if e isa InterruptException || e isa TaskFailedException
197-
@info "Intrrupted"
198-
break
199-
else
200-
@warn "Got Exception"
201-
rethrow(e) # so we don't swallow true exceptions
202-
end
230+
@warn "Got Exception"
231+
rethrow(e) # so we don't swallow true exceptions
203232
end
204233
end
205-
@info "Unhide cursor"
206234
unhidecursor() # unhide cursor
207235
end
208236

0 commit comments

Comments
 (0)