Add config parameter for benchmarking

pull/357/head
nyanpasu64 2018-08-15 18:19:27 -07:00
rodzic f0da6c682e
commit c58fb527cc
1 zmienionych plików z 35 dodań i 8 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
from typing import Optional, List from enum import unique, IntEnum
from typing import Optional, List, Union
from ovgenpy import outputs from ovgenpy import outputs
from ovgenpy.channel import Channel, ChannelConfig from ovgenpy.channel import Channel, ChannelConfig
@ -16,6 +17,13 @@ from ovgenpy.wave import Wave
RENDER_PROFILING = True RENDER_PROFILING = True
@unique
class BenchmarkMode(IntEnum):
NONE = 0
TRIGGER = 1
RENDER = 2
OUTPUT = 3
@register_config(always_dump='wave_prefix') @register_config(always_dump='wave_prefix')
class Config: class Config:
@ -35,10 +43,20 @@ class Config:
outputs: List[outputs.IOutputConfig] outputs: List[outputs.IOutputConfig]
benchmark_mode: Union[str, BenchmarkMode] = 'NONE'
@property @property
def render_width_s(self) -> float: def render_width_s(self) -> float:
return self.width_ms / 1000 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 _FPS = 60 # f_s
@ -104,6 +122,9 @@ class Ovgen:
if RENDER_PROFILING: if RENDER_PROFILING:
begin = time.perf_counter() begin = time.perf_counter()
benchmark_mode = self.cfg.benchmark_mode
not_benchmarking = not benchmark_mode
# For each frame, render each wave # For each frame, render each wave
prev = -1 prev = -1
for frame in range(nframes): for frame in range(nframes):
@ -120,17 +141,23 @@ class Ovgen:
sample = round(wave.smp_s * time_seconds) sample = round(wave.smp_s * time_seconds)
region_len = round(wave.smp_s * render_width_s) 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( datas.append(wave.get_around(
trigger_sample, region_len, channel.render_subsampling)) trigger_sample, region_len, channel.render_subsampling))
# Render frame if not_benchmarking or benchmark_mode >= BenchmarkMode.RENDER:
renderer.render_frame(datas) # Render frame
renderer.render_frame(datas)
# Output frame if not_benchmarking or benchmark_mode == BenchmarkMode.OUTPUT:
frame = renderer.get_frame() # Output frame
for output in self.outputs: frame = renderer.get_frame()
output.write_frame(frame) for output in self.outputs:
output.write_frame(frame)
if RENDER_PROFILING: if RENDER_PROFILING:
# noinspection PyUnboundLocalVariable # noinspection PyUnboundLocalVariable