Skip to content

Commit

Permalink
Merge pull request #66 from nschloe/lighter-deps
Browse files Browse the repository at this point in the history
Lighter deps
  • Loading branch information
nschloe authored Feb 10, 2020
2 parents 3b7f536 + 717143a commit 5e05a1a
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 164 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ black:

lint:
black --check .
flake8 setup.py stressberry/ test/*.py
flake8 .
2 changes: 1 addition & 1 deletion stressberry/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
__email__ = "[email protected]"
__copyright__ = f"Copyright (c) 2017-2020, {__author__} <{__email__}>"
__license__ = "License :: OSI Approved :: MIT License"
__version__ = "0.2.2"
__version__ = "0.2.3"
__maintainer__ = "Nico Schlömer"
__status__ = "Development Status :: 4 - Beta"
4 changes: 4 additions & 0 deletions stressberry/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .plot import plot
from .run import run

__all__ = ["plot", "run"]
17 changes: 17 additions & 0 deletions stressberry/cli/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys

from ..__about__ import __copyright__, __version__


def _get_version_text():
return "\n".join(
[
"stressberry {} [Python {}.{}.{}]".format(
__version__,
sys.version_info.major,
sys.version_info.minor,
sys.version_info.micro,
),
__copyright__,
]
)
142 changes: 142 additions & 0 deletions stressberry/cli/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import argparse

import yaml

from .helpers import _get_version_text


def plot(argv=None):
import matplotlib.pyplot as plt

parser = _get_parser_plot()
args = parser.parse_args(argv)

data = [yaml.load(f, Loader=yaml.SafeLoader) for f in args.infiles]

# sort the data such that the data series with the lowest terminal
# temperature is plotted last (and appears in the legend last)
terminal_temps = [d["temperature"][-1] for d in data]
order = [i[0] for i in sorted(enumerate(terminal_temps), key=lambda x: x[1])]
# actually plot it
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
for k in order[::-1]:
temperature_data = data[k]["temperature"]
if args.delta_t:
temperature_data = [t - data[k]["ambient"] for t in data[k]["temperature"]]
ax1.plot(
data[k]["time"], temperature_data, label=data[k]["name"], lw=args.line_width
)

ax1.grid()
if not args.hide_legend:
ax1.legend(loc="upper left", bbox_to_anchor=(1.03, 1.0), borderaxespad=0)
if args.delta_t:
plot_yaxis_label = "Δ temperature °C (over ambient)"
else:
plot_yaxis_label = "temperature °C"
ax1.set_xlabel("time (s)")
ax1.set_ylabel(plot_yaxis_label)
ax1.set_xlim([data[-1]["time"][0], data[-1]["time"][-1]])
if args.temp_lims:
ax1.set_ylim(*args.temp_lims)

# Only plot frequencies when using a single input file
if len(data) == 1 and args.frequency:
ax2 = plt.twinx()
ax2.set_ylabel("core frequency (MHz)")
if args.freq_lims:
ax2.set_ylim(*args.freq_lims)
try:
for k in order[::-1]:
ax2.plot(
data[k]["time"],
data[k]["cpu frequency"],
label=data[k]["name"],
color="C1",
alpha=0.9,
lw=args.line_width,
)
ax1.set_zorder(ax2.get_zorder() + 1) # put ax1 plot in front of ax2
ax1.patch.set_visible(False) # hide the 'canvas'
except KeyError():
print("Source data does not contain CPU frequency data.")

if args.outfile is not None:
plt.savefig(
args.outfile,
transparent=args.transparent,
bbox_inches="tight",
dpi=args.dpi,
)
else:
plt.show()
return


def _get_parser_plot():
parser = argparse.ArgumentParser(description="Plot stress test data.")
parser.add_argument(
"--version", "-v", action="version", version=_get_version_text()
)
parser.add_argument(
"infiles",
nargs="+",
type=argparse.FileType("r"),
help="input YAML file(s) (default: stdin)",
)
parser.add_argument(
"-o",
"--outfile",
help=(
"if specified, the plot is written to this file "
"(default: show on screen)"
),
)
parser.add_argument(
"-t",
"--temp-lims",
type=float,
nargs=2,
default=None,
help="limits for the temperature (default: data limits)",
)
parser.add_argument(
"-d",
"--dpi",
type=int,
default=None,
help="image resolution in dots per inch when written to file",
)
parser.add_argument(
"-f",
"--frequency",
help="plot CPU core frequency (single input files only)",
action="store_true",
)
parser.add_argument(
"-l",
"--freq-lims",
type=float,
nargs=2,
default=None,
help="limits for the frequency scale (default: data limits)",
)
parser.add_argument("--hide-legend", help="do not draw legend", action="store_true")
parser.add_argument(
"--not-transparent",
dest="transparent",
help="do not make images transparent",
action="store_false",
default=True,
)
parser.add_argument(
"-lw", "--line-width", type=float, default=None, help="line width"
)
parser.add_argument(
"--delta-t",
action="store_true",
default=False,
help="Use Delta-T (core - ambient) temperature instead of CPU core temperature",
)
return parser
160 changes: 3 additions & 157 deletions stressberry/cli.py → stressberry/cli/run.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
import argparse
import datetime
import sys
import threading
import time

import matplotlib.pyplot as plt
import numpy
import yaml

from .__about__ import __copyright__, __version__
from .main import (
from ..__about__ import __version__
from ..main import (
cooldown,
measure_ambient_temperature,
measure_core_frequency,
measure_temp,
test,
)


def _get_version_text():
return "\n".join(
[
"stressberry {} [Python {}.{}.{}]".format(
__version__,
sys.version_info.major,
sys.version_info.minor,
sys.version_info.micro,
),
__copyright__,
]
)
from .helpers import _get_version_text


def _get_parser_run():
Expand Down Expand Up @@ -176,141 +160,3 @@ def run(argv=None):
args.outfile,
)
return


def plot(argv=None):
parser = _get_parser_plot()
args = parser.parse_args(argv)

data = [yaml.load(f, Loader=yaml.SafeLoader) for f in args.infiles]

# sort the data such that the data series with the lowest terminal
# temperature is plotted last (and appears in the legend last)
terminal_temps = [d["temperature"][-1] for d in data]
order = [i[0] for i in sorted(enumerate(terminal_temps), key=lambda x: x[1])]
# actually plot it
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
for k in order[::-1]:
if args.delta_t:
temperature_data = numpy.subtract(
data[k]["temperature"], data[k]["ambient"]
)
else:
temperature_data = data[k]["temperature"]
ax1.plot(
data[k]["time"], temperature_data, label=data[k]["name"], lw=args.line_width
)

ax1.grid()
if not args.hide_legend:
ax1.legend(loc="upper left", bbox_to_anchor=(1.03, 1.0), borderaxespad=0)
if args.delta_t:
plot_yaxis_label = "Δ temperature °C (over ambient)"
else:
plot_yaxis_label = "temperature °C"
ax1.set_xlabel("time (s)")
ax1.set_ylabel(plot_yaxis_label)
ax1.set_xlim([data[-1]["time"][0], data[-1]["time"][-1]])
if args.temp_lims:
ax1.set_ylim(*args.temp_lims)

# Only plot frequencies when using a single input file
if len(data) == 1 and args.frequency:
ax2 = plt.twinx()
ax2.set_ylabel("core frequency (MHz)")
if args.freq_lims:
ax2.set_ylim(*args.freq_lims)
try:
for k in order[::-1]:
ax2.plot(
data[k]["time"],
data[k]["cpu frequency"],
label=data[k]["name"],
color="C1",
alpha=0.9,
lw=args.line_width,
)
ax1.set_zorder(ax2.get_zorder() + 1) # put ax1 plot in front of ax2
ax1.patch.set_visible(False) # hide the 'canvas'
except KeyError():
print("Source data does not contain CPU frequency data.")

if args.outfile is not None:
plt.savefig(
args.outfile,
transparent=args.transparent,
bbox_inches="tight",
dpi=args.dpi,
)
else:
plt.show()
return


def _get_parser_plot():
parser = argparse.ArgumentParser(description="Plot stress test data.")
parser.add_argument(
"--version", "-v", action="version", version=_get_version_text()
)
parser.add_argument(
"infiles",
nargs="+",
type=argparse.FileType("r"),
help="input YAML file(s) (default: stdin)",
)
parser.add_argument(
"-o",
"--outfile",
help=(
"if specified, the plot is written to this file "
"(default: show on screen)"
),
)
parser.add_argument(
"-t",
"--temp-lims",
type=float,
nargs=2,
default=None,
help="limits for the temperature (default: data limits)",
)
parser.add_argument(
"-d",
"--dpi",
type=int,
default=None,
help="image resolution in dots per inch when written to file",
)
parser.add_argument(
"-f",
"--frequency",
help="plot CPU core frequency (single input files only)",
action="store_true",
)
parser.add_argument(
"-l",
"--freq-lims",
type=float,
nargs=2,
default=None,
help="limits for the frequency scale (default: data limits)",
)
parser.add_argument("--hide-legend", help="do not draw legend", action="store_true")
parser.add_argument(
"--not-transparent",
dest="transparent",
help="do not make images transparent",
action="store_false",
default=True,
)
parser.add_argument(
"-lw", "--line-width", type=float, default=None, help="line width"
)
parser.add_argument(
"--delta-t",
action="store_true",
default=False,
help="Use Delta-T (core - ambient) temperature instead of CPU core temperature",
)
return parser
10 changes: 5 additions & 5 deletions stressberry/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def measure_ambient_temperature(sensor_type="2302", pin="23"):
print("Invalid ambient temperature sensor")
raise e
humidity, 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 be taken when reading if on a time sensitive path
# Temperature is in °C but can also be None
# 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
# be taken when reading if on a time sensitive path Temperature is in °C but can
# also be None
return temperature


Expand Down

0 comments on commit 5e05a1a

Please sign in to comment.