Skip to content

Commit 94c69d7

Browse files
[CPP-31]Disk Usage benchmark. (#13)
* [CPP-31]Disk Usage benchmark. * Respond to review requests. * Respond to review requests.
1 parent 6f1c8d8 commit 94c69d7

File tree

7 files changed

+145
-90
lines changed

7 files changed

+145
-90
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ jobs:
211211
bash ./.github/ci-build.sh
212212
echo "RELEASE_ARCHIVE=$(cat release-archive.filename)" >>$GITHUB_ENV
213213
echo "BENCH_ARCHIVE=$(cat bench.filename)" >>$GITHUB_ENV
214+
- name: ${{ runner.os }} Installer Size Benchmark.
215+
env:
216+
OS_NAME: ${{ runner.os }}
217+
shell: bash
218+
run: |
219+
cargo make disk-usage-bench
214220
- uses: actions/upload-artifact@v2
215221
with:
216222
name: ${{ runner.os }}-artifacts

Makefile.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,9 @@ conda run -n $CONDA_ENV python console_backend/benches/benchmarks.py
202202

203203
[tasks.benches]
204204
dependencies = ["bench-rust", "bench-rust-validate"]
205+
206+
[tasks.disk-usage-bench]
207+
script_runner = "@shell"
208+
script = '''
209+
conda run -n $CONDA_ENV python utils/disk_usage_benchmarks.py
210+
'''

poetry.lock

Lines changed: 77 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ disable=bad-continuation,
1818
too-many-nested-blocks,
1919
fixme,
2020
ungrouped-imports,
21+
duplicate-code,
2122

2223
[FORMAT]
2324
max-line-length=120

utils/create_nuitka_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def create_nuitka_script():
2222
for root, _, files in os.walk(f"{CONDA_DIR}/{SITEPACK_DIR}PySide2/Qt", topdown=False):
2323
for name in files:
2424
path = os.path.relpath(os.path.join(root, name), f"{CONDA_DIR}/{SITEPACK_DIR}")
25-
if any([x in path for x in BLACKLIST]):
25+
if [x in path for x in BLACKLIST]:
2626
continue
2727
out += f"--include-data-file={CONDA_PREFIX}/{SITEPACK_DIR}{path}={path} "
2828

utils/disk_usage_benchmarks.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import subprocess
2+
import sys
3+
4+
WINDOWS = "win32"
5+
MACOS = "darwin"
6+
LINUX = "linux"
7+
NAME = "name"
8+
FILE_PATH = "file_path"
9+
EXPECTED = "expected"
10+
ERROR_MARGIN_FRAC = "error_margin_frac"
11+
12+
DISK_USAGE_COMMAND = lambda file_path: f"du -ch {file_path} | grep total"
13+
14+
INSTALLER_BENCHMARKS = {
15+
WINDOWS: [
16+
{NAME: "Windows Installer", FILE_PATH: "release-archive.filename", EXPECTED: 55, ERROR_MARGIN_FRAC: 0.05,},
17+
],
18+
MACOS: [{NAME: "macOS Installer", FILE_PATH: "release-archive.filename", EXPECTED: 95, ERROR_MARGIN_FRAC: 0.05,},],
19+
LINUX: [{NAME: "Linux Installer", FILE_PATH: "release-archive.filename", EXPECTED: 85, ERROR_MARGIN_FRAC: 0.05,},],
20+
}
21+
22+
23+
def run_disk_usage_benchmark():
24+
"""Runner for disk usage benchmark validations.
25+
"""
26+
os_ = sys.platform
27+
benchmarks = INSTALLER_BENCHMARKS.get(os_, [])
28+
for bench in benchmarks:
29+
release_file = ""
30+
with open(bench[FILE_PATH]) as archive_file:
31+
release_file = archive_file.readline().rstrip()
32+
33+
bench_command = DISK_USAGE_COMMAND(release_file)
34+
disk_usage = subprocess.run(bench_command, shell=True, text=True, check=True, capture_output=True)
35+
print(disk_usage)
36+
disk_usage, _ = disk_usage.stdout.split("\t")
37+
print(disk_usage)
38+
39+
disk_usage = float(disk_usage.rstrip("M"))
40+
assert disk_usage is not None, f"Test:{bench[NAME]} retrieved bench value None."
41+
assert disk_usage >= bench[ERROR_MARGIN_FRAC] * bench[EXPECTED], (
42+
f"Test:{bench[NAME]} Bench Value:{disk_usage} not larger than "
43+
f"{bench[ERROR_MARGIN_FRAC]*bench[EXPECTED]}MB."
44+
)
45+
assert disk_usage - bench[EXPECTED] <= bench[ERROR_MARGIN_FRAC] * bench[EXPECTED], ( # type: ignore
46+
f"Test:{bench[NAME]} Bench Value:{disk_usage} not within "
47+
f"{bench[ERROR_MARGIN_FRAC]} of {bench[EXPECTED]}."
48+
)
49+
print(f"PASS - {os_}:{bench[NAME]} MARGIN={disk_usage - bench[EXPECTED]}")
50+
51+
52+
if __name__ == "__main__":
53+
run_disk_usage_benchmark()

utils/get_fbs_remove_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def create_remove_negligibles_file():
1717
for root, _, files in os.walk(f"{INSTALLER_DIR}", topdown=False):
1818
for name in files:
1919
path = os.path.relpath(os.path.join(root, name), f"{INSTALLER_DIR}")
20-
if not any([x in path for x in BLACKLIST]):
20+
if not [x in path for x in BLACKLIST]:
2121
continue
2222
out += f'rm -rf "{INSTALLER_DIR}/{path}" && '
2323
filename_prefix = SYS_PLATFORM_PREFIXS.get(sys.platform, "unknown")

0 commit comments

Comments
 (0)