Skip to content

Commit

Permalink
Merge pull request #35 from george0st/changes
Browse files Browse the repository at this point in the history
Redesign graph generation
  • Loading branch information
george0st authored Sep 17, 2024
2 parents 6a4e933 + 28b7078 commit 8216f6a
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 23 deletions.
9 changes: 9 additions & 0 deletions qgate_perf/executor_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import math
from enum import Flag


class GraphScope(Flag):
"""Define typy of graph for generation"""
off = 0 # without graph generation
perf = 1 # generation of performance graph
exe = 2 # generation of executor graph
all = perf | exe # generation of performance and executor graph

class ExecutorHelper:
""" Predefines values for setting of executor lists with pattern [[processes, threads, label], ..] """
Expand Down
70 changes: 49 additions & 21 deletions qgate_perf/parallel_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from qgate_perf.file_format import FileFormat
from qgate_perf.run_setup import RunSetup
from qgate_perf.bundle_helper import BundleHelper
from qgate_perf.executor_helper import ExecutorHelper
from qgate_perf.executor_helper import ExecutorHelper, GraphScope
from qgate_perf.parallel_probe import ParallelProbe
from qgate_perf.run_return import RunReturn
from platform import python_version
Expand Down Expand Up @@ -466,53 +466,81 @@ def test_run(self, run_setup: RunSetup=None, print_output=False):
return False
return True

def create_graph(self, output_graph_dir="output", picture_dpi=100, suppress_error = False) -> list[str]:
@staticmethod
def create_graph_static(input_file, output_graph_dir="output", scope: GraphScope = GraphScope.all, picture_dpi=100, suppress_error = False) -> list[str]:
"""
Generate graph(s) based on output from performance tests
:param input_file: source file with detail of outputs from performance tests
:param output_graph_dir: directory for graph outputs (with subdirectory 'graph-perf' and 'graph-exec')
:param scope: definition of scope generation (default ExecutorGraph.all)
:param picture_dpi: quality of picture (default is 100 DPI)
:param suppress_error: suppress error (default is False)
:return: list of output files
"""
from qgate_graph.graph_performance import GraphPerformance
from qgate_graph.graph_executor import GraphExecutor

output_file=[]

graph = GraphPerformance(picture_dpi)
for file in graph.generate_from_file(self._output_file, os.path.join(output_graph_dir,"graph-perf"), suppress_error):
output_file.append(file)
if GraphScope.perf in scope:
from qgate_graph.graph_performance import GraphPerformance

graph = GraphPerformance(picture_dpi)
for file in graph.generate_from_file(input_file, os.path.join(output_graph_dir,"graph-perf"), suppress_error):
output_file.append(file)

if GraphScope.exe in scope:
from qgate_graph.graph_executor import GraphExecutor

graph = GraphExecutor(picture_dpi)
for file in graph.generate_from_file(input_file, os.path.join(output_graph_dir,"graph-exec"), suppress_error):
output_file.append(file)

graph = GraphExecutor(picture_dpi)
for file in graph.generate_from_file(self._output_file, os.path.join(output_graph_dir,"graph-exec"), suppress_error):
output_file.append(file)
return output_file

def create_graph(self, output_graph_dir="output", scope: GraphScope = GraphScope.all, picture_dpi=100, suppress_error = False) -> list[str]:
"""
Generate graph(s) based on output from performance tests.
The outputs will be in subdirectories 'graph-perf' and 'graph-exec'.
:param output_graph_dir: directory for graph outputs (with subdirectory 'graph-perf' and 'graph-exec')
:param scope: definition of scope generation (default ExecutorGraph.all)
:param picture_dpi: quality of picture (default is 100 DPI)
:param suppress_error: suppress error (default is False)
:return: list of output files
"""
return ParallelExecutor.create_graph_static(self._output_file,
output_graph_dir,
scope,
picture_dpi,
suppress_error)

