Skip to content

Commit

Permalink
Add timer for stress test
Browse files Browse the repository at this point in the history
Addresses #59, adds a timer to stress tests.
The timer start when a stress test begins. The timer can be reset with
the reset button or by starting a new stress
  • Loading branch information
amanusk committed Aug 22, 2018
1 parent 02bf149 commit 0fa9f16
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ script:
- "python -m s_tui.Tests.test_util_source"
- "s-tui -t"
- "s-tui -j"
- "s-tui -dr"
9 changes: 8 additions & 1 deletion s_tui/HelperFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from collections import OrderedDict
from sys import exit

__version__ = "0.7.8"
__version__ = "0.8.0"


def get_processor_name():
Expand Down Expand Up @@ -165,6 +165,13 @@ def make_user_config_dir():
return config_path


def seconds_to_text(secs):
hours = (secs)//3600
minutes = (secs - hours*3600)//60
seconds = secs - hours*3600 - minutes*60
return "%02d:%02d:%02d" % (hours, minutes, seconds)


DEFAULT_PALETTE = [
('body', 'default', 'default', 'standout'),
('header', 'default', 'dark red',),
Expand Down
48 changes: 46 additions & 2 deletions s_tui/s_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
import os
import subprocess
import time
import timeit
import psutil
import urwid
import signal
import itertools

try:
import configparser
except(ImportError):
Expand All @@ -57,6 +59,7 @@
from s_tui.HelperFunctions import make_user_config_dir
from s_tui.HelperFunctions import user_config_dir_exists
from s_tui.HelperFunctions import user_config_file_exists
from s_tui.HelperFunctions import seconds_to_text
from s_tui.UiElements import ViListBox
from s_tui.UiElements import radio_button
from s_tui.UiElements import button
Expand Down Expand Up @@ -92,6 +95,7 @@
stress_installed = False
graph_controller = None
stress_program = None
debug_run_counter = 0

INTRO_MESSAGE = HELP_MESSAGE

Expand Down Expand Up @@ -195,6 +199,10 @@ def __init__(self, controller):

self.controller = controller
self.hline = urwid.AttrWrap(urwid.SolidFill(u'_'), 'line')

clock_text = seconds_to_text(self.controller.stress_time)
self.clock_view = urwid.Text(('bold text', clock_text), align="center")

self.mode_buttons = []
self.refresh_rate_ctrl = urwid.Edit(('bold text', u'Refresh[s]:'),
self.controller.refresh_rate)
Expand All @@ -215,8 +223,6 @@ def __init__(self, controller):
self.stress_menu.sqrt_workers = str(self.global_data.num_cpus)
self.left_margin = 0
self.top_margin = 0
self.v_relative = 50
self.h_relative = 50

urwid.WidgetPlaceholder.__init__(self, self.main_window())
urwid.connect_signal(self.refresh_rate_ctrl, 'change',
Expand All @@ -243,6 +249,13 @@ def update_displayed_information(self):
for s in self.available_summaries.values():
s.update()

# Only update clock if not is stress mode
if self.controller.mode.get_current_mode() != 'Monitor':
self.controller.stress_time = (timeit.default_timer() -
self.controller.stress_start_time)
self.clock_view.set_text(('bold text', seconds_to_text(
int(self.controller.stress_time))))

def on_reset_button(self, w):
"""Reset graph data and display empty graph"""
for g in self.visible_graphs.values():
Expand All @@ -252,6 +265,9 @@ def on_reset_button(self, w):
g.source.reset()
except (NotImplementedError):
pass
# Reset clock
self.controller.stress_time = 0

self.update_displayed_information()

def on_menu_close(self):
Expand Down Expand Up @@ -453,6 +469,7 @@ def graph_controls(self, conf):
buttons = [urwid.Text(('bold text', u"Modes"), align="center"),
] + self.mode_buttons + [
install_stress_message,
urwid.LineBox(self.clock_view),
urwid.Divider(),
urwid.Text(('bold text', u"Control Options"), align="center"),
animate_controls,
Expand Down Expand Up @@ -703,6 +720,9 @@ def __init__(self, args):

self.handle_mouse = not(args.no_mouse)

self.stress_start_time = 0
self.stress_time = 0

self.view = GraphView(self)
# use the first mode (no stress) as the default
mode = self.get_modes()[0]
Expand Down Expand Up @@ -753,10 +773,20 @@ def animate_graph(self, loop=None, user_data=None):
self.view.update_displayed_information()
self.animate_alarm = self.loop.set_alarm_in(
float(self.refresh_rate), self.animate_graph)
# Update
global debug_run_counter
if self.args.debug_run:
debug_run_counter += int(float(self.refresh_rate))
if debug_run_counter >= 5:
self.view.exit_program()

def start_stress(self):
mode = self.mode
if mode.get_current_mode() == 'Stress':

self.stress_start_time = timeit.default_timer()
self.stress_time = 0

kill_child_processes(mode.get_stress_process())
# This is not pretty, but this is how we know stress started
self.view.graphs['Frequency'].source.set_stress_started()
Expand Down Expand Up @@ -803,6 +833,10 @@ def start_stress(self):
kill_child_processes(mode.get_stress_process())

stress_cmd = fire_starter

self.stress_start_time = timeit.default_timer()
self.stress_time = 0

self.view.graphs['Frequency'].source.set_stress_started()
logging.debug("Firestarter " + str(fire_starter))
with open(os.devnull, 'w') as DEVNULL:
Expand All @@ -826,6 +860,10 @@ def start_stress(self):
except(KeyError, AttributeError):
logging.debug('Unalbe to reset performance loss meter')

# Start a new clock upon starting a new stress test
self.view.clock_view.set_text(('bold text', seconds_to_text(
int(self.stress_time))))


def main():
args = get_args()
Expand All @@ -838,6 +876,8 @@ def main():
global log_file
level = ""
log_file = DEFAULT_LOG_FILE
if args.debug_run:
args.debug = True
if args.debug or args.debug_file is not None:
level = logging.DEBUG
if args.debug_file is not None:
Expand Down Expand Up @@ -909,6 +949,10 @@ def get_args():
default=None,
help="Use a custom debug file. Default: " +
"_s-tui.log")
# This is mainly to be used for testing purposes
parser.add_argument('-dr', '--debug_run',
default=False, action='store_true',
help="Run for 5 seconds and quit")
parser.add_argument('-c', '--csv', action='store_true',
default=False, help="Save stats to csv file")
parser.add_argument('--csv-file',
Expand Down

0 comments on commit 0fa9f16

Please sign in to comment.