Skip to content

Commit 5ebc20c

Browse files
Add extension
1 parent c507351 commit 5ebc20c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module TerminalSystemMonitorMetalExt
2+
3+
using Metal
4+
using MLDataDevices: MetalDevice
5+
using UnicodePlots: barplot
6+
import TerminalSystemMonitor
7+
using MacOSIOReport: Sampler, get_metrics
8+
using TerminalSystemMonitor: extract_number_and_unit
9+
10+
function _plot_cpu_utilization_rates(id, usage)
11+
x = string(id)
12+
y = usage
13+
return barplot([x], [y], maximum = 100, width = 15)
14+
end
15+
16+
function TerminalSystemMonitor.plot_cpu_utilization_rates(::Type{MetalDevice})
17+
sampler = Sampler()
18+
msec = UInt(1000)
19+
m = get_metrics(sampler, msec)
20+
cpu_ids = ["E-CPU: ", "P-CPU: "]
21+
usages = [
22+
round(100 * m.ecpu_usage[2], digits = 1),
23+
round(100 * m.pcpu_usage[2], digits = 1),
24+
]
25+
return Any[barplot(cpu_ids, usages, maximum = 100, width = 15)]
26+
end
27+
28+
function TerminalSystemMonitor.plot_gpu_utilization_rates(::Type{MetalDevice})
29+
sampler = Sampler()
30+
msec = UInt(1000)
31+
m = get_metrics(sampler, msec)
32+
gpu_usages = [
33+
("GPU: ", round(100 * m.gpu_usage[2], digits = 1)),
34+
]
35+
plts = []
36+
for (id, usage) in gpu_usages
37+
push!(plts, _plot_cpu_utilization_rates(id, usage))
38+
end
39+
return plts
40+
end
41+
42+
end # module TerminalSystemMonitorCUDAExt

0 commit comments

Comments
 (0)