def create_graph_perf(self, output_graph_dir="output", picture_dpi=100, suppress_error = False) -> list[str]:
"""
Generate performance graph(s) based on output from performance tests
Generate performance graph(s) based on output from performance tests.
The outputs will be in subdirectory 'graph-perf'.
:param output_graph_dir: directory for graph outputs (with subdirectory 'graph-perf')
:param picture_dpi: quality of picture (default is 100 DPI)
:param suppress_error: suppress error (default is False)
:return: list of output files
"""
from qgate_graph.graph_performance import GraphPerformance

graph = GraphPerformance(picture_dpi)
return graph.generate_from_file(self._output_file, os.path.join(output_graph_dir,"graph-perf"), suppress_error)
return ParallelExecutor.create_graph_static(self._output_file,
os.path.join(output_graph_dir,"graph-perf"),
GraphScope.perf,
picture_dpi,
suppress_error)

def create_graph_exec(self, output_graph_dir="output", picture_dpi=100, suppress_error = False) -> list[str]:
"""
Generate executors graph(s) based on output from performance tests
Generate executors graph(s) based on output from performance tests.
The outputs will be in subdirectory 'graph-exec'.
:param output_graph_dir: directory for graph outputs (with subdirectory 'graph-exec')
:param picture_dpi: quality of picture (default is 100 DPI)
:param suppress_error: suppress error (default is False)
:return: list of output files
"""
from qgate_graph.graph_executor import GraphExecutor

graph = GraphExecutor(picture_dpi)
return graph.generate_from_file(self._output_file,os.path.join(output_graph_dir,"graph-exec"), suppress_error)
return ParallelExecutor.create_graph_static(self._output_file,
os.path.join(output_graph_dir,"graph-exec"),
GraphScope.exe,
picture_dpi,
suppress_error)
2 changes: 1 addition & 1 deletion qgate_perf/standard_deviation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class StandardDeviation:
Welford's alg for incrementally calculation of standard deviation
"""

def __init__(self, ddof=1):
def __init__(self, ddof = 1):
self.ddof, self.n, self.mean, self.M2 = ddof, 0, 0.0, 0.0

def include(self, data):
Expand Down
2 changes: 1 addition & 1 deletion qgate_perf/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Store the version here so:

__version__ = '0.4.19'
__version__ = '0.4.20'
28 changes: 28 additions & 0 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from qgate_perf.parallel_executor import ParallelExecutor
from qgate_perf.parallel_probe import ParallelProbe
from qgate_perf.run_setup import RunSetup
from qgate_perf.executor_helper import GraphScope
import time
from os import path
import shutil
Expand Down Expand Up @@ -139,3 +140,30 @@ def test_graph_runbulkexecutor_exception_random(self):
self.assertTrue(len(file) == 1)
print(file[0])

def test_graph_scope(self):
generator = ParallelExecutor(prf_test,
label="test_graph_scope",
detail_output=True,
output_file=path.join(self.OUTPUT_ADR, "perf_test_graph_scope.txt"))

setup = RunSetup(duration_second=1, start_delay=2, parameters=None)
self.assertTrue(generator.run_bulk_executor([[10, 10]],
[[1, 2, 'Austria perf'],
[1, 4, 'Germany perf']],
setup))
generator.create_graph(self.OUTPUT_ADR, GraphScope.perf)

today = datetime.datetime.now().strftime("%Y-%m-%d")
file=glob.glob(path.join(self.OUTPUT_ADR, "graph-perf", "1 sec", today, f"PRF-test_graph_scope-*-bulk-10x10.png"))
self.assertTrue(len(file) == 1)
print(file[0])
file=glob.glob(path.join(self.OUTPUT_ADR, "graph-exec", "1 sec", today, f"EXE-test_graph_scope-*-bulk-10x10-*.png"))
self.assertTrue(len(file) == 0) # without these file


generator.create_graph(self.OUTPUT_ADR, GraphScope.exe)

today = datetime.datetime.now().strftime("%Y-%m-%d")
file=glob.glob(path.join(self.OUTPUT_ADR, "graph-exec", "1 sec", today, f"EXE-test_graph_scope-*-bulk-10x10-*.png"))
self.assertTrue(len(file) == 2)
print(file[0])

0 comments on commit 8216f6a

Please sign in to comment.