Skip to content

toolbar

BenchmarkToolbar

BenchmarkToolbar(main: MainWindow)

Bases: AbstractToolbar

Source code
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def __init__(self, main: MainWindow) -> None:
    super().__init__(main, BenchmarkSettings(self))

    self.setup_ui()

    self.running = False
    self.unsequenced = False
    self.buffer = deque[Future[vs.VideoFrame]]()
    self.run_start_time = 0.0
    self.start_frame = Frame(0)
    self.end_frame = Frame(0)
    self.total_frames = Frame(0)
    self.benchmark_data = None

    self.sequenced_timer = Timer(
        timeout=self._request_next_frame_sequenced, timerType=Qt.TimerType.PreciseTimer, interval=0
    )

    self.update_info_timer = Timer(timeout=self.update_info, timerType=Qt.TimerType.PreciseTimer)

    self.main.reload_before_signal.connect(self.abort)

    self.set_qobject_names()

benchmark_data instance-attribute

benchmark_data = None

buffer instance-attribute

buffer = deque[Future[VideoFrame]]()

class_storable_attrs class-attribute instance-attribute

class_storable_attrs = tuple[str, ...](('settings', 'visibility'))

end_frame instance-attribute

end_frame = Frame(0)

hlayout instance-attribute

hlayout: HBoxLayout

is_notches_visible property

is_notches_visible: bool

main instance-attribute

main: MainWindow = main

name instance-attribute

name: str = __name__[:-7]

notches_changed class-attribute instance-attribute

notches_changed = pyqtSignal(ExtendedWidget)

num_keys class-attribute instance-attribute

num_keys = [
    Key_1,
    Key_2,
    Key_3,
    Key_4,
    Key_5,
    Key_6,
    Key_7,
    Key_8,
    Key_9,
    Key_0,
]

run_start_time instance-attribute

run_start_time = 0.0

running instance-attribute

running = False

sequenced_timer instance-attribute

sequenced_timer = Timer(
    timeout=_request_next_frame_sequenced, timerType=PreciseTimer, interval=0
)

settings instance-attribute

start_frame instance-attribute

start_frame = Frame(0)

storable_attrs class-attribute instance-attribute

storable_attrs = tuple[str, ...]()

toggle_button instance-attribute

toggle_button = PushButton(name, self, checkable=True, clicked=on_toggle)

total_frames instance-attribute

total_frames = Frame(0)

unsequenced instance-attribute

unsequenced = False

update_info_timer instance-attribute

update_info_timer = Timer(timeout=update_info, timerType=PreciseTimer)

visibility instance-attribute

visibility = False

vlayout instance-attribute

vlayout: VBoxLayout

abort

abort() -> None
Source code
185
186
187
188
189
190
191
192
193
194
def abort(self) -> None:
    if self.running:
        self.update_info()
        self._save_benchmark_results()

    self.running = False
    QMetaObject.invokeMethod(self.update_info_timer, 'stop', Qt.ConnectionType.QueuedConnection)

    if self.run_abort_button.isChecked():
        self.run_abort_button.click()

get_notches

get_notches() -> Notches
Source code
405
406
407
def get_notches(self) -> Notches:
    from .custom import Notches
    return Notches()

get_separator

get_separator(horizontal: bool = False) -> QFrame
Source code
318
319
320
321
322
def get_separator(self, horizontal: bool = False) -> QFrame:
    separator = QFrame(self)
    separator.setFrameShape(QFrame.Shape.HLine if horizontal else QFrame.Shape.VLine)
    separator.setFrameShadow(QFrame.Shadow.Sunken)
    return separator

init_notches

init_notches(main: MainWindow = ...) -> None
Source code
402
403
def init_notches(self, main: MainWindow = ...) -> None:
    self.notches_changed.connect(main.timeline.update_notches)

on_current_frame_changed

on_current_frame_changed(frame: Frame) -> None
Source code
471
472
def on_current_frame_changed(self, frame: Frame) -> None:
    pass

on_current_output_changed

on_current_output_changed(index: int, prev_index: int) -> None
Source code
117
118
119
120
121
122
def on_current_output_changed(self, index: int, prev_index: int) -> None:
    max_frames = 1000 if self.main.current_output is None else self.main.current_output.total_frames
    self.start_frame_control.setMaximum(max_frames - 1)
    self.end_frame_control.setMaximum(max_frames - 1)
    self.total_frames_control.setMaximum(max_frames)
    self.total_frames_control.setValue(min(self.total_frames_control.value() or 1000, max_frames))

on_prefetch_changed

on_prefetch_changed(new_state: CheckState) -> None
Source code
231
232
233
234
235
236
237
238
def on_prefetch_changed(self, new_state: Qt.CheckState) -> None:
    if new_state == Qt.CheckState.Checked:
        self.unsequenced_checkbox.setEnabled(True)
        self.usable_cpus_spinbox.setEnabled(True)
    elif new_state == Qt.CheckState.Unchecked:
        self.unsequenced_checkbox.setChecked(False)
        self.unsequenced_checkbox.setEnabled(False)
        self.usable_cpus_spinbox.setEnabled(False)

on_run_abort_pressed

on_run_abort_pressed(checked: bool) -> None
Source code
224
225
226
227
228
229
def on_run_abort_pressed(self, checked: bool) -> None:
    self.set_ui_editable(not checked)
    if checked:
        self.run()
    else:
        self.abort()

on_toggle

on_toggle(new_state: bool) -> None
Source code
461
462
463
464
465
466
467
468
469
def on_toggle(self, new_state: bool) -> None:
    if new_state == self.visibility:
        return

    # invoking order matters
    self.setVisible(new_state)
    self.visibility = new_state
    self.toggle_button.setChecked(new_state)
    self.resize_main_window(new_state)

resize_main_window

resize_main_window(expanding: bool) -> None
Source code
481
482
483
484
485
486
487
488
489
def resize_main_window(self, expanding: bool) -> None:
    if self.main.windowState() in {Qt.WindowState.WindowMaximized, Qt.WindowState.WindowFullScreen}:
        return

    if expanding:
        self.main.resize(self.main.width(), self.main.height() + self.height() + round(6 * self.main.display_scale))
    if not expanding:
        self.main.resize(self.main.width(), self.main.height() - self.height() - round(6 * self.main.display_scale))
        self.main.timeline.update()

run

run() -> None
Source code
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
def run(self) -> None:
    if self.settings.clear_cache_enabled:
        from vstools.utils.vs_proxy import clear_cache
        clear_cache()

    if self.settings.frame_data_sharing_fix_enabled:
        self.main.current_output.update_graphic_item(
            self.main.current_scene.pixmap().copy(),
            graphics_scene_item=self.main.current_output.graphics_scene_item
        )

    self.frames_done = 0

    self.start_frame = self.start_frame_control.value()
    self.end_frame = self.end_frame_control.value()
    self.total_frames = self.total_frames_control.value()

    if self.prefetch_checkbox.isChecked():
        concurrent_requests_count = self.usable_cpus_spinbox.value()
    else:
        concurrent_requests_count = 1

    self.unsequenced = self.unsequenced_checkbox.isChecked()
    if not self.unsequenced:
        self.buffer = deque([], concurrent_requests_count)
        self.sequenced_timer.start()

    self.running = True
    self.run_start_time = perf_counter()

    # Initialize benchmark data if logging is enabled
    if self.settings.log_results_enabled:
        self.benchmark_data = {
            'Date & Time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
            'Node': self.main.current_output.name,
            'Index': self.main.current_output.index,
            'Start': int(self.start_frame),
            'End': int(self.end_frame),
            'Frames Processed': 0,
            'Average FPS': 0.0,
            'Total Time (s)': 0.0,
            'Thread Count': concurrent_requests_count,
            'Prefetch': self.prefetch_checkbox.isChecked(),
            'Unsequenced': self.unsequenced_checkbox.isChecked(),
        }

        logging.debug(f"Initial benchmark data: {self.benchmark_data}")

    self.update_info()

    for offset in range(min(int(self.end_frame - self.frames_done), concurrent_requests_count)):
        if self.unsequenced:
            self._request_next_frame_unsequenced()
        else:
            self.buffer.appendleft(
                self.main.current_output.source.original_clip.get_frame_async(self.start_frame + offset)
            )

    self.update_info_timer.setInterval(round(float(self.settings.refresh_interval) * 1000))
    self.update_info_timer.start()

set_qobject_names

set_qobject_names() -> None
Source code
279
280
281
282
283
284
285
286
287
288
289
290
291
292
def set_qobject_names(self) -> None:
    if not hasattr(self, '__slots__'):
        return

    slots = list(self.__slots__)

    if isinstance(self, AbstractToolbar) and 'main' in slots:
        slots.remove('main')

    for attr_name in slots:
        attr = getattr(self, attr_name)
        if not isinstance(attr, QObject):
            continue
        attr.setObjectName(type(self).__name__ + '.' + attr_name)

set_ui_editable

set_ui_editable(new_state: bool) -> None
Source code
240
241
242
243
244
245
def set_ui_editable(self, new_state: bool) -> None:
    self. start_frame_control.setEnabled(new_state)
    self.end_frame_control.setEnabled(new_state)
    self.total_frames_control.setEnabled(new_state)
    self.prefetch_checkbox.setEnabled(new_state)
    self. unsequenced_checkbox.setEnabled(new_state)

setup_ui

setup_ui() -> None
Source code
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def setup_ui(self) -> None:
    super().setup_ui()

    self.start_frame_control = FrameEdit(
        self, 0, maximum=10000, valueChanged=lambda value: self.update_controls(start=value)
    )
    self.end_frame_control = FrameEdit(
        self, maximum=10000, valueChanged=lambda value: self.update_controls(end=value)
    )
    self.total_frames_control = FrameEdit(
        self, 1, maximum=10000, valueChanged=lambda value: self.update_controls(total=value)
    )
    self.total_frames_control.setValue(1000)

    self.unsequenced_checkbox = CheckBox(
        'Unsequenced', self, checked=True, tooltip=(
            "If enabled, next frame will be requested each time frameserver returns completed frame.\n"
            "If disabled, first frame that's currently processing will be waited before requesting the next one."
        )
    )

    self.prefetch_checkbox = CheckBox(
        'Prefetch', self, checked=True, tooltip='Request multiple frames in advance.',
        stateChanged=self.on_prefetch_changed
    )

    self.run_abort_button = PushButton('Run', self, checkable=True, clicked=self.on_run_abort_pressed)

    self.info_label = QLabel(self)

    self.usable_cpus_spinbox = SpinBox(self, 1, self.settings.default_usable_cpus_spinbox.maximum())
    self.usable_cpus_spinbox.setValue(self.settings.default_usable_cpus_count)

    self.hlayout.addWidgets([
        QLabel('Start:'), self.start_frame_control,
        QLabel('End:'), self.end_frame_control,
        QLabel('Total:'), self.total_frames_control,
        QLabel('Usable CPUs Count:'), self.usable_cpus_spinbox,
        self.prefetch_checkbox,
        self.unsequenced_checkbox,
        self.settings.log_results_checkbox,
        self.run_abort_button,
        self.info_label
    ])
    self.hlayout.addStretch()

update_controls

update_controls(
    start: Frame | None = None,
    end: Frame | None = None,
    total: Frame | None = None,
) -> None
Source code
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
def update_controls(
    self, start: Frame | None = None, end: Frame | None = None, total: Frame | None = None
) -> None:
    if not hasattr(self.main, 'current_output'):
        return

    if self.main.current_output is None:
        max_frames = 1000
    else:
        max_frames = self.main.current_output.total_frames

    if start is not None:
        end = self.end_frame_control.value()
        total = self.total_frames_control.value()

        if start > end:
            end = start
        total = end - start + Frame(1)
    elif end is not None:
        start = self.start_frame_control.value()
        total = self.total_frames_control.value()

        if end < start:
            start = end
        total = end - start + Frame(1)
    elif total is not None:
        start = self.start_frame_control.value()
        end = self.end_frame_control.value()
        old_total = end - start + Frame(1)
        delta = total - old_total

        end += delta
        if end > (e := max_frames - 1):
            start -= end - e
            end = e
    else:
        return

    qt_silent_call(self.start_frame_control.setValue, start)
    qt_silent_call(self.end_frame_control.setValue, end)
    qt_silent_call(self.total_frames_control.setValue, total)

update_info

update_info() -> None
Source code
289
290
291
292
293
294
295
def update_info(self) -> None:
    run_time = Time(seconds=(perf_counter() - self.run_start_time))
    fps = int(self.frames_done) / float(run_time)

    self.info_label.setText(
        f"{self.frames_done}/{self.total_frames} frames in {strfdelta(run_time, '%M:%S.%Z')}, {fps:.4f} fps"
    )