Skip to content

Commit

Permalink
Merge pull request #89 from nschloe/meta-update
Browse files Browse the repository at this point in the history
  • Loading branch information
nschloe authored Dec 16, 2020
2 parents 0f9a086 + 4faa9f9 commit 196b83b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 49 deletions.
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ upload:
rm -f dist/*
# python3 setup.py sdist bdist_wheel
# https://stackoverflow.com/a/58756491/353337
python3 -m pep517.build --source --binary .
python3 -m build --sdist --wheel .
twine upload dist/*

publish: tag upload
Expand All @@ -26,11 +26,9 @@ clean:
@rm -rf *.egg-info/ build/ dist/

format:
isort -rc .
black .

black:
isort .
black .
blacken-docs README.md

lint:
black --check .
Expand Down
14 changes: 5 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[metadata]
name = stressberry
version = 0.3.1
version = 0.3.2
author = Nico Schlömer
email = [email protected]
author_email = [email protected]
description = Stress tests for the Raspberry Pi
url = https://github.com/nschloe/stressberry
project_urls =
Code=https://github.com/nschloe/stressberry
Issues=https://github.com/nschloe/stressberry/issues
long_description = file: README.md
long_description_content_type = text/markdown
license = GPLv3
platforms = any
license = GPL-3.0-or-later
classifiers =
Development Status :: 4 - Beta
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Expand All @@ -21,20 +20,17 @@ classifiers =
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Topic :: Utilities

[options]
packages = find:
# importlib_metadata can be removed when we support Python 3.8+ only
install_requires =
dufte
importlib_metadata
importlib_metadata;python_version<"3.8"
matplotlib
pyyaml
python_requires = >=3.6
setup_requires =
setuptools>=42
wheel

[options.entry_points]
console_scripts =
Expand Down
28 changes: 14 additions & 14 deletions stressberry/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,29 @@ def run(argv=None):
# If never had a good result, probably configuration error
# Else use last known value if available or worst case set to zero
if not ambient:
message = "Could not read ambient temperature sensor {} on pin {}".format(
args.ambient[0], args.ambient[1]
print(
f"Could not read ambient temperature sensor {args.ambient[0]} "
f"on pin {args.ambient[1]}"
)
else:
message = "WARN - Could not read ambient temperature, using last good value"
print(message)
print(
"WARN - Could not read ambient temperature, "
"using last good value"
)
ambient_temperature = next(
(temp for temp in reversed(ambient) if temp is not None), 0
)
ambient.append(ambient_temperature)
delta_t = temps[-1] - ambient[-1]
print(
"Temperature (current | ambient | ΔT): {:4.1f}°C | {:4.1f}°C | {:4.1f}°C - Frequency: {:4.0f}MHz".format(
temps[-1], ambient[-1], delta_t, freqs[-1]
)
"Temperature (current | ambient | ΔT): "
f"{temps[-1]:4.1f}°C | {ambient[-1]:4.1f}°C | {delta_t:4.1f}°C "
f"- Frequency: {freqs[-1]:4.0f}MHz"
)
else:
print(
"Current temperature: {:4.1f}°C - Frequency: {:4.0f}MHz".format(
temps[-1], freqs[-1]
)
f"Current temperature: {temps[-1]:4.1f}°C "
f"- Frequency: {freqs[-1]:4.0f}MHz"
)
# Choose the sample interval such that we have a respectable number of
# data points
Expand All @@ -145,9 +147,8 @@ def run(argv=None):
times = [tm - time0 for tm in times]

args.outfile.write(
"# This file was created by stressberry v{} on {}\n".format(
__version__, datetime.datetime.now()
)
f"# This file was created by stressberry v{__version__} "
f"on {datetime.datetime.now()}\n"
)
yaml.dump(
{
Expand All @@ -159,4 +160,3 @@ def run(argv=None):
},
args.outfile,
)
return
32 changes: 11 additions & 21 deletions stressberry/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ def stress_cpu(num_cpus, time):


def cooldown(interval=60, filename=None):
"""Lets the CPU cool down until the temperature does not change anymore.
"""
"""Lets the CPU cool down until the temperature does not change anymore."""
prev_tmp = measure_temp(filename=filename)
while True:
tme.sleep(interval)
tmp = measure_temp(filename=filename)
print(
"Current temperature: {:4.1f}°C - Previous temperature: {:4.1f}°C".format(
tmp, prev_tmp
)
f"Current temperature: {tmp:4.1f}°C - "
f"Previous temperature: {prev_tmp:4.1f}°C"
)
if abs(tmp - prev_tmp) < 0.2:
break
Expand All @@ -27,10 +25,9 @@ def cooldown(interval=60, filename=None):


def measure_temp(filename=None):
"""Returns the core temperature in Celsius.
"""
"""Returns the core temperature in Celsius."""
if filename is not None:
with open(filename, "r") as f:
with open(filename) as f:
temp = float(f.read()) / 1000
else:
# Using vcgencmd is specific to the raspberry pi
Expand All @@ -40,10 +37,9 @@ def measure_temp(filename=None):


def measure_core_frequency(filename=None):
"""Returns the CPU frequency in MHz
"""
"""Returns the CPU frequency in MHz"""
if filename is not None:
with open(filename, "r") as f:
with open(filename) as f:
frequency = float(f.read()) / 1000
else:
# Only vcgencmd measure_clock arm is accurate on Raspberry Pi.
Expand All @@ -54,8 +50,7 @@ def measure_core_frequency(filename=None):


def measure_ambient_temperature(sensor_type="2302", pin="23"):
"""Uses Adafruit temperature sensor to measure ambient temperature
"""
"""Uses Adafruit temperature sensor to measure ambient temperature"""
try:
import Adafruit_DHT # Late import so that library is only needed if requested
except ImportError as e:
Expand All @@ -72,7 +67,7 @@ def measure_ambient_temperature(sensor_type="2302", pin="23"):
except KeyError as e:
print("Invalid ambient temperature sensor")
raise e
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
_, temperature = Adafruit_DHT.read_retry(sensor, pin)
# Note that sometimes you won't get a reading and the results will be null (because
# Linux can't guarantee the timing of calls to read the sensor). The read_retry
# call will attempt to read the sensor 15 times with a 2 second delay. Care should
Expand All @@ -83,21 +78,16 @@ def measure_ambient_temperature(sensor_type="2302", pin="23"):

def test(stress_duration, idle_duration, cores):
"""Run stress test for specified duration with specified idle times
at the start and end of the test.
at the start and end of the test.
"""
if cores is None:
cores = cpu_count()

print(
"Preparing to stress [{}] CPU Cores for [{}] seconds".format(
cores, stress_duration
)
)
print(f"Preparing to stress [{cores}] CPU Cores for [{stress_duration}] seconds")
print(f"Idling for {idle_duration} seconds...")
tme.sleep(idle_duration)

stress_cpu(num_cpus=cores, time=stress_duration)

print(f"Idling for {idle_duration} seconds...")
tme.sleep(idle_duration)
return

0 comments on commit 196b83b

Please sign in to comment.