Skip to content

Instantly share code, notes, and snippets.

@vjcitn
Created May 11, 2026 10:48
Show Gist options
  • Select an option

  • Save vjcitn/cd9f7ccb71d2e9ab7475eff9373cbdb9 to your computer and use it in GitHub Desktop.

Select an option

Save vjcitn/cd9f7ccb71d2e9ab7475eff9373cbdb9 to your computer and use it in GitHub Desktop.
use macmon to develop report on GPU usage on m4 mac
library(littleDeep)
library(processx)
tf = tempfile()
fstr = paste0(">>", tf)
#file.create(tf)
basecmd = sprintf("/Users/vincentcarey/INSTRUMENTATION/macmon/target/release/macmon")
pp = process$new(basecmd, c("pipe"), stdout=fstr)
suppress_keras_warnings()
r1 = run_cifar100(nEpochs=3)
pp$kill()
library(jsonlite)
z = readLines(tf)
library(jsonlite)
library(tibble)
library(dplyr)
library(purrr)
parse_macmon_record <- function(json_str) {
r <- fromJSON(json_str)
tibble(
timestamp = as.POSIXct(r$timestamp, format = "%Y-%m-%dT%H:%M:%OS", tz = "UTC"),
# Power (watts)
all_power = r$all_power,
sys_power = r$sys_power,
cpu_power = r$cpu_power,
gpu_power = r$gpu_power,
gpu_ram_power = r$gpu_ram_power,
ram_power = r$ram_power,
ane_power = r$ane_power,
# CPU utilization
cpu_usage_pct = r$cpu_usage_pct,
ecpu_freq_mhz = r$ecpu_usage[[1]],
ecpu_usage_ratio = r$ecpu_usage[[2]],
pcpu_freq_mhz = r$pcpu_usage[[1]],
pcpu_usage_ratio = r$pcpu_usage[[2]],
# GPU
gpu_freq_mhz = r$gpu_usage[[1]],
gpu_usage_ratio = r$gpu_usage[[2]],
# Memory (convert bytes -> GB)
ram_total_gb = r$memory$ram_total / 1e9,
ram_used_gb = r$memory$ram_usage / 1e9,
swap_total_gb = r$memory$swap_total / 1e9,
swap_used_gb = r$memory$swap_usage / 1e9,
# Temperature
cpu_temp_c = r$temp$cpu_temp_avg,
gpu_temp_c = r$temp$gpu_temp_avg
)
}
# For a vector of JSONL lines (e.g. from readLines()):
# records <- readLines("macmon_log.jsonl")
# df <- map(records, parse_macmon_record) |> list_rbind()
df <- map(z, parse_macmon_record) |> list_rbind()
glimpse(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment