Skip to content

Commit 256877b

Browse files
Update
1 parent d8a47e7 commit 256877b

File tree

3 files changed

+74
-68
lines changed

3 files changed

+74
-68
lines changed

Project.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ version = "0.0.1"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
8+
MLDataDevices = "7e8f7934-dd98-4c1a-8fe8-92b47a384d40"
89
Term = "22787eb5-b846-44ae-b979-8e399b8463ab"
910
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
1011

1112
[weakdeps]
1213
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
1314

1415
[extensions]
15-
TerminalSystemMonitorCUDAExt = "CUDA"
16+
TerminalSystemMonitorCUDAExt = ["CUDA"]
1617

1718
[compat]
18-
CUDA = "5"
19+
CUDA = "5.5.2"
1920
Dates = "1"
21+
MLDataDevices = "1.5.3"
22+
Term = "2.0.6"
2023
UnicodePlots = "3.7.0"
2124
julia = "1"

ext/TerminalSystemMonitorCUDAExt/TerminalSystemMonitorCUDAExt.jl renamed to ext/TerminalSystemMonitorCUDAExt.jl/TerminalSystemMonitorCUDAExt.jl

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -44,69 +44,66 @@ using TerminalSystemMonitor: extract_number_and_unit
4444
└41s────────────────30s──────────────────20s─────────────────10s─────────────────0s┘
4545
"""
4646

47-
function plot_gpu_utilization_rates()
47+
function plot_gpu_utilization_rates(dev::CUDA.CuDevice)
48+
mig = uuid(dev) != parent_uuid(dev)
49+
nvml_dev = CUDA.NVML.Device(uuid(dev); mig)
50+
x = CUDA.NVML.name(nvml_dev)
51+
y = CUDA.NVML.utilization_rates(nvml_dev).compute # percent
52+
return barplot([x], [y], maximum = 100, width = max(5, 15))
53+
end
54+
55+
function plot_gpu_utilization_rates(::Type{CUDA.CuDevice})
4856
plts = []
4957
for dev in CUDA.devices()
50-
mig = uuid(dev) != parent_uuid(dev)
51-
nvml_dev = CUDA.NVML.Device(uuid(dev); mig)
52-
x = CUDA.NVML.name(nvml_dev)
53-
y = CUDA.NVML.utilization_rates(nvml_dev).compute # percent
54-
push!(plts, barplot([x], [y], maximum = 100, width = max(5, 15)))
58+
push!(plts, plot_gpu_utilization_rates(dev))
5559
end
56-
plts
60+
return plts
5761
end
5862

59-
function plot_gpu_memory_utilization(dev::CUDA.CuDevcie)
60-
device_name = CUDA.name(dev)
61-
mig = uuid(dev) != parent_uuid(dev)
62-
nvml_gpu = CUDA.NVML.Device(parent_uuid(dev))
63-
nvml_dev = CUDA.NVML.Device(uuid(dev); mig)
64-
x = CUDA.NVML.name(nvml_dev)
65-
device_capability = CUDA.NVML.compute_capability(nvml_dev)
66-
#@show CUDA.NVML.power_usage(nvml_dev) # watt
67-
y = CUDA.NVML.utilization_rates(nvml_dev).compute # percent
68-
#@show CUDA.NVML.temperature(nvml_dev)
69-
(; total, free, used) = CUDA.NVML.memory_info(nvml_dev)
63+
function plot_gpu_memory_utilization(dev::CUDA.CuDevice)
64+
device_name = CUDA.name(dev)
65+
mig = uuid(dev) != parent_uuid(dev)
66+
nvml_gpu = CUDA.NVML.Device(parent_uuid(dev))
67+
nvml_dev = CUDA.NVML.Device(uuid(dev); mig)
68+
x = CUDA.NVML.name(nvml_dev)
69+
device_capability = CUDA.NVML.compute_capability(nvml_dev)
70+
#@show CUDA.NVML.power_usage(nvml_dev) # watt
71+
y = CUDA.NVML.utilization_rates(nvml_dev).compute # percent
72+
#@show CUDA.NVML.temperature(nvml_dev)
73+
(; total, free, used) = CUDA.NVML.memory_info(nvml_dev)
7074

71-
memorytot, memorytotal_unit = eextract_number_and_unit(Base.format_bytes(total))
72-
memoryusage, memoryusage_unit = eextract_number_and_unit(Base.format_bytes(used))
75+
memorytot, memorytotal_unit = eextract_number_and_unit(Base.format_bytes(total))
76+
memoryusage, memoryusage_unit = eextract_number_and_unit(Base.format_bytes(used))
7377

74-
if memorytotal_unit == "GiB"
75-
# convert to MB
76-
memorytotal = memorytotal * 1024
77-
memorytotal_unit = "MiB"
78-
end
78+
if memorytotal_unit == "GiB"
79+
# convert to MB
80+
memorytotal = memorytotal * 1024
81+
memorytotal_unit = "MiB"
82+
end
7983

80-
if memoryusage_unit == "GiB"
81-
# convert to MB
82-
memoryusage = memoryusage * 1024
83-
memoryusage_unit = "MiB"
84-
end
84+
if memoryusage_unit == "GiB"
85+
# convert to MB
86+
memoryusage = memoryusage * 1024
87+
memoryusage_unit = "MiB"
88+
end
8589

86-
push!(
87-
plts,
88-
barplot(
89-
["GPU Mem: "],
90-
[memoryusage],
91-
xlabel=device_name,
92-
# Adds a space for better styling
93-
name=" $(memorytot) $(memoryunit)",
94-
maximum = memorytot,
95-
width = max(5, 15),
96-
),
97-
)
90+
return barplot(
91+
["GPU Mem: "],
92+
[memoryusage],
93+
xlabel = device_name,
94+
# Adds a space for better styling
95+
name = " $(memorytot) $(memoryunit)",
96+
maximum = memorytot,
97+
width = max(5, 15),
98+
)
9899
end
99100

100-
#=
101-
(; total, free) = CUDA.device!(dev) do
102-
(free=CUDA.free_memory(), total=CUDA.total_memory())
103-
end
104-
used = total - free
105-
device_name = name(dev)
106-
@show device_name
107-
@show extract_number_and_unit(Base.format_bytes(total))
108-
@show extract_number_and_unit(Base.format_bytes(free))
109-
@show extract_number_and_unit(Base.format_bytes(used))
110-
=#
101+
function plot_gpu_memory_utilization(::Type{CUDA.CuDevice})
102+
plts = []
103+
for dev in CUDA.devices()
104+
push!(plts, plot_gpu_memory_utilization(dev))
105+
end
106+
plts
107+
end
111108

112109
end # module TerminalSystemMonitorCUDAExt

src/TerminalSystemMonitor.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ module TerminalSystemMonitor
33
using Dates: Dates, Day, DateTime, Second
44
using UnicodePlots
55
import Term # this is required by UnicodePlots.panel
6+
using MLDataDevices: MLDataDevices
7+
8+
function plot_gpu_utilization_rates end
9+
function plot_gpu_memory_utilization end
610

711
idle_time(info::Sys.CPUinfo) = Int64(info.cpu_times!idle)
812

@@ -60,17 +64,17 @@ function unhidecursor()
6064
end
6165

6266
function extract_number_and_unit(str::AbstractString)
63-
m = match(r"(\d+\.\d+)\s*(\w+)", str)
64-
if !isnothing(m)
65-
return parse(Float64, m.captures[1]), m.captures[2]
66-
else
67-
return nothing, nothing
68-
end
67+
m = match(r"(\d+\.\d+)\s*(\w+)", str)
68+
if !isnothing(m)
69+
return parse(Float64, m.captures[1]), m.captures[2]
70+
else
71+
return nothing, nothing
72+
end
6973
end
7074

7175
function plot_cpu_utilization_rates()
7276
y = get_cpu_percent()
73-
npad = 1+floor(Int, log10(length(y)))
77+
npad = 1 + floor(Int, log10(length(y)))
7478
x = ["id: $(lpad(i-1, npad))" for (i, _) in enumerate(y)]
7579

7680
ncpus = length(y)
@@ -89,7 +93,8 @@ function plot_cpu_utilization_rates()
8993
end
9094

9195
function plot_cpu_memory_utilization()
92-
memorytot, memoryunit = Sys.total_memory() |> Base.format_bytes |> extract_number_and_unit
96+
memorytot, memoryunit =
97+
Sys.total_memory() |> Base.format_bytes |> extract_number_and_unit
9398
memoryfree, _ = Sys.free_memory() |> Base.format_bytes |> extract_number_and_unit
9499
memoryusage = memorytot - memoryfree
95100
memorytot = round(memorytot)
@@ -103,16 +108,17 @@ function plot_cpu_memory_utilization()
103108
barplot(
104109
["Mem: "],
105110
[memoryusage],
106-
xlabel= join(
111+
xlabel = join(
107112
[
108-
"Load average: " * join(string.(round.(Sys.loadavg(), digits=2)),' '),
113+
"Load average: " *
114+
join(string.(round.(Sys.loadavg(), digits = 2)), ' '),
109115
# Adds spaces for better styling
110116
" Uptime: $(max(Day(0), Day(datetime)-Day(1))), $(Dates.format(datetime, "HH:MM:SS"))",
111117
],
112118
'\n',
113119
),
114120
# Adds a space for better styling
115-
name=" $(memorytot) $(memoryunit)",
121+
name = " $(memorytot) $(memoryunit)",
116122
maximum = memorytot,
117123
width = max(5, 15),
118124
),
@@ -129,8 +135,8 @@ function main(dummyargs...)
129135
append!(plts, plot_cpu_utilization_rates())
130136
append!(plts, plot_cpu_memory_utilization())
131137
if isdefined(Main, :CUDA)
132-
append!(plts, TerminalSystemMonitorCUDAExt.plot_gpu_utilization_rates())
133-
append!(plts, TerminalSystemMonitorCUDAExt.plot_gpu_memory_utilization())
138+
append!(plts, plot_gpu_utilization_rates(MLDataDevices.CUDADevice))
139+
append!(plts, plot_gpu_memory_utilization(MLDataDevices.CUDADevice))
134140
end
135141
# adjust layout
136142
_, cols = displaysize(stdout)

0 commit comments

Comments
 (0)