Add CPU graph upload logic

This commit is contained in:
2Shirt 2023-10-14 19:28:40 -07:00
parent eb07a93e20
commit cfd502245c
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 38 additions and 14 deletions

View file

@ -9,7 +9,11 @@ from typing import TextIO
from wk import exe from wk import exe
from wk.cfg.hw import CPU_TEMPS from wk.cfg.hw import CPU_TEMPS
from wk.graph import export_cpu_graph from wk.graph import (
export_cpu_graph,
upload_to_imgur,
upload_to_nextcloud,
)
from wk.os.mac import set_fans as macos_set_fans from wk.os.mac import set_fans as macos_set_fans
from wk.std import PLATFORM from wk.std import PLATFORM
from wk.ui import ansi from wk.ui import ansi
@ -21,8 +25,9 @@ SysbenchType = tuple[subprocess.Popen, TextIO]
# Functions # Functions
def check_cooling_results(cpu_description, log_dir, sensors, test_object) -> None: def check_cooling_results(state, test_object) -> None:
"""Check cooling result via sensor data.""" """Check cooling result via sensor data."""
sensors = state.sensors
idle_temp = sensors.get_cpu_temp('Idle') idle_temp = sensors.get_cpu_temp('Idle')
cooldown_temp = sensors.get_cpu_temp('Cooldown') cooldown_temp = sensors.get_cpu_temp('Cooldown')
max_temp = sensors.get_cpu_temp('Max') max_temp = sensors.get_cpu_temp('Max')
@ -85,12 +90,36 @@ def check_cooling_results(cpu_description, log_dir, sensors, test_object) -> Non
*report_labels, only_cpu=True, include_avg_for=average_labels): *report_labels, only_cpu=True, include_avg_for=average_labels):
test_object.report.append(f' {line}') test_object.report.append(f' {line}')
# Export graph # Export and upload graph
export_cpu_graph( export_and_upload_graphs(state, test_object)
cpu_description = cpu_description,
log_dir = log_dir,
sensor_history = sensors.history, def export_and_upload_graphs(state, test_object):
"""Export and upload graphs."""
image_path = None
try:
image_path = export_cpu_graph(
cpu_description = state.system.cpu_description,
log_dir = state.log_dir,
sensor_history = state.sensors.history,
) )
except RuntimeError as err:
# Failed to export PNG, skip uploads below
LOG.error('Failed to export graph: %s', err)
test_object.report.append('Failed to export graph')
return
# Upload PNG
if not state.ost.disabled and state.ost.ticket_id:
try:
imgur_url = upload_to_imgur(image_path)
nextcloud_url = upload_to_nextcloud(image_path, state.ost.ticket_id, 'cpu')
test_object.report.append(f'Imgur: {imgur_url}')
test_object.report.append(f'Nextcloud: {nextcloud_url}')
except Exception as err:
LOG.error('%s', err)
LOG.error('Failed to upload graph')
test_object.report.append('Failed to upload graph')
def check_mprime_results(test_obj, working_dir) -> None: def check_mprime_results(test_obj, working_dir) -> None:

View file

@ -413,12 +413,7 @@ def cpu_test_cooling(state: State, test_object, test_mode=False) -> None:
if test_object.disabled: if test_object.disabled:
return return
hw_cpu.check_cooling_results( hw_cpu.check_cooling_results(state, test_object)
state.system.cpu_description,
state.log_dir,
state.sensors,
test_object,
)
state.update_progress_file() state.update_progress_file()