Skip to content
Snippets Groups Projects
Commit a28e5908 authored by Jari-Matti Mäkelä's avatar Jari-Matti Mäkelä
Browse files

Update examples

parent 2fe3d15c
No related branches found
No related tags found
No related merge requests found
Pipeline #86735 passed
Showing
with 257 additions and 131 deletions
---
name: Client script example
author: Captain Planet
---
This folder contains client side scripts for interfacing
with PowerGoblin, without the client library.
HOST=localhost:8080
msg_get() {
curl "http://$HOST/api/v2/$*"
echo
}
msg_post_file() {
curl --data-binary "@$1" "http://$HOST/api/v2/$2"
echo
}
if [ ! -e "collected.zip" ]; then
echo Need a collectd.zip to run. Either use the one from the test directory or generate a new file.
exit 1
fi
msg_get cmd/startSession
msg_post_file collected.zip session/latest/import/collectd
msg_get session/latest/sync/`date +%s%N`
msg_get session/latest/close
msg_get session/latest/store
......@@ -3,25 +3,26 @@
# API v1 (PowerGoblin 1.x aka old version)
#
# The script should be run on the same system.
# Adjust the HOST parameter if necessary
# Requires 'curl'.
# Adjust the HOST parameter if necessary.
HOST=localhost:8080
msg_get() {
pg_get() {
curl "http://$HOST/$*"
}
msg_get api/v1/measurement/start/TestScenario1
msg_get api/v1/meter/rename/SP3-99%20IN/PSU
msg_get api/v1/measurement/rename/Dummy%20test
msg_get api/v1/run/start/sut
pg_get api/v1/measurement/start/TestScenario1
pg_get api/v1/meter/rename/SP3-99%20IN/PSU
pg_get api/v1/measurement/rename/Dummy%20test
pg_get api/v1/run/start/sut
sleep 1
msg_get api/v1/run/stop/sut
msg_get api/v1/run/start/sut
pg_get api/v1/run/stop/sut
pg_get api/v1/run/start/sut
sleep 1
msg_get api/v1/run/stop/sut
pg_get api/v1/run/stop/sut
sleep 0.5
msg_get api/v1/measurement/stop/TestScenario1
msg_get api/v1/session/close
msg_get api/v1/session/store
pg_get api/v1/measurement/stop/TestScenario1
pg_get api/v1/session/close
pg_get api/v1/session/store
#!/bin/sh
# simple script for testing the functionality of the built-in HTTP server
# API v2
# A simple script for testing the functionality of the built-in HTTP server
#
# The script should be run on the same system.
# Adjust the HOST parameter if necessary
# Requires 'curl'.
# Adjust the HOST parameter if necessary.
HOST=localhost:8080
msg_get() {
pg_get() {
curl "http://$HOST/api/v2/$*"
}
msg_get cmd/startSession
msg_get session/latest/rename/CLI%20tool%20measurements
msg_get session/latest/meter/SP3-fc/rename/out1/PSU
msg_get session/latest/measurement/start
msg_get session/latest/measurement/rename/Sleep
pg_post_file() {
curl --data-binary "@$2" "http://$HOST/api/v2/$1"
}
pg_get cmd/startSession
pg_post_file session/latest/import/template README.md
pg_get session/latest/measurement/start
pg_get session/latest/measurement/rename/Sleep
for i in $(seq 10); do
msg_get session/latest/run/start
pg_get session/latest/run/start
sleep 1.5
msg_get session/latest/run/stop
pg_get session/latest/run/stop
done
sleep 0.5
msg_get session/latest/measurement/stop
msg_get session/latest/close
msg_get session/latest/store
pg_get session/latest/measurement/stop
pg_get session/latest/close
pg_get session/latest/store
import requests
import json
class GoblinClient:
def __init__(self, host):
self.host = host
def get(self, url):
return requests.get(self.host + "/" + url)
def post_json(self, url, json):
return requests.post(self.host + "/" + url, json = json)
def post_text(self, url, text):
return requests.post(self.host + "/" + url, data = text, headers={'Content-Type': 'text/plain'})
def post_file(self, url, file):
with open(file, 'rb') as payload:
headers = {'content-type': 'application/x-zip'}
return requests.post(self.host + "/" + url, data=payload, verify=False, headers=headers)
def interpret(self, result):
return json.loads(result.content)["result"]
# --- Examples ---
c = GoblinClient("http://localhost:8080")
# GET example
#meters = c.get("api/v1/session/meters")
#print(c.interpret(meters))
# POST examples
#data = { "triggerType" : "Run", "unit" : "SUT", "message": "Starting", "type": "trigger" }
#c.post_json("api/v1/trigger", json = data)
#c.post_text("api/v1/session/rename", text = "foobar")
c.post_file("api/v1/import/collectd", "collectd2.zip")
---
name: Client library example
author: Captain Planet
---
This folder contains client side library scripts for interfacing
with PowerGoblin, written in Bash and Python, and also examples of
their use.
Library scripts:
- `intel-rapl.py`
- `powergoblin.py`
- `powergoblin.sh`
- `seleniumdriver.py`
Usage examples:
- `test.py`
- `test.sh`
- `test-selenium.py`
On Arch Linux, the following (AUR) packages need to be
installed to run the Selenium measurement:
......
......@@ -50,16 +50,13 @@ class PowerGoblin:
return str(round(time.time() * 1000))
class Collectd:
def __init__(self, target = "/tmp/collectd/", interval = "0.1", rapl = False):
def __init__(self, target = "/tmp/collectd/", interval = "0.1", rapl = False, nvml = False):
self.conf_file = "collectd.conf"
if rapl:
with open(self.conf_file, "w") as f:
f.write(f"""
base = f"""
Interval ${interval}
LoadPlugin cpu
LoadPlugin csv
LoadPlugin python
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
......@@ -68,29 +65,26 @@ LoadPlugin memory
DataDir "{target}"
StoreRates false
</Plugin>
"""
raplCode = f"""
LoadPlugin python
<Plugin python>
ModulePath "."
LogTraces true
Import "intel_rapl"
</Plugin>
""")
else:
with open(self.conf_file, "w") as f:
f.write(f"""
Interval ${interval}
LoadPlugin cpu
LoadPlugin csv
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
"""
nvmlCode = f"""
LoadPlugin gpu_nvidia
"""
if rapl:
base = base + raplCode
if nvml:
base = base + nvmlCode
<Plugin csv>
DataDir "{target}"
StoreRates false
</Plugin>
""")
with open(self.conf_file, "w") as f:
f.write(base)
self.process = subprocess.Popen(["/usr/sbin/collectd", "-fC", self.conf_file])
self.target = target
......
......@@ -15,6 +15,7 @@
#
# export COLLECTD_INTERVAL=0.1
# export COLLECTD_RAPL=N
# export COLLECTD_NVML=N
# collectd_start /tmp/collectd
# collectd_stop
# pg_post_file session/latest/import/collectd "$(collectd_dump)"
......@@ -75,6 +76,7 @@ COLLECTD_CONFIGURATION=collectd.conf
COLLECTD_TARGET=collected.zip
COLLECTD_DATA=/tmp/collectd
COLLECTD_RAPL=N
COLLECTD_NVML=N
collectd_start() {
if [ "$1" != "" ]; then
......@@ -102,13 +104,11 @@ collectd_start() {
mkdir -p "${COLLECTD_DATA}"
if [ "${COLLECTD_RAPL}" == Y ]; then
cat << EOF > "$CONF"
Interval ${COLLECTD_INTERVAL}
LoadPlugin cpu
LoadPlugin csv
LoadPlugin python
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
......@@ -118,26 +118,23 @@ LoadPlugin memory
StoreRates false
</Plugin>
EOF
if [ "${COLLECTD_RAPL}" == Y ]; then
cat << EOF >> "$CONF"
LoadPlugin python
<Plugin python>
ModulePath "."
LogTraces true
Import "intel_rapl"
</Plugin>
EOF
else
cat << EOF > "$CONF"
Interval ${COLLECTD_INTERVAL}
LoadPlugin cpu
LoadPlugin csv
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
EOF
fi
if [ "${COLLECTD_NVML}" == Y ]; then
cat << EOF >> "$CONF"
LoadPlugin gpu_nvidia
<Plugin csv>
DataDir "${COLLECTD_DATA}"
StoreRates false
</Plugin>
EOF
fi
......
......@@ -35,7 +35,7 @@ class SeleniumDriver:
pg = self.powergoblin.host
try:
return self.driver.execute_script(f"await fetch(\"{pg}/{cmd}\")")
return self.driver.execute_script(f"await fetch(\"{pg}{cmd}\")")
except JavascriptException as err:
print(err)
return None
......
......@@ -6,7 +6,7 @@ import time
pg = PowerGoblin("localhost:8080")
pg.get("cmd/startSession")
pg.get("session/latest/rename/CLI%20tool%20measurements")
pg.post_file("session/latest/import/template", "README.md")
cd = Collectd(target = "/tmp/collectd/", rapl = False)
......
......@@ -7,7 +7,7 @@ export HOST=localhost:8080
export HTTPCLIENT=curl
pg_get cmd/startSession
pg_get session/latest/rename/CLI%20tool%20measurements
pg_post_file session/latest/import/template README.md
export COLLECTD_RAPL=N
......
......@@ -13,6 +13,20 @@ communicating with PowerGoblin. It is assumed that PowerGoblin also runs
on the same system. In practice, it would be better to run it on a separate
system.
Preparations (background shell):
```shell
$ wget https://tech.utugit.fi/soft/tools/power/powergoblin/powergoblin.jar
$ java -jar powergoblin.jar
```
Usage:
```shell
$ cp ../client-library/powergoblin.sh .
$ ./collect.sh
```
You will need to customize the script to suit your needs. In the beginning of
the file, there are parameters for configuring names, number of runs, and
other settings. The actual code that will be measured is located on lines 28
......
---
name: System utility benchmarks with NVML
author: Captain Planet
---
The purpose of this example is to demonstrate how to measure the
resource consumption of a GPU provided by the CUDA and Nvidia
drivers.
The script assumes that `collectd` and `cuda` have been installed.
The client library (see `client-library/powergoblin.sh`) is used for
communicating with PowerGoblin. It is assumed that PowerGoblin also runs
on the same system. In practice, it would be better to run it on a separate
system.
The script also makes use of NVML counters for energy measurements.
Preparations (background shell):
```shell
$ wget https://tech.utugit.fi/soft/tools/power/powergoblin/powergoblin.jar
$ java -jar powergoblin.jar
```
Usage:
```shell
$ cp ../client-library/powergoblin.sh .
$ ./collect.sh
```
You will need to customize the script to suit your needs. In the beginning of
the file, there are parameters for configuring names, number of runs, and
other settings. The actual code that will be measured is located on lines 29
and 47.
#!/bin/bash
# You can use this as a template for your measurements.
# This depends on the `powergoblin.sh` in `client-library/`
source powergoblin.sh
export HOST=localhost:8080
export MEASUREMENT1="Sleep 1000ms"
export MEASUREMENT2="Sleep 2000ms"
export RUNS=5
export HTTPCLIENT=curl
export COLLECTD_NVML=Y
pg_get cmd/startSession
pg_post_file session/latest/import/template README.md
pg_get session/latest/resource/fanspeed,frequency,percent,power/include
collectd_start /tmp/collectd
# ---
pg_get session/latest/measurement/start
pg_get session/latest/measurement/rename/${MEASUREMENT1}
for i in $(seq $RUNS); do
echo "Run $i"
pg_get session/latest/run/start
sleep 1
pg_get session/latest/run/stop
done
pg_get session/latest/measurement/stop
sleep 0.5
# ---
pg_get session/latest/measurement/start
pg_get session/latest/measurement/rename/${MEASUREMENT2}
for i in $(seq $RUNS); do
echo "Run $i"
pg_get session/latest/run/start
sleep 2
pg_get session/latest/run/stop
done
pg_get session/latest/measurement/stop
sleep 0.5
# ---
collectd_stop
date +%s%N | pg_post session/latest/sync
pg_post_file session/latest/import/collectd "$(collectd_dump)"
pg_get session/latest/close
pg_get session/latest/remove
......@@ -14,14 +14,25 @@ on the same system. In practice, it would be better to run it on a separate
system.
The script also makes use of RAPL counters for energy measurements.
You may need to change the permissions of counter variables:
You may need to change the permissions of counter variables.
Preparations (background shell):
```shell
$ wget https://tech.utugit.fi/soft/tools/power/powergoblin/powergoblin.jar
$ java -jar powergoblin.jar
# chown -R $USER /sys/devices/virtual/powercap/intel-rapl
```
Usage:
```shell
$ cp ../client-library/powergoblin.sh .
$ ./collect.sh
```
You will need to customize the script to suit your needs. In the beginning of
the file, there are parameters for configuring names, number of runs, and
other settings. The actual code that will be measured is located on lines 28
and 46.
other settings. The actual code that will be measured is located on lines 29
and 47.
......@@ -13,6 +13,7 @@ export COLLECTD_RAPL=Y
pg_get cmd/startSession
pg_post_file session/latest/import/template README.md
pg_get session/latest/resource/counter/include
collectd_start /tmp/collectd
......
File moved
File moved
......@@ -6,6 +6,13 @@ author: Captain Planet
The purpose of this example is to demonstrate how to perform
energy measurements of a system packaged as a Docker container.
Preparations (background shell):
```shell
$ wget https://tech.utugit.fi/soft/tools/power/powergoblin/powergoblin.jar
$ java -jar powergoblin.jar
```
Usage:
```shell
......
# Sample: Generates lists of random numbers and sorts them
import time
import random
def milli_time():
return round(time.time() * 1000)
def gen(n):
return [random.randint(1, 1000) for _ in range(n)]
def sort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return sort(left) + middle + sort(right)
def do_computation():
start = milli_time()
msg = time.ctime()
print("Computing..", flush = True)
while milli_time() < start + 2000:
n = 100000
nums = gen(n)
sort(nums)
msg2 = time.ctime()
if msg != msg2:
print(msg2, flush = True)
msg = msg2
print("Done", flush = True)
do_computation()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment