From c58fb527ccdf300164985664b5aa4a5afaa20c6e Mon Sep 17 00:00:00 2001 From: nyanpasu64 <nyanpasu64@tuta.io> Date: Wed, 15 Aug 2018 18:19:27 -0700 Subject: [PATCH] Add config parameter for benchmarking --- ovgenpy/ovgenpy.py | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/ovgenpy/ovgenpy.py b/ovgenpy/ovgenpy.py index a6ac150..ef057aa 100644 --- a/ovgenpy/ovgenpy.py +++ b/ovgenpy/ovgenpy.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import time -from typing import Optional, List +from enum import unique, IntEnum +from typing import Optional, List, Union from ovgenpy import outputs from ovgenpy.channel import Channel, ChannelConfig @@ -16,6 +17,13 @@ from ovgenpy.wave import Wave RENDER_PROFILING = True +@unique +class BenchmarkMode(IntEnum): + NONE = 0 + TRIGGER = 1 + RENDER = 2 + OUTPUT = 3 + @register_config(always_dump='wave_prefix') class Config: @@ -35,10 +43,20 @@ class Config: outputs: List[outputs.IOutputConfig] + benchmark_mode: Union[str, BenchmarkMode] = 'NONE' + @property def render_width_s(self) -> float: return self.width_ms / 1000 + def __post_init__(self): + try: + self.benchmark_mode = BenchmarkMode[self.benchmark_mode] + except KeyError: + raise ValueError( + f'invalid benchmark_mode mode {self.benchmark_mode} not in ' + f'{[el.name for el in BenchmarkMode]}') + _FPS = 60 # f_s @@ -104,6 +122,9 @@ class Ovgen: if RENDER_PROFILING: begin = time.perf_counter() + benchmark_mode = self.cfg.benchmark_mode + not_benchmarking = not benchmark_mode + # For each frame, render each wave prev = -1 for frame in range(nframes): @@ -120,17 +141,23 @@ class Ovgen: sample = round(wave.smp_s * time_seconds) region_len = round(wave.smp_s * render_width_s) - trigger_sample = channel.trigger.get_trigger(sample) + if not_benchmarking or benchmark_mode == BenchmarkMode.TRIGGER: + trigger_sample = channel.trigger.get_trigger(sample) + else: + trigger_sample = sample + datas.append(wave.get_around( trigger_sample, region_len, channel.render_subsampling)) - # Render frame - renderer.render_frame(datas) + if not_benchmarking or benchmark_mode >= BenchmarkMode.RENDER: + # Render frame + renderer.render_frame(datas) - # Output frame - frame = renderer.get_frame() - for output in self.outputs: - output.write_frame(frame) + if not_benchmarking or benchmark_mode == BenchmarkMode.OUTPUT: + # Output frame + frame = renderer.get_frame() + for output in self.outputs: + output.write_frame(frame) if RENDER_PROFILING: # noinspection PyUnboundLocalVariable