From a761abccf661048380e8151e6028192b7832b170 Mon Sep 17 00:00:00 2001 From: Nikolas Date: Mon, 15 Apr 2024 11:43:23 -0700 Subject: [PATCH] first draft for testing --- pugetbench/pugetbench.py | 111 ++++++++++++++++++++++ pugetbench/test_samples/photoshop_log.csv | 44 +++++++++ pugetbench/utils.py | 30 ++++++ 3 files changed, 185 insertions(+) create mode 100644 pugetbench/pugetbench.py create mode 100644 pugetbench/test_samples/photoshop_log.csv create mode 100644 pugetbench/utils.py diff --git a/pugetbench/pugetbench.py b/pugetbench/pugetbench.py new file mode 100644 index 0000000..919afbf --- /dev/null +++ b/pugetbench/pugetbench.py @@ -0,0 +1,111 @@ +"""pugetbench for creators test script""" +import json +import logging +import os.path +from pathlib import Path +import shutil +import sys +from argparse import ArgumentParser +import time +from subprocess import Popen +from utils import find_latest_log, find_score_in_log + +sys.path.insert(1, os.path.join(sys.path[0], "..")) +from harness_utils.process import terminate_processes +from harness_utils.output import ( + seconds_to_milliseconds, + setup_log_directory, + write_report_json, + DEFAULT_LOGGING_FORMAT, + DEFAULT_DATE_FORMAT, +) + +script_dir = os.path.dirname(os.path.realpath(__file__)) +log_dir = os.path.join(script_dir, "run") +setup_log_directory(log_dir) +logging.basicConfig(filename=f'{log_dir}/harness.log', + format=DEFAULT_LOGGING_FORMAT, + datefmt='%m-%d %H:%M', + level=logging.DEBUG) +console = logging.StreamHandler() +formatter = logging.Formatter(DEFAULT_LOGGING_FORMAT) +console.setFormatter(formatter) +logging.getLogger('').addHandler(console) + +executable_name = "PugetBench for Creators.exe" + +def run_benchmark(application: str) -> Popen: + start_time = time.time() + executable_path = Path(f"C:\\Program Files\\PugetBench for Creators\\{executable_name}") + command_args = ["--run_count" , "1", "--rerun_count", "1", "--benchmark_version", "1.0.0", "--preset", "Standard"] + photoshop_args = command_args + ["--app", "photoshop"] + premiere_args = command_args + ["--app", '"Premiere Pro"'] + + process = None + if application == "premiere": + process = Popen([executable_path] + premiere_args) + elif application == "photoshop": + process = Popen([executable_path] + photoshop_args) + + exit_code = process.wait() + end_time = time.time() + return start_time, end_time, exit_code + +def main(): + start_time = time.time() + parser = ArgumentParser() + parser.add_argument( + "--app", dest="app", help="Host for Keras OCR service", required=True + ) + args = parser.parse_args() + apps = [ + "premiere", + "photoshop" + ] + + if args.app is None or args.app not in apps: + logging.info(f"unrecognized option for program {args.app}") + print('what') + sys.exit(1) + + # 1 check if pugetbench is installed + # 2 check adobe photoshop or premiere is present + # parse the report + # print the report + + score = 0 + test = "" + if args.app == "premiere": + test = "Adobe Premiere Pro" + elif args.app == "photoshop": + test = "Adobe Photoshop" + + try: + start_time, end_time, exit_code = run_benchmark(args.app) + + if exit_code > 0: + logging.error("Test failed!") + sys.exit(exit_code) + + log_file = find_latest_log() + score = find_score_in_log(log_file) + destination = Path(script_dir) / "run" / os.path.split(log_file)[1] + shutil.copy(log_file, destination) + + report = { + "start_time": seconds_to_milliseconds(start_time), + "end_time": seconds_to_milliseconds(end_time), + "test": test, + "score": score + } + + write_report_json(log_dir, "report.json", report) + except Exception as e: + logging.error("Something went wrong running the benchmark!") + logging.exception(e) + terminate_processes(executable_name) + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/pugetbench/test_samples/photoshop_log.csv b/pugetbench/test_samples/photoshop_log.csv new file mode 100644 index 0000000..fdf38c8 --- /dev/null +++ b/pugetbench/test_samples/photoshop_log.csv @@ -0,0 +1,44 @@ +Benchmark Name,PugetBench for Photoshop +Benchmark Version,1.0.0 +Application Name,Photoshop +Application Version,25.6 + +System Specs: + +System,ASUS,System Product Name +OS,Microsoft Corporation,Microsoft Windows 11 Pro,22631 +CPU,GenuineIntel,12th Gen Intel Core i5-12600K,10 +Motherboard,ASUSTeK COMPUTER INC.,ProArt Z690-CREATOR WIFI,1720 +Memory,G Skill Intl,16,GB,5200,MHz +Memory,G Skill Intl,16,GB,5200,MHz +GPU,"Parsec Cloud, Inc.",Parsec Virtual Display Adapter,0.41.0.0 +GPU,NVIDIA,NVIDIA GeForce RTX 4070,31.0.15.5176 +Engine + +Benchmark Results: + +Test,Setting,Result,Units +Overall Score (Standard),,7097, +General Score (Standard),General,73, +Filter Score (Standard),Filter,69, +File Open - RAW,General,1.53,seconds +Resize to 150MP - Preserve Details,General,1.98,seconds +Resize to 150MP - Bicubic Smooth,General,0.63,seconds +Rotate,General,1.08,seconds +Select Subject,General,3.18,seconds +Select and Mask,General,3.78,seconds +Convert to Smart Object,General,1.79,seconds +Paint Bucket,General,1.15,seconds +Smudge Tool,General,12.41,seconds +Adaptive Wide Angle,Filter,120.3,seconds +Camera Raw,Filter,3.25,seconds +Lens Correction,Filter,26.78,seconds +Content Aware Fill,Filter,8.84,seconds +Reduce Noise,Filter,11.66,seconds +Smart Sharpen,Filter,1.31,seconds +Iris Blur,Filter,7.35,seconds +Field Blur,Filter,9.38,seconds +File Save - JPG,General,1.6,seconds +File Save - PNG,General,61.37,seconds +File Save - PSD,General,25.77,seconds +File Open - PSD,General,5.4,seconds diff --git a/pugetbench/utils.py b/pugetbench/utils.py new file mode 100644 index 0000000..3602852 --- /dev/null +++ b/pugetbench/utils.py @@ -0,0 +1,30 @@ +import re +import os +from pathlib import Path + + +def find_latest_log(): + appdata_path = os.getenv('LOCALAPPDATA') + puget_lunch_dir = Path(appdata_path) / "com.puget.benchmark" / "csv" + files = [os.path.join(puget_lunch_dir, file) for file in os.listdir( + puget_lunch_dir) if os.path.isfile(os.path.join(puget_lunch_dir, file))] + latest_file = max(files, key=os.path.getmtime) + script_dir = os.path.dirname(os.path.realpath(__file__)) + return Path(script_dir) / latest_file + + +def find_score_in_log(log_path): + with open(log_path, 'r') as file: + for line in file: + score = is_score_line(line) + if score is not None: + return score + + +def is_score_line(line): + regex_pattern = r"^Overall Score.+,+(\d+),+" + match = re.search(regex_pattern, line) + if match and len(match.groups()) > 0: + return match.group(1) + else: + return None