Skip to content

Instantly share code, notes, and snippets.


Kwarf/ Secret

Created February 10, 2015 18:22
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Kwarf/e2f7fcb0feb713fde5be to your computer and use it in GitHub Desktop.
Quick hack to benchmark Raspberry Pi 2
# !!! IMPORTANT !!!
# This is just something I threw together when benchmarking my Raspberry Pi 2
# don't expect it to work on anything else.
# Check out my blog post for more info:
# The graphs in the post were generated using the following commands:
# rrdtool graph pinetwork.png -W -s end-90s -e `rrdtool last pi.rrd` -w 900 -h 200 DEF:downbytes=pi.rrd:down:AVERAGE CDEF:down=downbytes,8,* AREA:down#00ff00:down DEF:upbytes=pi.rrd:up:AVERAGE CDEF:up=upbytes,8,* AREA:up#ff0000:up
# rrdtool graph picores.png -W -s end-90s -e `rrdtool last pi.rrd` -w 900 -h 200 -l 0 -u 100 -r DEF:core0=pi.rrd:core0:AVERAGE LINE:core0#ff0000:core0 DEF:core1=pi.rrd:core1:AVERAGE LINE:core1#00ff00:core1 DEF:core2=pi.rrd:core2:AVERAGE LINE:core2#0000ff:core2 DEF:core3=pi.rrd:core3:AVERAGE LINE:core3#ffff00:core3
# rrdtool graph piperf.png -W -s end-90s -e `rrdtool last pi.rrd` -w 900 -h 200 -l 0 -u 100 -r DEF:core0=pi.rrd:core0:AVERAGE DEF:core1=pi.rrd:core1:AVERAGE DEF:core2=pi.rrd:core2:AVERAGE DEF:core3=pi.rrd:core3:AVERAGE CDEF:cpu=core0,core1,+,core2,+,core3,+,4,/ LINE:cpu#00ff00:cpu DEF:mem=pi.rrd:mem:AVERAGE LINE:mem#0000ff:mem DEF:temp=pi.rrd:temp:AVERAGE LINE:temp#ff0000:temp
import os
import psutil
import rrdtool
import threading
FILENAME = "pi.rrd"
def core_temp():
path = "/sys/class/thermal/thermal_zone0/temp"
return int(open(path, "r").read()) / 1000
def tick():
threading.Timer(1, tick).start()
cpu = psutil.cpu_percent(percpu=True)
mem = psutil.phymem_usage().percent
temp = core_temp()
net = psutil.network_io_counters(pernic=True).get("eth0")
down = net.bytes_recv
up = net.bytes_sent
update_string = "N:{}:{}:{}:{}:{}:{}:{}:{}".format(
cpu[0], cpu[1], cpu[2], cpu[3], mem, temp, down, up
rrdtool.update(FILENAME, update_string)
# Create RRD database for 1 second log interval, 90 samples (1.5 minute)
"--step", "1",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment