71 lines
2.8 KiB
Python
71 lines
2.8 KiB
Python
"""Measure rule-table allocation/refresh and unopened detail controls, without CAD."""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
from statistics import median
|
|
import subprocess
|
|
import sys
|
|
from time import perf_counter
|
|
from types import ModuleType, SimpleNamespace
|
|
|
|
os.environ.setdefault('QT_QPA_PLATFORM', 'offscreen')
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'src'))
|
|
|
|
from PySide6.QtCore import QCoreApplication, QEvent
|
|
from PySide6.QtWidgets import QApplication, QCheckBox, QWidget
|
|
|
|
|
|
def load_class(module, name, revision):
|
|
if revision:
|
|
source = subprocess.check_output(
|
|
['git', 'show', f'{revision}:src/dx_productivity/trial_task_center/ui/{module}.py'],
|
|
encoding='utf-8')
|
|
namespace = ModuleType(module)
|
|
exec(compile(source, f'{revision}/{module}.py', 'exec'), namespace.__dict__)
|
|
return getattr(namespace, name)
|
|
import importlib
|
|
return getattr(importlib.import_module(f'dx_productivity.trial_task_center.ui.{module}'), name)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--revision', help='Baseline Git revision; omit to measure workspace')
|
|
parser.add_argument('--output', type=Path)
|
|
args = parser.parse_args()
|
|
app = QApplication([])
|
|
mapping = load_class('mapping_table', 'MappingTable', args.revision)
|
|
panel_type = load_class('run_panel', 'RunPanel', args.revision)
|
|
rules = tuple(SimpleNamespace(rule_id=str(i), old_part_number=f'OLD{i}', new_part_number='NEW',
|
|
custom_value_enabled=False, sync_nc=True, enabled=True, position=i) for i in range(1000))
|
|
samples = []
|
|
for _ in range(3):
|
|
table = mapping()
|
|
started = perf_counter()
|
|
table.populate(rules)
|
|
first = perf_counter() - started
|
|
widgets = len(table.findChildren(QWidget))
|
|
checkboxes = len(table.findChildren(QCheckBox))
|
|
started = perf_counter()
|
|
table.populate(rules)
|
|
refresh = perf_counter() - started
|
|
samples.append((first, refresh))
|
|
table.deleteLater()
|
|
QCoreApplication.sendPostedEvents(None, QEvent.Type.DeferredDelete)
|
|
panel = panel_type()
|
|
result = dict(revision=args.revision or 'workspace', rules=len(rules), samples=3,
|
|
first_ms=median(s[0] for s in samples) * 1000,
|
|
unchanged_refresh_ms=median(s[1] for s in samples) * 1000,
|
|
table_widgets=widgets, checkbox_widgets=checkboxes,
|
|
unopened_run_panel_widgets=len(panel.findChildren(QWidget)))
|
|
text = json.dumps(result, ensure_ascii=False, indent=2)
|
|
if args.output:
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
args.output.write_text(text + '\n', encoding='utf-8')
|
|
print(text)
|
|
panel.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|