Skip to content

Instantly share code, notes, and snippets.

@kevsmith
Last active August 29, 2015 14:06
Show Gist options
  • Save kevsmith/8b096c74d5a4f5989d9d to your computer and use it in GitHub Desktop.
Save kevsmith/8b096c74d5a4f5989d9d to your computer and use it in GitHub Desktop.
Reading performance counters using LuaJIT and libstatsgrab
ksmith@abelson:build/(master✗) $ time dev/bin/loom_client ../demos/stats.lua
Host Info
---------------------------------
os_name: Linux
os_release: 3.13.0-30-generic
uptime: 3119735LL
bit_width: 64
max_cpus: 8
cpus: 8
os_version: #55-Ubuntu SMP Fri Jul 4 21:40:53 UTC 2014
host_name: abelson.home
platform: x86_64
host_state: physical_host
Load Stats
---------------------------------
avg_5min: 0.01
avg_15min: 0.05
avg_1min: 0
Memory Stats
---------------------------------
cache: 1790578688ULL
total: 33628286976ULL
free: 31328247808ULL
used: 2300039168ULL
CPU Stats
---------------------------------
soft_interrupts: 132271286ULL
user: 358038ULL
interrupts: 108911752ULL
iowait: 94104ULL
context_switches: 352637233ULL
swap: 0ULL
involuntary_conext_switches: 0ULL
voluntary_context_switches: 0ULL
total: 2495384026ULL
syscalls: 0ULL
idle: 2494145137ULL
nice: 43915ULL
kernel: 836936ULL
CPU %
---------------------------------
swap: 0
iowait: 0.0037711229622178
user: 0.014348012020175
idle: 99.950352771874
nice: 0.0017598493675698
kernel: 0.033539366737936
dev/bin/loom_client ../demos/stats.lua 0.01s user 0.00s system 92% cpu 0.014 total
>
local SEPARATOR = "---------------------------------"
local function print_stats(title, stats)
print(string.format("%s\n%s", title, SEPARATOR))
for k, v in pairs(stats) do
print(string.format(" %s: %s", k, v))
end
end
local pmon = require("perfmon/perfmon")
print_stats("Host Info", pmon:host_info())
print_stats("Load Stats", pmon:load_stats())
print_stats("Memory Stats", pmon:memory_stats())
cpu_stats = pmon:cpu_stats()
print_stats("CPU Stats", cpu_stats)
print_stats("CPU %", pmon:cpu_percentages(cpu_stats))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment