Benchmark the Linux desktop build
Add a Ziran benchmark (tests/desktop_benchmark*.zi; make desktop-benchmark and desktop-benchmark-build) for moving the Linux desktop build off raylib. It drives the app through the Kryon test driver on a private Xvfb with a seeded profile and no audio device: screen switches, a 240-item list scrolled by wheel, a modal, a floating practice window, then 30 s idle. It reports time to first frame, frame rate and frame cost, idle CPU, resident memory, build times, generated C, executable size and libraries, each as a median over runs with its range. Under APP_PROFILE the app now logs when each host frame begins and the process CPU time then, so the benchmark can take per-frame intervals. plans/2026-11-15-breeze-desktop-without-raylib.md records the method, the raylib baseline measured with the installed build, and the call-site map for the port.
This commit is contained in:
1 parent
385449fd38
commit
0dc9ba9007
13 files changed
+1626
No files matched your search
@@ -890,4 +890,5 @@ include mk/tests-android.mk
|
||||
include mk/tests-web.mk
|
||||
include mk/tests-apps.mk
|
||||
include mk/tests-ui.mk
|
||||
include mk/tests-benchmark.mk
|
||||
include mk/tests-suite.mk
|
||||
@@ -0,0 +1,40 @@
|
||||
# The desktop benchmark (tests/desktop_benchmark.zi), which measures the Linux
|
||||
# desktop build the same way before and after a change of desktop host. Its
|
||||
# runtime scenario needs an executable built with the test driver:
|
||||
#
|
||||
# build-queue -- make native KRYON_TEST_DRIVER=1
|
||||
# build-queue -- make desktop-benchmark BENCHMARK_LABEL=before
|
||||
# build-queue -- make desktop-benchmark-build BENCHMARK_LABEL=before
|
||||
#
|
||||
# Results go to build/desktop-benchmark/LABEL/ as Markdown and TSV.
|
||||
|
||||
DESKTOP_BENCHMARK_DIR := $(BUILD_DIR)/desktop-benchmark
|
||||
DESKTOP_BENCHMARK := $(DESKTOP_BENCHMARK_DIR)/desktop-benchmark
|
||||
DESKTOP_BENCHMARK_SOURCES := $(wildcard tests/desktop_benchmark*.zi) \
|
||||
$(KRYON_DIR)/src/backend/test_driver_client.zi
|
||||
BENCHMARK_RUNS ?= 5
|
||||
BENCHMARK_LABEL ?= current
|
||||
BENCHMARK_OUT := $(abspath $(DESKTOP_BENCHMARK_DIR)/$(BENCHMARK_LABEL))
|
||||
|
||||
$(DESKTOP_BENCHMARK): $(DESKTOP_BENCHMARK_SOURCES) $(ZIRAN_BIN) $(SQLITE_AMALGAMATION_C)
|
||||
rm -rf $(DESKTOP_BENCHMARK_DIR)/c
|
||||
mkdir -p $(DESKTOP_BENCHMARK_DIR)/c
|
||||
$(ZIRAN_BIN) build --target=c --root tests --module-path $(KRYON_DIR)/src/backend \
|
||||
--module-path $(ZIRAN_DIR)/std -o $(DESKTOP_BENCHMARK_DIR)/c tests/desktop_benchmark.zi
|
||||
$(CC) -O1 -w -c -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
|
||||
$(SQLITE_AMALGAMATION_C) -o $(DESKTOP_BENCHMARK_DIR)/sqlite3.o
|
||||
$(CC) -O2 -I$(ZIRAN_DIR)/include -I$(DESKTOP_BENCHMARK_DIR)/c \
|
||||
$$(find $(DESKTOP_BENCHMARK_DIR)/c -name '*.c' | LC_ALL=C sort) \
|
||||
$(DESKTOP_BENCHMARK_DIR)/sqlite3.o -lm -o $@
|
||||
|
||||
.PHONY: desktop-benchmark-tool desktop-benchmark desktop-benchmark-build
|
||||
desktop-benchmark-tool: $(DESKTOP_BENCHMARK)
|
||||
|
||||
desktop-benchmark: $(DESKTOP_BENCHMARK)
|
||||
@test -x $(TARGET) || { echo "Build the app first: KRYON_TEST_DRIVER=1 make native" >&2; exit 1; }
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS \
|
||||
-u SESSION_MANAGER -u GDK_DISPLAY YUE_DESKTOP_RECOVERY=0 \
|
||||
$(DESKTOP_BENCHMARK) run $(abspath $(TARGET)) $(CURDIR) $(BENCHMARK_OUT) $(BENCHMARK_RUNS)
|
||||
|
||||
desktop-benchmark-build: $(DESKTOP_BENCHMARK)
|
||||
$(DESKTOP_BENCHMARK) build $(CURDIR) $(BENCHMARK_OUT) $(BENCHMARK_RUNS)
|
||||
@@ -0,0 +1,178 @@
|
||||
# Breeze desktop without raylib
|
||||
|
||||
Owner, 2026-11-15: "im curiosu cna we run breez withou raylib?", then, after
|
||||
hearing what it would take: "okay thats interesing i wanty ou to bencmark it
|
||||
before relpanig ralyib and after fulyl eo ndkospt" (benchmark before
|
||||
replacing raylib, and after, fully on desktop).
|
||||
|
||||
Goal: the Linux desktop build runs on Kryon's own desktop host (SDL2 window
|
||||
and input, Cairo/Pango raster) with no raylib in its link or code path, and
|
||||
every feature still works. Windows, web and Android keep their current hosts.
|
||||
The same benchmark runs before and after.
|
||||
|
||||
## Benchmark method
|
||||
|
||||
Harness: `tests/desktop_benchmark*.zi` (Ziran), built and run by
|
||||
`mk/tests-benchmark.mk`. It drives the app with the Kryon test driver
|
||||
(`test_driver_client`), so the executable must be built with
|
||||
`KRYON_TEST_DRIVER=1`.
|
||||
|
||||
```sh
|
||||
build-queue -- make native KRYON_TEST_DRIVER=1
|
||||
build-queue -- make desktop-benchmark BENCHMARK_LABEL=before # 5 runs
|
||||
build-queue -- make desktop-benchmark-build BENCHMARK_LABEL=before # 5 builds
|
||||
```
|
||||
|
||||
Conditions, identical for both hosts:
|
||||
|
||||
- A private Xvfb at 1280x1000x24 per run; the app's default 900x720 window.
|
||||
The desktop's display, session bus, audio servers and recovery services
|
||||
are removed from the app's environment.
|
||||
- No audio device for either host: ALSA reads an empty configuration and the
|
||||
Pulse/PipeWire sockets are unreachable.
|
||||
- A profile the app creates on its first start (past the audio offer), then
|
||||
seeded by SQLite: setup and guides done, no update checks, and one list of
|
||||
240 items. Every run copies it.
|
||||
- `APP_PROFILE=1`: the app logs `PROFILE: sample wall_us= cpu_us=` as each
|
||||
host frame begins (`app_profile_frame_sample`, in the host-neutral
|
||||
`src/app/app_profile.zi`).
|
||||
|
||||
The scenario (`tests/desktop_benchmark_scenario.zi`): start up; twice through
|
||||
Habits, Lumi, Practice, Apps, Lists and Diary; scroll the 240-item list down
|
||||
40 wheel steps and back; open an app's Properties dialog from its options
|
||||
menu and close it with Escape; start a practice, float it in its own window
|
||||
for 3 s, bring it back and exit it; then 30 s idle on Habits.
|
||||
|
||||
Measurements, each over 5 runs, reported as median, range and spread
|
||||
(half the range as a percentage of the median):
|
||||
|
||||
- Clean and incremental build time. Clean removes the generated C, objects,
|
||||
source-check stamp, executable and the raylib library built for it; the
|
||||
Ziran toolchain, curl, liboqs, SQLite and codecs stay built. Incremental
|
||||
touches `src/main.zi`.
|
||||
- Generated C files and bytes, executable size, direct dynamic libraries
|
||||
(ELF `DT_NEEDED`), and raylib markers in the executable (rlgl's shader
|
||||
attribute names, miniaudio, dr_mp3), since the release executable has no
|
||||
symbol table.
|
||||
- Time to first frame: process start to the `APP PROBE: drawing ended` line.
|
||||
- Frame interval p50/p95 and CPU per frame p50/p95 during the interaction.
|
||||
- Idle CPU % over 30 s, steady RSS (median of 2 Hz samples while idle) and
|
||||
peak RSS (`VmHWM`).
|
||||
|
||||
Caveats: on Xvfb raylib's OpenGL ES 2 runs on llvmpipe (software GL), while
|
||||
Cairo draws on the CPU on any display, so these numbers compare two software
|
||||
renderers and say nothing about a real GPU. The machine is shared with other
|
||||
lanes' builds and tests; timings carry about 3–10% noise.
|
||||
|
||||
## Before (raylib host)
|
||||
|
||||
The checkout does not build at the moment, so the before numbers come from
|
||||
existing raylib executables rather than a fresh build.
|
||||
|
||||
Installed build, measured 2026-11-16 12:17–12:46 (load average 13–17 on
|
||||
32 CPUs): `/home/wao/.local/bin/breeze`, 88,609,512 bytes, built
|
||||
2026-11-13 00:16 from 939593a1 plus that day's uncommitted changes (build ID
|
||||
8247f20d57c98dacf8ab991cbdfaa0c0b842861e). It predates the per-frame samples,
|
||||
so only the 120-frame reports measure its frames.
|
||||
|
||||
| Measurement | Median | Range | Spread |
|
||||
|---|---|---|---|
|
||||
| Time to first frame (ms) | 149.1 | 148.8–170 | ±7.1% |
|
||||
| Frame rate while interacting, 120-frame reports (fps) | 60.5 | 60.5–60.5 | ±0% |
|
||||
| App frame time, 120-frame report median (ms) | 0.83 | 0.82–0.96 | ±8.4% |
|
||||
| Longest app frame while interacting (ms) | 212.3 | 47.3–333.5 | ±67.4% |
|
||||
| Idle CPU over 30 s (%) | 63.75 | 60.66–66.39 | ±4.5% |
|
||||
| Steady RSS, idle median (MiB) | 447.8 | 427.2–449.5 | ±2.5% |
|
||||
| Peak RSS (MiB) | 447.8 | 430.4–449.5 | ±2.1% |
|
||||
|
||||
Idle CPU is about two thirds of one core: the raylib host keeps drawing
|
||||
frames through llvmpipe while nothing changes.
|
||||
|
||||
| Executable | Value |
|
||||
|---|---|
|
||||
| Size | 84.5 MiB |
|
||||
| raylib markers (rlgl shader names, miniaudio, dr_mp3) | 4 of 4 |
|
||||
| Linked libraries (10) | libSDL2-2.0.so.0, libGLESv2.so.2, libssl.so.3, libcrypto.so.3, libz.so.1, libm.so.6, libatomic.so.1, libgio-2.0.so.0, libglib-2.0.so.0, libc.so.6 |
|
||||
|
||||
Not measured before: build times and generated C, which need a checkout
|
||||
that builds; per-frame intervals and CPU, which need the per-frame samples.
|
||||
The 2026-11-16 09:27 working-tree build has those samples but exits at
|
||||
startup (its embedded app bundle is in a ZX format the runtime rejects), so
|
||||
it cannot serve as the baseline. Measure both with the last raylib state of
|
||||
the checkout once it builds, before the port's commits land.
|
||||
|
||||
## Port map: raylib call sites and their replacements
|
||||
|
||||
Kryon pieces (claude-kryon-desktop-host-for-breeze builds them as small new
|
||||
modules and sends their names and calls as it pushes):
|
||||
|
||||
- K1 desktop window and input: events routed by window, a sideways wheel,
|
||||
key-down and repeat state, minimize/restore/raise/always-on-top, monitor
|
||||
size and DPI scale.
|
||||
- K2 desktop secondary windows: the `raylib_secondary_window` calls, each
|
||||
window with its own Cairo surface, presenter, session input, click, drag,
|
||||
right-click and keyboard grab.
|
||||
- K3 SDL2 audio: sounds, streamed music, pushed PCM streams, volume, pitch,
|
||||
a mix tap, and Vorbis/Opus/WAV decoding. MP3 waits on an owner decision.
|
||||
- K4 Cairo raster hooks: an asset reader for embedded assets, font
|
||||
registration from memory, and a render scale for zoom.
|
||||
|
||||
Already in Kryon's desktop host (`desktop_runtime`, `desktop_loop`):
|
||||
`OpenDesktopSized`, `CloseDesktop`, `PollDesktop`, `BeginDesktopFrame`,
|
||||
`EndDesktopFrame`, `PauseDesktop`, `DesktopViewport`, `PollPointer`,
|
||||
`PollSecondaryPointer`, `DesktopWheelMove`, `DesktopInputTake`, typed
|
||||
codepoints, `DesktopCursor`, `EndFrameRetained` with `DesktopFrameReusable`
|
||||
and `DesktopFrameUnchanged`, `frame_snapshot`, `DesktopSetTitle`,
|
||||
`DesktopSetIcon`, `DesktopWindow`, `WindowVisibleHost`, `WindowFocusedHost`,
|
||||
`WindowSetVisibleHost`, `SystemClipboard*Host`, `CaptureRequested`,
|
||||
`CaptureConfigured`. Time comes from `std/timer_linux`.
|
||||
|
||||
The Linux desktop build selects its host modules at compile time; Windows,
|
||||
Android and web keep today's raylib or canvas modules under the same names.
|
||||
|
||||
| Breeze file | raylib use today | Linux desktop replacement |
|
||||
|---|---|---|
|
||||
| `src/platform/app_host.zi` | `RunRaylibAppFrame`; `SetConfigFlags`, `SetExitKey`; `GetRenderWidth/Height`; `GetMousePosition`, `IsMouseButton*` (left, right); `GetMouseWheelMoveV`; `IsKeyPressed` (Esc, Tab, Enter, Space, arrows, Back, zoom keys); `RaylibModifiers`; `SetMouseCursor`; `SetTargetFPS`; `GetTime`; `Begin/EndRetainedFrame*`; `PumpSecondaryWindows`; `LoadImageFromScreen`, `UnloadImage`; `SetTraceLogLevel`, `RaylibTraceToConsole`; `kryon/Raylib` | A Breeze desktop loop: `PollDesktop`, `BeginDesktopFrame`, `DesktopViewport`, `PollPointer`, `PollSecondaryPointer`, `DesktopWheelMove` plus K1 sideways wheel, `DesktopInputTake` keys and modifiers plus K1 key state, `DesktopCursor`, `PauseDesktop` pacing, `EndFrameRetained`, K2 pump, `CaptureConfigured` for screenshots, `trace_log` |
|
||||
| `src/platform/raylib_host.zi` | `InitWindow`, `CloseWindow`, `ExportImage`, `RaylibUseIconTextures` | `OpenDesktopSized`, `CloseDesktop`; Cairo draws icons itself; PNG through Kryon `png`. The raylib module stays for Windows and Android |
|
||||
| `src/platform/main_platform.zi` | `TraceLog`, `IsWindowReady`, `GetWindowHandle`, `ChangeDirectory`, `GetTime`, `RaylibTraceToFile`, `RaylibTraceRecentErrors`, `RaylibTraceClose` | `trace_log` with an `inbe.log` sink and recent-error buffer; `OpenDesktopSized` result; `DesktopWindow`; `DesktopStartBeside` or libc `chdir`; timer |
|
||||
| `src/platform/raylib_text_input.zi` | `GetCharPressed`, `IsKeyPressed`, `IsKeyPressedRepeat`, `IsKeyDown`, `GetClipboardText`, `SetClipboardText` | Typed codepoints and `KeyboardSend` as `desktop_loop` does, K1 repeat state, `SystemClipboard*Host`; the module stays for Windows and Android |
|
||||
| `src/platform/practice_window_host.zi` | `raylib_secondary_window`; `RestoreWindow`, `SetWindowFocused`, `ClearWindowState` | K2; K1 restore and raise |
|
||||
| `src/breaks/app_breaks.zi` | `raylib_secondary_window`; `GetMouseWheelMove`, `GetMouseDelta`, `IsKeyPressed`, `IsWindowFocused`, `ClearWindowState`, `RestoreWindow`, `SetWindowFocused`, `GetCurrentMonitor`, `GetMonitorWidth/Height`, `GetTime` | K2 with per-window input; `WindowFocusedHost`; K1 restore, raise and monitor size; timer |
|
||||
| `src/screens/break_overlay.zi` | `IsMouseButtonPressed`, `GetMousePosition` | The break window's K2 session pointer |
|
||||
| `src/platform/desktop_tray.zi` | `IsWindowHidden`, `SetWindowState`, `ClearWindowState`, `RestoreWindow`, `MinimizeWindow`, `TraceLog`, `GetTime` | `WindowVisibleHost`, `WindowSetVisibleHost`, K1 minimize and restore, `trace_log`, timer |
|
||||
| `src/app/app_launcher_pins.zi` | `SetWindowTitle` | `DesktopSetTitle` |
|
||||
| `src/apps/node_app_tree.zi` | `IsWindowFocused`, `raylib_trace` | `WindowFocusedHost`, `trace_log` |
|
||||
| `src/app/application_update.zi` | `IsKeyPressed`, `IsKeyDown` | K1 key state |
|
||||
| `src/app/application_frame.zi` | `BeginMode2D`/`EndMode2D` (camera zoom), `BeginScissorMode`/`EndScissorMode`, `RetainedPreviousFrameTexture`, `InvalidateRaylibAssets(Under)`, `ResetRaylibGraphics` (Android), `kryon/raylib_runtime`, `raylib_trace` | K4 render scale; paint-queue clips; `frame_snapshot`; the Cairo image cache's clear; Android keeps its reset; `trace_log` |
|
||||
| `src/app/app_frame_transition.zi`, `src/app/media_compression_dialog.zi` | `Texture2D` and `FrameSurface` from retained raylib targets | `frame_snapshot` images |
|
||||
| `src/app/dpi_state.zi` | `IsWindowReady`, `GetWindowScaleDPI`, `RaylibSetZoom`, `kryon/Raylib` | K1 DPI scale, K4 render scale |
|
||||
| `src/platform/asset_files.zi` | `SetLoadFileDataCallback`, `MemAlloc`, `MemFree`, `GetFileLength` | K4 asset reader |
|
||||
| `src/app/fonts.zi` | none directly: `typeface_source` (`RegisterFontAsset`, `RegisterSystemTypeface`), which raylib implements today | K4 font registration behind the same calls |
|
||||
| `src/platform/launcher_icon.zi` | `ExportImageToMemory`, `MemFree` | Kryon `png` encoder |
|
||||
| `src/app/screenshots.zi` | `GetTime`, `WaitTime` | timer, `SleepMilliseconds` |
|
||||
| `src/app/lumi_guide.zi`, `src/screens/habits_screen.zi` | `GetTime` | timer |
|
||||
| `src/platform/trace_log.zi`, `src/app/audio_meter_host.zi` | `TraceLog` | `trace_log` on stderr and `inbe.log` |
|
||||
| `raylib_trace` importers: `src/main.zi`, `src/apps/module_host.zi`, `src/apps/node_apps.zi`, `src/screens/practice_screen.zi`, `src/app/application_init.zi`, `src/app/app_launcher_apps.zi`, `src/app/device_link_session.zi`, `src/app/app_sync.zi`, `src/app/application_modals.zi` | `TraceLog` | `trace_log` |
|
||||
| `src/platform/audio_runtime.zi` | raudio: `InitAudioDevice`, `IsAudioDeviceReady`, `CloseAudioDevice`, `LoadWave(FromMemory)`, `WaveFormat`, `LoadSound(FromWave)`, `Play/Stop/PauseSound`, `SetSoundVolume/Pitch`, `LoadMusicStream(FromMemory)`, `Play/Stop/Pause/ResumeMusicStream`, `UpdateMusicStream`, `SetMusicVolume`, `Attach/DetachAudioMixedProcessor` | K3 |
|
||||
| `src/platform/radio_native.zi` | `LoadAudioStream`, `UpdateAudioStream`, `IsAudioStreamProcessed`, `SetAudioStreamVolume`, `SetAudioStreamBufferSizeDefault`, `drmp3dec_*`, `GetTime` | K3 pushed stream; MP3 decoder per the owner's decision; timer |
|
||||
| `src/platform/voice_audio.zi` | `media_audio_raylib`, `MediaAudioUseRaylib` | K3's media-audio sink |
|
||||
| `src/screens/node_app_screen.zi` | imports `kryon/raylib_runtime`, `raylib_text_input` | Drop on Linux; bundled apps draw into Breeze's own session |
|
||||
| `apps/practice/practice_probe.zi` | `raylib_trace`, `kryon/Raylib`, `CaptureRequested`, `CaptureConfigured` | Another lane's untracked probe; follow its owner |
|
||||
| `Makefile` | builds `libraylib.a`, `KRYON_BACKEND_RAYLIB=1`, `RAY_*` flags and checks, `AVIF_RAYLIB`, raylib `SUPPORT_*` config | Native Linux links SDL2, Cairo, Pango, fontconfig and FreeType from pkg-config; Windows keeps `WIN64_RAYLIB_A`; Android and web unchanged |
|
||||
|
||||
Unchanged: Android's `GetAndroidApp` and window-state calls, and the web
|
||||
canvas host (`src/platform/web_window.zi`).
|
||||
|
||||
## Steps
|
||||
|
||||
1. Get a Breeze build to benchmark. The checkout does not build right now
|
||||
while its pins move to Kryon's namespaced widget API; the Breeze pin
|
||||
sessions (breeze-entity-kryon-master, breeze-one-format-pins) own that
|
||||
repair. Benchmark the first state that builds.
|
||||
2. Measure and record the before table; commit and push the plan, the
|
||||
harness and the numbers.
|
||||
3. Port the Linux desktop layer file by file as K1–K4 land, following the
|
||||
map above; delete the raylib code the Linux path no longer uses. Windows,
|
||||
web and Android builds must still pass.
|
||||
4. Run the same benchmark after the port and add the after table and the
|
||||
comparison here.
|
||||
@@ -6,6 +6,7 @@ c :: #system_library "c";
|
||||
#scope_file
|
||||
ProfileGetEnv :: (name: *u8) -> *u8 #foreign c "app_getenv_bytes";
|
||||
ProfileClock :: () -> float64 #foreign c "app_monotonic_seconds";
|
||||
ProfileProcessCpu :: () -> float64 #foreign c "app_process_cpu_seconds";
|
||||
ProfileLogInfo :: (line: *u8) #foreign c "app_log_line";
|
||||
#if #defined(ANDROID_DEBUG) {
|
||||
android_log :: #system_library "log";
|
||||
@@ -203,6 +204,29 @@ app_profile_work_end :: (start: float64, stage: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// One line as each host frame begins: when, on the monotonic clock, and the
|
||||
// process's CPU time so far, both in microseconds. The desktop benchmark
|
||||
// takes frame intervals and each frame's CPU cost from these lines.
|
||||
#program_export
|
||||
app_profile_frame_sample :: () {
|
||||
if !enabled() { return }
|
||||
wall := ProfileClock()
|
||||
cpu := ProfileProcessCpu()
|
||||
if wall <= 0.0 || cpu < 0.0 { return }
|
||||
line: [96]u8
|
||||
used: s32 = 0
|
||||
if !ProfileAppend(line[:], *used, "PROFILE: sample wall_us=") ||
|
||||
!ProfileAppendNumber(line[:], *used, cast(u64)(wall * 1000000.0)) ||
|
||||
!ProfileAppend(line[:], *used, " cpu_us=") ||
|
||||
!ProfileAppendNumber(line[:], *used, cast(u64)(cpu * 1000000.0)) {
|
||||
return
|
||||
}
|
||||
line[used] = cast(u8)0
|
||||
#if !#defined(ANDROID_DEBUG) {
|
||||
ProfileLogInfo(*line[0])
|
||||
}
|
||||
}
|
||||
|
||||
#program_export
|
||||
app_profile_frame_end :: (start: float64) {
|
||||
if !enabled() || start <= 0.0 { return }
|
||||
|
||||
@@ -171,6 +171,25 @@ app_monotonic_seconds :: () -> float64 {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
// CPU time every thread of this process has used, for frame profiling.
|
||||
// Platforms without a process CPU clock report 0.
|
||||
#program_export
|
||||
app_process_cpu_seconds :: () -> float64 {
|
||||
#if !#defined(_WIN32) && !#defined(PLATFORM_WEB) && !#defined(__APPLE__) {
|
||||
clock_id: s32 = 2
|
||||
#if #defined(__FreeBSD__) {
|
||||
clock_id = 15
|
||||
}
|
||||
now: HostTimespec
|
||||
if HostClockGetTime(clock_id, *now) != 0 {
|
||||
return 0.0
|
||||
}
|
||||
return cast(float64)now.seconds +
|
||||
cast(float64)now.nanoseconds / 1000000000.0
|
||||
}
|
||||
return 0.0
|
||||
}
|
||||
|
||||
#program_export
|
||||
app_log_line :: (line: *u8) {
|
||||
if line == null {
|
||||
|
||||
@@ -19,6 +19,7 @@ app_getenv_bytes :: (name: *u8) -> *u8 #foreign c;
|
||||
#import, file "../app/application.zi";
|
||||
#import, file "../app/application_init.zi";
|
||||
#import, file "../app/application_frame.zi";
|
||||
#import, file "../app/app_profile.zi";
|
||||
#import, file "../apps/module_host.zi";
|
||||
#import, file "desktop_identity.zi";
|
||||
#import, file "../app/text_buffers.zi";
|
||||
@@ -325,6 +326,7 @@ AppNavigationKey :: () -> s32 {
|
||||
|
||||
#program_export
|
||||
app_frame :: (argument: *void) {
|
||||
app_profile_frame_sample()
|
||||
app := cast(*InnerBreeze)argument
|
||||
#if #defined(ANDROID_BUILD) {
|
||||
android_timer_frame_begin()
|
||||
|
||||
@@ -0,0 +1,497 @@
|
||||
// Benchmarks Breeze's Linux desktop build, the same way before and after a
|
||||
// change of desktop host (plans/2026-11-15-breeze-desktop-without-raylib.md).
|
||||
//
|
||||
// desktop-benchmark run BINARY ROOT OUT RUNS
|
||||
// RUNS copies of one scripted session on a private Xvfb: time to the
|
||||
// first frame, frame intervals and each frame's CPU cost while it
|
||||
// interacts, CPU use over 30 idle seconds, and resident memory.
|
||||
// desktop-benchmark build ROOT OUT RUNS
|
||||
// RUNS clean and incremental `make native` builds, then `size`.
|
||||
// desktop-benchmark size ROOT OUT [EXECUTABLE]
|
||||
// Generated C, the executable's size and the libraries it links;
|
||||
// EXECUTABLE defaults to the native build in ROOT.
|
||||
//
|
||||
// The executable must be built with KRYON_TEST_DRIVER=1. Every result is a
|
||||
// median over the runs with its range, written to OUT as Markdown and TSV.
|
||||
#import "c_string"
|
||||
#import "byte_text_linux"
|
||||
#import "file"
|
||||
#import "file_tree_linux"
|
||||
#import "number_text"
|
||||
#import "process_run_linux"
|
||||
#import "text_tools"
|
||||
#import "test_driver_client"
|
||||
#import "vec"
|
||||
#import, file "desktop_benchmark_build.zi";
|
||||
#import, file "desktop_benchmark_proc.zi";
|
||||
#import, file "desktop_benchmark_profile.zi";
|
||||
#import, file "desktop_benchmark_scenario.zi";
|
||||
#import, file "desktop_benchmark_session.zi";
|
||||
#import, file "desktop_benchmark_stats.zi";
|
||||
|
||||
IDLE_SECONDS :: 30
|
||||
RSS_SAMPLE_MS :: 500
|
||||
FIRST_FRAME_TIMEOUT :: 60.0
|
||||
STARTUP_SETTLE_FRAMES :: 10
|
||||
STARTUP_SETTLE_MS :: 20000
|
||||
|
||||
// Values below 0 were not measured: a build from before the per-frame
|
||||
// samples has only the 120-frame reports.
|
||||
RunMetrics :: struct {
|
||||
first_frame_ms: float64
|
||||
report_fps: float64
|
||||
report_frame_avg_ms: float64
|
||||
report_frame_max_ms: float64
|
||||
frames: s64
|
||||
frame_p50_ms: float64
|
||||
frame_p95_ms: float64
|
||||
frame_cpu_p50_ms: float64
|
||||
frame_cpu_p95_ms: float64
|
||||
idle_cpu_percent: float64
|
||||
steady_rss_mib: float64
|
||||
peak_rss_mib: float64
|
||||
}
|
||||
|
||||
AppendFixed :: (builder: *Vec(u8), value: float64, places: s32) {
|
||||
digits: [64]u8
|
||||
Append(builder, FormatDecimal(value, places, digits[:]))
|
||||
}
|
||||
|
||||
Report :: (message: string) -> s32 {
|
||||
print("desktop-benchmark: %\n", message)
|
||||
return 1
|
||||
}
|
||||
|
||||
RunDirectory :: (out: string, name: string, index: s32) -> Text {
|
||||
path: Vec(u8)
|
||||
BuilderPrint(*path, "%/%-%", out, name, index)
|
||||
return BuilderFinish(path)
|
||||
}
|
||||
|
||||
// Frame intervals and per-frame CPU between STARTED and ENDED, in ms.
|
||||
FrameCosts :: (samples: []FrameSample, interaction: Interaction,
|
||||
metrics: *RunMetrics) {
|
||||
intervals: Vec(float64)
|
||||
cpu: Vec(float64)
|
||||
for index: cast(s64)1..samples.count - 1 {
|
||||
before := samples[index - 1]
|
||||
after := samples[index]
|
||||
if before.wall >= interaction.started && after.wall <= interaction.ended {
|
||||
VecPush(intervals, (after.wall - before.wall) * 1000.0)
|
||||
VecPush(cpu, (after.cpu - before.cpu) * 1000.0)
|
||||
}
|
||||
}
|
||||
metrics.frames = intervals.count
|
||||
if intervals.count == 0 {
|
||||
metrics.frame_p50_ms = -1.0
|
||||
metrics.frame_p95_ms = -1.0
|
||||
metrics.frame_cpu_p50_ms = -1.0
|
||||
metrics.frame_cpu_p95_ms = -1.0
|
||||
return
|
||||
}
|
||||
metrics.frame_p50_ms = Percentile(intervals[:], 0.5)
|
||||
metrics.frame_p95_ms = Percentile(intervals[:], 0.95)
|
||||
metrics.frame_cpu_p50_ms = Percentile(cpu[:], 0.5)
|
||||
metrics.frame_cpu_p95_ms = Percentile(cpu[:], 0.95)
|
||||
}
|
||||
|
||||
// The 120-frame reports written while the scenario ran: their median frame
|
||||
// rate and frame time, and the longest frame of all. False when none came.
|
||||
ReportCosts :: (reports: []ProfileReport, metrics: *RunMetrics) -> bool {
|
||||
fps: Vec(float64)
|
||||
average: Vec(float64)
|
||||
metrics.report_fps = -1.0
|
||||
metrics.report_frame_avg_ms = -1.0
|
||||
metrics.report_frame_max_ms = -1.0
|
||||
for index: cast(s64)0..reports.count - 1 {
|
||||
VecPush(fps, reports[index].fps)
|
||||
VecPush(average, reports[index].frame_avg_ms)
|
||||
if reports[index].frame_max_ms > metrics.report_frame_max_ms {
|
||||
metrics.report_frame_max_ms = reports[index].frame_max_ms
|
||||
}
|
||||
}
|
||||
if reports.count == 0 {
|
||||
return false
|
||||
}
|
||||
metrics.report_fps = Median(fps[:])
|
||||
metrics.report_frame_avg_ms = Median(average[:])
|
||||
return true
|
||||
}
|
||||
|
||||
// Thirty seconds without input: the CPU share it used and its resident
|
||||
// memory, sampled twice a second.
|
||||
MeasureIdle :: (pid: s32, metrics: *RunMetrics) -> bool {
|
||||
cpu_before := ProcessCpuSeconds(pid)
|
||||
started := NowSeconds()
|
||||
resident: Vec(float64)
|
||||
ends := started + cast(float64)IDLE_SECONDS
|
||||
while NowSeconds() < ends {
|
||||
PauseMilliseconds(RSS_SAMPLE_MS)
|
||||
kib := ResidentKib(pid)
|
||||
if kib < 0 {
|
||||
return false
|
||||
}
|
||||
VecPush(resident, cast(float64)kib / 1024.0)
|
||||
}
|
||||
cpu_after := ProcessCpuSeconds(pid)
|
||||
elapsed := NowSeconds() - started
|
||||
if cpu_before < 0.0 || cpu_after < 0.0 || elapsed <= 0.0 {
|
||||
return false
|
||||
}
|
||||
metrics.idle_cpu_percent = 100.0 * (cpu_after - cpu_before) / elapsed
|
||||
metrics.steady_rss_mib = Median(resident[:])
|
||||
return true
|
||||
}
|
||||
|
||||
Running :: struct {
|
||||
display: Display
|
||||
app: App
|
||||
}
|
||||
|
||||
// Starts a display and the app with PROFILE in DIRECTORY, driven by DRIVER.
|
||||
Launch :: (binary: string, root: string, directory: string, profile: string,
|
||||
driver: *TestDriverClient, running: *Running) -> bool {
|
||||
if !CreateDirectories(directory) || !StartDisplay(directory, *running.display) {
|
||||
return false
|
||||
}
|
||||
if !StartApp(binary, root, directory, profile, running.display.name,
|
||||
DriverEnvironment(driver), *running.app) {
|
||||
return false
|
||||
}
|
||||
DriverWatch(driver, running.app.run.pid, running.app.log)
|
||||
return true
|
||||
}
|
||||
|
||||
// A driver for the app that will run in DIRECTORY, which it creates.
|
||||
DriverIn :: (directory: string) -> TestDriverClient {
|
||||
unused CreateDirectories(directory)
|
||||
return DriverOpen(JoinPath(directory, "driver"))
|
||||
}
|
||||
|
||||
Stop :: (running: *Running) {
|
||||
StopProcess(*running.app.run)
|
||||
StopProcess(*running.display.run)
|
||||
}
|
||||
|
||||
// The profile the app creates on its first start, past its audio offer,
|
||||
// then seeded (desktop_benchmark_profile.zi). Its second start must open
|
||||
// with the navigation rail and nothing over it.
|
||||
PrepareProfile :: (binary: string, root: string, out: string) -> string {
|
||||
directory := JoinPath(out, "prepare")
|
||||
profile := JoinPath(directory, "profile")
|
||||
if PathStatus(directory, false).kind != .Missing {
|
||||
unused RemoveTree(directory)
|
||||
}
|
||||
first: Running
|
||||
first_driver := DriverIn(directory)
|
||||
if !Launch(binary, root, directory, profile, *first_driver, *first) {
|
||||
Stop(*first)
|
||||
return ""
|
||||
}
|
||||
ready := WaitFirstFrame(*first.app, FIRST_FRAME_TIMEOUT) >= 0.0
|
||||
if ready {
|
||||
unused DriverWaitIdle(*first_driver, STARTUP_SETTLE_FRAMES, STARTUP_SETTLE_MS)
|
||||
if DriverFind(*first_driver, .{label = "Not now"}) > 0 {
|
||||
ready = DriverPress(*first_driver, .{label = "Not now"})
|
||||
unused DriverWaitIdle(*first_driver, STARTUP_SETTLE_FRAMES, STARTUP_SETTLE_MS)
|
||||
}
|
||||
}
|
||||
Stop(*first)
|
||||
if !ready || !SeedProfile(profile) {
|
||||
return ""
|
||||
}
|
||||
check_directory := JoinPath(directory, "check")
|
||||
second: Running
|
||||
second_driver := DriverIn(check_directory)
|
||||
if !Launch(binary, root, check_directory, profile, *second_driver, *second) {
|
||||
Stop(*second)
|
||||
return ""
|
||||
}
|
||||
ready = WaitFirstFrame(*second.app, FIRST_FRAME_TIMEOUT) >= 0.0 &&
|
||||
DriverWait(*second_driver, .{label = "Habits"}, STARTUP_SETTLE_MS)
|
||||
Stop(*second)
|
||||
if !ready {
|
||||
return ""
|
||||
}
|
||||
return profile
|
||||
}
|
||||
|
||||
MeasureRun :: (binary: string, root: string, out: string, prepared: string,
|
||||
index: s32, metrics: *RunMetrics) -> bool {
|
||||
directory := RunDirectory(out, "run", index)
|
||||
if PathStatus(directory, false).kind != .Missing {
|
||||
unused RemoveTree(directory)
|
||||
}
|
||||
profile := JoinPath(directory, "profile")
|
||||
if !CreateDirectories(directory) || !CopyTree(prepared, profile) {
|
||||
return false
|
||||
}
|
||||
running: Running
|
||||
defer { Stop(*running) }
|
||||
driver := DriverIn(directory)
|
||||
if !Launch(binary, root, directory, profile, *driver, *running) {
|
||||
return false
|
||||
}
|
||||
first_frame := WaitFirstFrame(*running.app, FIRST_FRAME_TIMEOUT)
|
||||
if first_frame < 0.0 {
|
||||
return false
|
||||
}
|
||||
metrics.first_frame_ms = first_frame * 1000.0
|
||||
unused DriverWaitIdle(*driver, STARTUP_SETTLE_FRAMES, STARTUP_SETTLE_MS)
|
||||
interaction: Interaction
|
||||
if !RunInteraction(*driver, running.app.log, *interaction) {
|
||||
return false
|
||||
}
|
||||
if !MeasureIdle(running.app.run.pid, metrics) {
|
||||
return false
|
||||
}
|
||||
peak := PeakResidentKib(running.app.run.pid)
|
||||
metrics.peak_rss_mib = cast(float64)peak / 1024.0
|
||||
Stop(*running)
|
||||
samples := ReadFrameSamples(*running.app)
|
||||
FrameCosts(samples[:], interaction, metrics)
|
||||
reports := ReadProfileReports(*running.app, interaction.log_started, interaction.log_ended)
|
||||
return ReportCosts(reports[:], metrics) || metrics.frames > 0
|
||||
}
|
||||
|
||||
// One table row: the median, the range and the spread around the median.
|
||||
SummaryRow :: (out: *Vec(u8), name: string, values: []float64, places: s32) {
|
||||
summary := Summarize(values)
|
||||
BuilderPrint(out, "| % | ", name)
|
||||
if summary.count == 0 {
|
||||
Append(out, "n/a | n/a | n/a |\n")
|
||||
return
|
||||
}
|
||||
AppendFixed(out, summary.median, places)
|
||||
Append(out, " | ")
|
||||
AppendFixed(out, summary.minimum, places)
|
||||
Append(out, "–")
|
||||
AppendFixed(out, summary.maximum, places)
|
||||
Append(out, " | ±")
|
||||
AppendFixed(out, SpreadPercent(summary), 1)
|
||||
Append(out, "% |\n")
|
||||
}
|
||||
|
||||
// One measurement of every run, by its row number in the report.
|
||||
Column :: (runs: []RunMetrics, which: s32) -> Vec(float64) {
|
||||
values: Vec(float64)
|
||||
for index: cast(s64)0..runs.count - 1 {
|
||||
run := runs[index]
|
||||
value := run.peak_rss_mib
|
||||
if which == 0 {
|
||||
value = run.first_frame_ms
|
||||
} else if which == 9 {
|
||||
value = run.report_fps
|
||||
} else if which == 10 {
|
||||
value = run.report_frame_avg_ms
|
||||
} else if which == 11 {
|
||||
value = run.report_frame_max_ms
|
||||
} else if which == 1 {
|
||||
value = run.frame_p50_ms
|
||||
} else if which == 2 {
|
||||
value = run.frame_p95_ms
|
||||
} else if which == 3 {
|
||||
value = run.frame_cpu_p50_ms
|
||||
} else if which == 4 {
|
||||
value = run.frame_cpu_p95_ms
|
||||
} else if which == 5 {
|
||||
value = cast(float64)run.frames
|
||||
} else if which == 6 {
|
||||
value = run.idle_cpu_percent
|
||||
} else if which == 7 {
|
||||
value = run.steady_rss_mib
|
||||
}
|
||||
if value >= 0.0 {
|
||||
VecPush(values, value)
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
RunReport :: (runs: []RunMetrics) -> Text {
|
||||
names: [12]string = .["Time to first frame (ms)", "Frame interval p50 (ms)",
|
||||
"Frame interval p95 (ms)", "CPU per frame p50 (ms)", "CPU per frame p95 (ms)",
|
||||
"Frames during interaction", "Idle CPU over 30 s (%)",
|
||||
"Steady RSS, idle median (MiB)", "Peak RSS (MiB)",
|
||||
"Frame rate while interacting, 120-frame reports (fps)",
|
||||
"App frame time, 120-frame report median (ms)",
|
||||
"Longest app frame while interacting (ms)"]
|
||||
places: [12]s32 = .[1, 2, 2, 2, 2, 0, 2, 1, 1, 1, 2, 1]
|
||||
order: [12]s32 = .[0, 9, 10, 11, 1, 2, 3, 4, 5, 6, 7, 8]
|
||||
out: Vec(u8)
|
||||
BuilderPrint(*out, "Runs: %\n\n", runs.count)
|
||||
Append(*out, "| Measurement | Median | Range | Spread |\n|---|---|---|---|\n")
|
||||
for row: cast(s32)0..11 {
|
||||
which := order[row]
|
||||
values := Column(runs, which)
|
||||
SummaryRow(*out, names[which], values[:], places[which])
|
||||
}
|
||||
return BuilderFinish(out)
|
||||
}
|
||||
|
||||
RunTsv :: (runs: []RunMetrics) -> Text {
|
||||
out: Vec(u8)
|
||||
Append(*out, "run\tfirst_frame_ms\treport_fps\treport_frame_avg_ms\treport_frame_max_ms\tframes\tframe_p50_ms\tframe_p95_ms\tframe_cpu_p50_ms\tframe_cpu_p95_ms\tidle_cpu_percent\tsteady_rss_mib\tpeak_rss_mib\n")
|
||||
for index: cast(s64)0..runs.count - 1 {
|
||||
run := runs[index]
|
||||
BuilderPrint(*out, "%\t", index + 1)
|
||||
AppendFixed(*out, run.first_frame_ms, 2)
|
||||
Append(*out, "\t")
|
||||
AppendFixed(*out, run.report_fps, 2)
|
||||
Append(*out, "\t")
|
||||
AppendFixed(*out, run.report_frame_avg_ms, 3)
|
||||
Append(*out, "\t")
|
||||
AppendFixed(*out, run.report_frame_max_ms, 2)
|
||||
BuilderPrint(*out, "\t%\t", run.frames)
|
||||
AppendFixed(*out, run.frame_p50_ms, 3)
|
||||
Append(*out, "\t")
|
||||
AppendFixed(*out, run.frame_p95_ms, 3)
|
||||
Append(*out, "\t")
|
||||
AppendFixed(*out, run.frame_cpu_p50_ms, 3)
|
||||
Append(*out, "\t")
|
||||
AppendFixed(*out, run.frame_cpu_p95_ms, 3)
|
||||
Append(*out, "\t")
|
||||
AppendFixed(*out, run.idle_cpu_percent, 3)
|
||||
Append(*out, "\t")
|
||||
AppendFixed(*out, run.steady_rss_mib, 2)
|
||||
Append(*out, "\t")
|
||||
AppendFixed(*out, run.peak_rss_mib, 2)
|
||||
Append(*out, "\n")
|
||||
}
|
||||
return BuilderFinish(out)
|
||||
}
|
||||
|
||||
Save :: (out: string, name: string, text: string) -> bool {
|
||||
path := JoinPath(out, name)
|
||||
if !WriteEntireFile(path, text) {
|
||||
return false
|
||||
}
|
||||
print("%", text)
|
||||
return true
|
||||
}
|
||||
|
||||
RunCommand :: (binary: string, root: string, out: string, count: s32) -> s32 {
|
||||
if !CreateDirectories(out) {
|
||||
return Report("cannot create the output folder")
|
||||
}
|
||||
prepared := PrepareProfile(binary, root, out)
|
||||
if prepared.count == 0 {
|
||||
return Report("the app did not prepare its profile; see prepare/app.log")
|
||||
}
|
||||
runs: Vec(RunMetrics)
|
||||
for index: cast(s32)1..count {
|
||||
metrics: RunMetrics
|
||||
if !MeasureRun(binary, root, out, prepared, index, *metrics) {
|
||||
print("desktop-benchmark: run % failed; see run-%/app.log\n", index, index)
|
||||
return 1
|
||||
}
|
||||
VecPush(runs, metrics)
|
||||
print("desktop-benchmark: run % of % done\n", index, count)
|
||||
}
|
||||
report := RunReport(runs[:])
|
||||
tsv := RunTsv(runs[:])
|
||||
if !Save(out, "runs.md", report) || !Save(out, "runs.tsv", tsv) {
|
||||
return Report("cannot write the results")
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
SizeReport :: (root: string, executable: string) -> Text {
|
||||
out: Vec(u8)
|
||||
generated: GeneratedC
|
||||
generated_path := JoinPath(root, GENERATED_C_DIRECTORY)
|
||||
unused CountGeneratedC(generated_path, *generated)
|
||||
info := PathStatus(executable)
|
||||
linkage := ReadLinkage(executable)
|
||||
Append(*out, "| Measurement | Value |\n|---|---|\n")
|
||||
BuilderPrint(*out, "| Generated C files | % |\n", generated.files)
|
||||
BuilderPrint(*out, "| Generated C (MiB) | ")
|
||||
AppendFixed(*out, cast(float64)generated.bytes / 1048576.0, 2)
|
||||
BuilderPrint(*out, " |\n| Executable (MiB) | ")
|
||||
AppendFixed(*out, cast(float64)info.size / 1048576.0, 2)
|
||||
BuilderPrint(*out, " |\n| raylib markers (rlgl shader names, miniaudio, dr_mp3) | % of % |\n",
|
||||
linkage.raylib_markers, RAYLIB_MARKER_COUNT)
|
||||
BuilderPrint(*out, "| Linked libraries (%) | ", linkage.needed.count)
|
||||
for index: cast(s64)0..linkage.needed.count - 1 {
|
||||
if index > 0 {
|
||||
Append(*out, ", ")
|
||||
}
|
||||
Append(*out, linkage.needed[index])
|
||||
}
|
||||
Append(*out, " |\n")
|
||||
return BuilderFinish(out)
|
||||
}
|
||||
|
||||
SizeCommand :: (root: string, out: string, executable: string) -> s32 {
|
||||
if !CreateDirectories(out) {
|
||||
return Report("cannot create the output folder")
|
||||
}
|
||||
report := SizeReport(root, executable)
|
||||
if !Save(out, "size.md", report) {
|
||||
return Report("cannot write the results")
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
BuildCommand :: (root: string, out: string, count: s32) -> s32 {
|
||||
if !CreateDirectories(out) {
|
||||
return Report("cannot create the output folder")
|
||||
}
|
||||
clean: Vec(float64)
|
||||
incremental: Vec(float64)
|
||||
for index: cast(s32)1..count {
|
||||
run := MeasureBuild(root, out, index)
|
||||
if run.clean_seconds < 0.0 || run.incremental_seconds < 0.0 {
|
||||
print("desktop-benchmark: build % failed; see build-%-*.log\n", index, index)
|
||||
return 1
|
||||
}
|
||||
VecPush(clean, run.clean_seconds)
|
||||
VecPush(incremental, run.incremental_seconds)
|
||||
print("desktop-benchmark: build % of % done\n", index, count)
|
||||
}
|
||||
report: Vec(u8)
|
||||
BuilderPrint(*report, "Builds: %\n\n", count)
|
||||
Append(*report, "| Measurement | Median | Range | Spread |\n|---|---|---|---|\n")
|
||||
SummaryRow(*report, "Clean build (s)", clean[:], 1)
|
||||
SummaryRow(*report, "Incremental build (s)", incremental[:], 1)
|
||||
if !Save(out, "build.md", BuilderFinish(report)) {
|
||||
return Report("cannot write the results")
|
||||
}
|
||||
return SizeCommand(root, out, JoinPath(root, NATIVE_EXECUTABLE))
|
||||
}
|
||||
|
||||
Argument :: (argv: **u8, index: s32) -> string {
|
||||
return TextFromCString(argv[index])
|
||||
}
|
||||
|
||||
Count :: (text: string) -> s32 {
|
||||
value, ok := TextInteger(text)
|
||||
if !ok || value < 1 || value > 100 {
|
||||
return 0
|
||||
}
|
||||
return cast(s32)value
|
||||
}
|
||||
|
||||
#program_export
|
||||
main :: (argc: s32, argv: **u8) -> s32 {
|
||||
usage := "usage: desktop-benchmark run BINARY ROOT OUT RUNS | build ROOT OUT RUNS | size ROOT OUT [EXECUTABLE]"
|
||||
if argc < 2 {
|
||||
return Report(usage)
|
||||
}
|
||||
command := Argument(argv, 1)
|
||||
if command == "run" && argc == 6 && Count(Argument(argv, 5)) > 0 {
|
||||
return RunCommand(Argument(argv, 2), Argument(argv, 3), Argument(argv, 4),
|
||||
Count(Argument(argv, 5)))
|
||||
}
|
||||
if command == "build" && argc == 5 && Count(Argument(argv, 4)) > 0 {
|
||||
return BuildCommand(Argument(argv, 2), Argument(argv, 3), Count(Argument(argv, 4)))
|
||||
}
|
||||
if command == "size" && argc == 4 {
|
||||
return SizeCommand(Argument(argv, 2), Argument(argv, 3),
|
||||
JoinPath(Argument(argv, 2), NATIVE_EXECUTABLE))
|
||||
}
|
||||
if command == "size" && argc == 5 {
|
||||
return SizeCommand(Argument(argv, 2), Argument(argv, 3), Argument(argv, 4))
|
||||
}
|
||||
return Report(usage)
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// Build timings for the desktop benchmark. A clean build removes what the
|
||||
// Linux desktop executable alone compiles: its generated C, objects,
|
||||
// source-check stamp, the executable and the raylib library built for it.
|
||||
// The Ziran toolchain, curl, liboqs, SQLite and the image and audio codecs
|
||||
// stay built, since both hosts use them unchanged. An incremental build
|
||||
// follows a touch of src/main.zi: checking, generating C and linking again.
|
||||
#import "file_tree_linux"
|
||||
#import "process_run_linux"
|
||||
#import "vec"
|
||||
#import, file "desktop_benchmark_session.zi";
|
||||
|
||||
#scope_file
|
||||
build_libc :: #system_library "c";
|
||||
// utimensat with null times sets both to now; -100 is AT_FDCWD.
|
||||
TouchRaw :: (directory: s32, path: *u8, times: *void, flags: s32) -> s32 #foreign build_libc "utimensat";
|
||||
#scope_export
|
||||
|
||||
NATIVE_EXECUTABLE :: "build/bin/linux/breeze-linux-x86_64"
|
||||
GENERATED_C_DIRECTORY :: "build/kryon/generated"
|
||||
|
||||
CleanBuildOutputs :: (root: string) -> bool {
|
||||
outputs: [5]string = .[GENERATED_C_DIRECTORY, "build/obj/native",
|
||||
"build/bin/linux", "build/zi-check", "vendor-builds/linux/x86_64/raylib"]
|
||||
for index: 0..4 {
|
||||
path := JoinPath(root, outputs[index])
|
||||
if PathStatus(path, false).kind != .Missing &&
|
||||
!RemoveTree(path) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
TouchFile :: (path: string) -> bool {
|
||||
bytes: Vec(u8)
|
||||
for index: cast(s64)0..path.count - 1 {
|
||||
VecPush(bytes, path[index])
|
||||
}
|
||||
VecPush(bytes, 0)
|
||||
return TouchRaw(-100, *bytes[0], null, 0) == 0
|
||||
}
|
||||
|
||||
// Wall seconds for `make native KRYON_TEST_DRIVER=1` in ROOT, its output in
|
||||
// LOG, or -1 when it failed.
|
||||
TimedNativeBuild :: (root: string, log: string) -> float64 {
|
||||
arguments: [3]string = .["make", "native", "KRYON_TEST_DRIVER=1"]
|
||||
options: ProcessOptions
|
||||
options.arguments = arguments[:]
|
||||
options.directory = root
|
||||
options.output_path = log
|
||||
options.merge_error = true
|
||||
run: ProcessRun
|
||||
started := NowSeconds()
|
||||
if !RunProcess(options, *run) || run.code != 0 {
|
||||
return -1.0
|
||||
}
|
||||
return NowSeconds() - started
|
||||
}
|
||||
|
||||
BuildRun :: struct {
|
||||
clean_seconds: float64
|
||||
incremental_seconds: float64
|
||||
}
|
||||
|
||||
MeasureBuild :: (root: string, directory: string, run_index: s32) -> BuildRun {
|
||||
result: BuildRun
|
||||
result.clean_seconds = -1.0
|
||||
result.incremental_seconds = -1.0
|
||||
clean_log: Vec(u8)
|
||||
BuilderPrint(*clean_log, "%/build-%-clean.log", directory, run_index)
|
||||
if !CleanBuildOutputs(root) {
|
||||
return result
|
||||
}
|
||||
result.clean_seconds = TimedNativeBuild(root, BuilderFinish(clean_log))
|
||||
if result.clean_seconds < 0.0 {
|
||||
return result
|
||||
}
|
||||
main := JoinPath(root, "src/main.zi")
|
||||
if !TouchFile(main) {
|
||||
return result
|
||||
}
|
||||
incremental_log: Vec(u8)
|
||||
BuilderPrint(*incremental_log, "%/build-%-incremental.log", directory, run_index)
|
||||
result.incremental_seconds = TimedNativeBuild(root, BuilderFinish(incremental_log))
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
// What the desktop benchmark reads from Linux about a process and a build:
|
||||
// CPU time and memory from /proc, an executable's dynamic libraries and
|
||||
// whether raylib is linked into it, and the generated C in a folder.
|
||||
#import "file"
|
||||
#import "file_tree_linux"
|
||||
#import "text_tools"
|
||||
#import "vec"
|
||||
|
||||
#scope_file
|
||||
proc_libc :: #system_library "c";
|
||||
SystemConfiguration :: (name: s32) -> s64 #foreign proc_libc "sysconf";
|
||||
CLOCK_TICKS_NAME :: 2
|
||||
#scope_export
|
||||
|
||||
ProcPath :: (pid: s32, name: string) -> Text {
|
||||
path: Vec(u8)
|
||||
BuilderPrint(*path, "/proc/%/%", pid, name)
|
||||
return BuilderFinish(path)
|
||||
}
|
||||
|
||||
// User plus system CPU time of PID in seconds, or -1 once it is gone.
|
||||
ProcessCpuSeconds :: (pid: s32) -> float64 {
|
||||
path := ProcPath(pid, "stat")
|
||||
bytes: Vec(u8)
|
||||
if !ReadFileInto(path, *bytes) {
|
||||
return -1.0
|
||||
}
|
||||
stat := TextView(bytes[:])
|
||||
// The command name can hold spaces; the fields after it are fixed:
|
||||
// state is field 3, utime field 14 and stime field 15.
|
||||
close := TextFindLast(stat, ")")
|
||||
if close < 0 {
|
||||
return -1.0
|
||||
}
|
||||
fields := TextSplit(stat[close + 2:], " ")
|
||||
if fields.count < 13 {
|
||||
return -1.0
|
||||
}
|
||||
user, user_ok := TextInteger(fields[11])
|
||||
system, system_ok := TextInteger(fields[12])
|
||||
ticks := SystemConfiguration(CLOCK_TICKS_NAME)
|
||||
if !user_ok || !system_ok || ticks <= 0 {
|
||||
return -1.0
|
||||
}
|
||||
return cast(float64)(user + system) / cast(float64)ticks
|
||||
}
|
||||
|
||||
// A kibibyte field of /proc/PID/status, such as "VmRSS:", or -1.
|
||||
StatusKib :: (pid: s32, field: string) -> s64 {
|
||||
path := ProcPath(pid, "status")
|
||||
bytes: Vec(u8)
|
||||
if !ReadFileInto(path, *bytes) {
|
||||
return -1
|
||||
}
|
||||
status := TextView(bytes[:])
|
||||
lines := TextLines(status)
|
||||
for index: cast(s64)0..lines.count - 1 {
|
||||
line := lines[index]
|
||||
if TextHasPrefix(line, field) {
|
||||
value := TextTrim(line[field.count:])
|
||||
space := TextFind(value, " ")
|
||||
if space > 0 {
|
||||
value = value[:space]
|
||||
}
|
||||
number, number_ok := TextInteger(value)
|
||||
if number_ok {
|
||||
return number
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
ResidentKib :: (pid: s32) -> s64 {
|
||||
return StatusKib(pid, "VmRSS:")
|
||||
}
|
||||
|
||||
PeakResidentKib :: (pid: s32) -> s64 {
|
||||
return StatusKib(pid, "VmHWM:")
|
||||
}
|
||||
|
||||
// The C files under DIRECTORY, counted with their bytes, recursively.
|
||||
GeneratedC :: struct {
|
||||
files: s64
|
||||
bytes: s64
|
||||
}
|
||||
|
||||
CountGeneratedC :: (directory: string, total: *GeneratedC) -> bool {
|
||||
names: Vec(string)
|
||||
if !ListDirectory(directory, *names) {
|
||||
return false
|
||||
}
|
||||
defer { FreeDirectoryNames(*names) }
|
||||
for index: cast(s64)0..names.count - 1 {
|
||||
path := JoinPath(directory, names[index])
|
||||
info := PathStatus(path, false)
|
||||
if info.kind == .Directory {
|
||||
if !CountGeneratedC(path, total) {
|
||||
return false
|
||||
}
|
||||
} else if info.kind == .File && TextHasSuffix(names[index], ".c") {
|
||||
total.files += 1
|
||||
total.bytes += info.size
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// An ELF executable's direct dynamic libraries (DT_NEEDED) and how many
|
||||
// raylib markers it holds. The release executable has no symbol table, so
|
||||
// the markers are text only raylib carries: rlgl's default shader names and
|
||||
// its bundled miniaudio and dr_mp3 libraries.
|
||||
Linkage :: struct {
|
||||
valid: bool
|
||||
needed: Vec(string)
|
||||
raylib_markers: s32
|
||||
}
|
||||
|
||||
RAYLIB_MARKER_COUNT :: 4
|
||||
|
||||
#scope_file
|
||||
ReadU16 :: (bytes: string, at: s64) -> u64 {
|
||||
if at < 0 || at + 2 > bytes.count {
|
||||
return 0
|
||||
}
|
||||
return cast(u64)bytes[at] | (cast(u64)bytes[at + 1] << 8)
|
||||
}
|
||||
|
||||
ReadU32 :: (bytes: string, at: s64) -> u64 {
|
||||
return ReadU16(bytes, at) | (ReadU16(bytes, at + 2) << 16)
|
||||
}
|
||||
|
||||
ReadU64 :: (bytes: string, at: s64) -> u64 {
|
||||
return ReadU32(bytes, at) | (ReadU32(bytes, at + 4) << 32)
|
||||
}
|
||||
|
||||
// The NUL-terminated name at OFFSET in the string table at TABLE.
|
||||
NameAt :: (bytes: string, table: s64, size: s64, offset: s64) -> string {
|
||||
start := table + offset
|
||||
if offset < 0 || offset >= size || start >= bytes.count {
|
||||
return ""
|
||||
}
|
||||
end := start
|
||||
while end < table + size && end < bytes.count && bytes[end] != 0 {
|
||||
end += 1
|
||||
}
|
||||
return bytes[start:end]
|
||||
}
|
||||
|
||||
SectionHeader :: struct {
|
||||
kind: u64
|
||||
offset: s64
|
||||
size: s64
|
||||
link: s64
|
||||
}
|
||||
|
||||
Section :: (bytes: string, index: s64) -> SectionHeader {
|
||||
table := cast(s64)ReadU64(bytes, 40)
|
||||
entry := cast(s64)ReadU16(bytes, 58)
|
||||
at := table + index * entry
|
||||
header: SectionHeader
|
||||
header.kind = ReadU32(bytes, at + 4)
|
||||
header.offset = cast(s64)ReadU64(bytes, at + 24)
|
||||
header.size = cast(s64)ReadU64(bytes, at + 32)
|
||||
header.link = cast(s64)ReadU32(bytes, at + 40)
|
||||
return header
|
||||
}
|
||||
#scope_export
|
||||
|
||||
ReadLinkage :: (path: string) -> Linkage {
|
||||
linkage: Linkage
|
||||
markers: [RAYLIB_MARKER_COUNT]string = .["colDiffuse", "vertexTexCoord", "miniaudio", "drmp3"]
|
||||
bytes, ok := ReadEntireFile(path)
|
||||
// A 64-bit little-endian ELF file.
|
||||
if !ok || bytes.count < 64 || bytes[0] != 127 || bytes[1] != 69 ||
|
||||
bytes[4] != 2 || bytes[5] != 1 {
|
||||
return .{}
|
||||
}
|
||||
sections := cast(s64)ReadU16(bytes, 60)
|
||||
for index: cast(s64)0..sections - 1 {
|
||||
section := Section(bytes, index)
|
||||
strings := Section(bytes, section.link)
|
||||
if section.kind == 6 {
|
||||
// The dynamic section: 16-byte tag and value pairs.
|
||||
entry: s64 = 0
|
||||
while entry + 16 <= section.size {
|
||||
tag := ReadU64(bytes, section.offset + entry)
|
||||
if tag == 1 {
|
||||
offset := cast(s64)ReadU64(bytes, section.offset + entry + 8)
|
||||
VecPush(linkage.needed, NameAt(bytes, strings.offset, strings.size, offset))
|
||||
}
|
||||
entry += 16
|
||||
}
|
||||
}
|
||||
}
|
||||
for index: 0..RAYLIB_MARKER_COUNT - 1 {
|
||||
if TextContains(bytes, markers[index]) {
|
||||
linkage.raylib_markers += 1
|
||||
}
|
||||
}
|
||||
linkage.valid = true
|
||||
return linkage
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// The profile every benchmark run starts from. The app creates it once;
|
||||
// SQLite then marks first-run guides and setup as done, turns off update
|
||||
// checks and adds one list long enough to scroll. Each run copies it.
|
||||
#import "file_tree_linux"
|
||||
#import "text_tools"
|
||||
#import "vec"
|
||||
|
||||
#scope_file
|
||||
sqlite :: #system_library "sqlite3";
|
||||
SqliteOpen :: (path: *u8, database: **void) -> s32 #foreign sqlite "sqlite3_open";
|
||||
SqliteExec :: (database: *void, sql: *u8, callback: *void, argument: *void,
|
||||
error: **u8) -> s32 #foreign sqlite "sqlite3_exec";
|
||||
SqliteClose :: (database: *void) -> s32 #foreign sqlite "sqlite3_close";
|
||||
|
||||
CText :: (text: string) -> Vec(u8) {
|
||||
bytes: Vec(u8)
|
||||
for index: cast(s64)0..text.count - 1 {
|
||||
VecPush(bytes, text[index])
|
||||
}
|
||||
VecPush(bytes, 0)
|
||||
return bytes
|
||||
}
|
||||
|
||||
// Settings that let the app open straight to its screens: no language,
|
||||
// apps or audio setup, no guides, no update checks or downloads.
|
||||
SETTINGS :: #string SQL
|
||||
language=en
|
||||
language_system=0
|
||||
language_setup_done=1
|
||||
apps_setup_done=1
|
||||
enabled_apps=31
|
||||
lumi_introduced=1
|
||||
package_updates_allowed=0
|
||||
apps_last_update_check=1900000000
|
||||
tutorial_seen=1
|
||||
habits_guide_seen=1
|
||||
lumi_guides_seen=127
|
||||
launcher_guide_seen=1
|
||||
ui_scale=10
|
||||
navigation_placement=1
|
||||
navigation_collapsed=0
|
||||
SQL
|
||||
|
||||
LONG_LIST_ITEMS :: 240
|
||||
#scope_export
|
||||
|
||||
BENCHMARK_LIST_TITLE :: "Benchmark list"
|
||||
|
||||
SeedSql :: () -> Text {
|
||||
sql: Vec(u8)
|
||||
lines := TextLines(SETTINGS)
|
||||
for index: cast(s64)0..lines.count - 1 {
|
||||
line := lines[index]
|
||||
equals := TextFind(line, "=")
|
||||
if equals > 0 {
|
||||
BuilderPrint(*sql, "INSERT INTO settings(user_id,key,value,updated_at) ")
|
||||
BuilderPrint(*sql, "SELECT id,'%','%',1 FROM users WHERE kind='local' ",
|
||||
line[:equals], line[equals + 1:])
|
||||
BuilderPrint(*sql, "ON CONFLICT(user_id,key) DO UPDATE SET value=excluded.value;\n")
|
||||
}
|
||||
}
|
||||
BuilderPrint(*sql, "INSERT INTO elist_lists(id,user_id,title,sort_order,updated_at) ")
|
||||
BuilderPrint(*sql, "SELECT 'benchmark-list',id,'%',0,1 FROM users WHERE kind='local';\n",
|
||||
BENCHMARK_LIST_TITLE)
|
||||
BuilderPrint(*sql, "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM n WHERE i<%) ",
|
||||
LONG_LIST_ITEMS)
|
||||
BuilderPrint(*sql, "INSERT INTO elist_items(id,user_id,list_id,title,sort_order,updated_at) ")
|
||||
BuilderPrint(*sql, "SELECT 'benchmark-item-'||i,(SELECT id FROM users WHERE kind='local'),")
|
||||
BuilderPrint(*sql, "'benchmark-list','Benchmark item '||i,i,1 FROM n;\n")
|
||||
BuilderPrint(*sql, "PRAGMA wal_checkpoint(TRUNCATE);\n")
|
||||
return BuilderFinish(sql)
|
||||
}
|
||||
|
||||
// Applies the benchmark's settings and list to the app's database in
|
||||
// PROFILE, which the app created and has closed.
|
||||
SeedProfile :: (profile: string) -> bool {
|
||||
path := JoinPath(profile, "inbe.db")
|
||||
path_bytes := CText(path)
|
||||
database: *void
|
||||
if SqliteOpen(*path_bytes[0], *database) != 0 {
|
||||
unused SqliteClose(database)
|
||||
return false
|
||||
}
|
||||
sql := SeedSql()
|
||||
sql_bytes := CText(sql)
|
||||
ok := SqliteExec(database, *sql_bytes[0], null, null, null) == 0
|
||||
unused SqliteClose(database)
|
||||
return ok
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
// The benchmark's scripted session, driven through the Kryon test driver
|
||||
// with the app's own pointer and keys: switch between the main screens,
|
||||
// scroll a long list, open and close a modal, float a practice in its own
|
||||
// window and bring it back. It records when the interaction began and ended
|
||||
// so frame samples can be taken from just that span.
|
||||
#import "file_tree_linux"
|
||||
#import "test_driver_client"
|
||||
#import, file "desktop_benchmark_profile.zi";
|
||||
#import, file "desktop_benchmark_session.zi";
|
||||
|
||||
// How long a step may wait for what it opens, and for the screen to settle.
|
||||
STEP_TIMEOUT_MS :: 10000
|
||||
SETTLE_FRAMES :: 5
|
||||
SETTLE_TIMEOUT_MS :: 3000
|
||||
SCREEN_CYCLES :: 2
|
||||
SCROLL_STEPS :: 40
|
||||
SCROLL_LINES :: 3.0
|
||||
FLOATING_MS :: 3000
|
||||
|
||||
// When the interaction ran, and how long the app's log was then, so the
|
||||
// app's 120-frame profile reports can be taken from that span too.
|
||||
Interaction :: struct {
|
||||
started: float64
|
||||
ended: float64
|
||||
log_started: s64
|
||||
log_ended: s64
|
||||
}
|
||||
|
||||
LogSize :: (log: string) -> s64 {
|
||||
return PathStatus(log).size
|
||||
}
|
||||
|
||||
// Waits for the screen to stop changing; a screen that keeps animating, such
|
||||
// as a running practice, simply ends the wait at its timeout.
|
||||
Settle :: (driver: *TestDriverClient) {
|
||||
unused DriverWaitIdle(driver, SETTLE_FRAMES, SETTLE_TIMEOUT_MS)
|
||||
}
|
||||
|
||||
Open :: (driver: *TestDriverClient, label: string) -> bool {
|
||||
if !DriverWait(driver, .{label = label}, STEP_TIMEOUT_MS) {
|
||||
return false
|
||||
}
|
||||
if !DriverPress(driver, .{label = label}) {
|
||||
return false
|
||||
}
|
||||
Settle(driver)
|
||||
return true
|
||||
}
|
||||
|
||||
// The navigation rail's screens, then the Lists and Diary apps from Apps.
|
||||
SwitchScreens :: (driver: *TestDriverClient) -> bool {
|
||||
rail: [4]string = .["Habits", "Lumi", "Practice", "Apps"]
|
||||
for cycle: 1..SCREEN_CYCLES {
|
||||
for index: 0..3 {
|
||||
if !Open(driver, rail[index]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if !Open(driver, "Lists") || !Open(driver, "Apps") ||
|
||||
!Open(driver, "Diary") || !Open(driver, "Apps") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// The seeded list: down by wheel to well past its first screen, then back.
|
||||
ScrollLongList :: (driver: *TestDriverClient) -> bool {
|
||||
if !Open(driver, "Lists") {
|
||||
return false
|
||||
}
|
||||
if !DriverWait(driver, .{label = "Benchmark item 1"}, STEP_TIMEOUT_MS) {
|
||||
return false
|
||||
}
|
||||
list := driver.nodes[0]
|
||||
x := list.x + list.width / 2.0
|
||||
y := list.y + list.height * 4.0
|
||||
for step: 1..SCROLL_STEPS {
|
||||
if !DriverWheel(driver, x, y, 0.0 - SCROLL_LINES) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if DriverFind(driver, .{label = "Benchmark item 1"}) != 0 {
|
||||
return DriverFail(driver, "the long list did not scroll")
|
||||
}
|
||||
for step: 1..SCROLL_STEPS {
|
||||
if !DriverWheel(driver, x, y, SCROLL_LINES) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if !DriverReleasePointer(driver) {
|
||||
return false
|
||||
}
|
||||
return DriverWait(driver, .{label = "Benchmark item 1"}, STEP_TIMEOUT_MS)
|
||||
}
|
||||
|
||||
// An app's Properties dialog from its options menu, closed with Escape.
|
||||
OpenAndCloseModal :: (driver: *TestDriverClient) -> bool {
|
||||
if !Open(driver, "Apps") || !Open(driver, "App options") ||
|
||||
!Open(driver, "Properties") {
|
||||
return false
|
||||
}
|
||||
if !DriverWait(driver, .{label = "Save"}, STEP_TIMEOUT_MS) {
|
||||
return false
|
||||
}
|
||||
if !DriverKey(driver, DRIVER_KEY_ESCAPE, false, false) {
|
||||
return false
|
||||
}
|
||||
if !DriverWaitGone(driver, .{label = "Save"}, STEP_TIMEOUT_MS) {
|
||||
return false
|
||||
}
|
||||
Settle(driver)
|
||||
return true
|
||||
}
|
||||
|
||||
// Starts a practice, floats it in its own window for a few seconds, brings
|
||||
// it back to the app and exits it.
|
||||
FloatPractice :: (driver: *TestDriverClient) -> bool {
|
||||
if !Open(driver, "Practice") || !Open(driver, "Start Practice") {
|
||||
return false
|
||||
}
|
||||
if !Open(driver, "Minimize") {
|
||||
return false
|
||||
}
|
||||
// The main window returns to the practice's start page while the
|
||||
// practice runs in the floating window.
|
||||
if !DriverWait(driver, .{label = "Start Practice"}, STEP_TIMEOUT_MS) {
|
||||
return false
|
||||
}
|
||||
PauseMilliseconds(FLOATING_MS)
|
||||
if !Open(driver, "Start Practice") {
|
||||
return false
|
||||
}
|
||||
if !DriverWait(driver, .{label = "Minimize"}, STEP_TIMEOUT_MS) {
|
||||
return false
|
||||
}
|
||||
if !Open(driver, "Close") || !Open(driver, "Exit") {
|
||||
return false
|
||||
}
|
||||
return DriverWait(driver, .{label = "Start Practice"}, STEP_TIMEOUT_MS)
|
||||
}
|
||||
|
||||
Step :: (name: string, done: bool) -> bool {
|
||||
if done {
|
||||
print("desktop-benchmark: %\n", name)
|
||||
} else {
|
||||
print("desktop-benchmark: % FAILED\n", name)
|
||||
}
|
||||
return done
|
||||
}
|
||||
|
||||
RunInteraction :: (driver: *TestDriverClient, log: string, interaction: *Interaction) -> bool {
|
||||
interaction.log_started = LogSize(log)
|
||||
interaction.started = NowSeconds()
|
||||
if !Step("switched screens", SwitchScreens(driver)) {
|
||||
return false
|
||||
}
|
||||
if !Step("scrolled the long list", ScrollLongList(driver)) {
|
||||
return false
|
||||
}
|
||||
if !Step("opened and closed a modal", OpenAndCloseModal(driver)) {
|
||||
return false
|
||||
}
|
||||
if !Step("floated a practice window", FloatPractice(driver)) {
|
||||
return false
|
||||
}
|
||||
interaction.ended = NowSeconds()
|
||||
interaction.log_ended = LogSize(log)
|
||||
// Idle on a still screen.
|
||||
return Open(driver, "Habits")
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
// One benchmark run's processes: a private Xvfb display at a fixed size and
|
||||
// the app on it, with a scrubbed environment, a disposable profile and the
|
||||
// Kryon test driver. Also reads the app's log: its first-frame probe and the
|
||||
// per-frame samples APP_PROFILE writes.
|
||||
#import "file"
|
||||
#import "float_text"
|
||||
#import "file_tree_linux"
|
||||
#import "process_run_linux"
|
||||
#import "text_tools"
|
||||
#import "timer_linux"
|
||||
#import "vec"
|
||||
|
||||
DISPLAY_SCREEN :: "1280x1000x24"
|
||||
FIRST_FRAME_PROBE :: "APP PROBE: drawing ended"
|
||||
SAMPLE_PREFIX :: "PROFILE: sample wall_us="
|
||||
|
||||
NowSeconds :: () -> float64 {
|
||||
return cast(float64)MonotonicNanoseconds() / 1000000000.0
|
||||
}
|
||||
|
||||
PauseMilliseconds :: (milliseconds: s64) {
|
||||
unused SleepMilliseconds(milliseconds)
|
||||
}
|
||||
|
||||
Display :: struct {
|
||||
run: ProcessRun
|
||||
name: string
|
||||
}
|
||||
|
||||
// Starts Xvfb, which picks a free display and writes its number to
|
||||
// NUMBER_PATH. False when it did not come up within ten seconds.
|
||||
StartDisplay :: (directory: string, display: *Display) -> bool {
|
||||
number_path := JoinPath(directory, "display-number")
|
||||
log_path := JoinPath(directory, "display.log")
|
||||
arguments: [9]string = .["Xvfb", "-noreset", "-displayfd", "1", "-screen", "0",
|
||||
DISPLAY_SCREEN, "-nolisten", "tcp"]
|
||||
options: ProcessOptions
|
||||
options.arguments = arguments[:]
|
||||
options.output_path = number_path
|
||||
options.error_path = log_path
|
||||
options.new_session = true
|
||||
if !StartProcess(options, *display.run) {
|
||||
return false
|
||||
}
|
||||
deadline := NowSeconds() + 10.0
|
||||
bytes: Vec(u8)
|
||||
while NowSeconds() < deadline {
|
||||
unused VecResize(bytes, 0)
|
||||
ok := ReadFileInto(number_path, *bytes)
|
||||
text := TextView(bytes[:])
|
||||
if ok && TextHasSuffix(text, "\n") {
|
||||
name: Vec(u8)
|
||||
BuilderPrint(*name, ":%", TextTrim(text))
|
||||
display.name = BuilderFinish(name)
|
||||
return true
|
||||
}
|
||||
if PollProcess(*display.run) {
|
||||
return false
|
||||
}
|
||||
PauseMilliseconds(20)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
StopProcess :: (run: *ProcessRun) {
|
||||
if !run.started || run.finished {
|
||||
return
|
||||
}
|
||||
unused SignalProcess(run, 15)
|
||||
deadline := NowSeconds() + 5.0
|
||||
while NowSeconds() < deadline {
|
||||
if PollProcess(run) {
|
||||
return
|
||||
}
|
||||
PauseMilliseconds(20)
|
||||
}
|
||||
unused SignalProcess(run, 9)
|
||||
unused WaitProcess(run)
|
||||
}
|
||||
|
||||
App :: struct {
|
||||
run: ProcessRun
|
||||
log: string
|
||||
started_at: float64
|
||||
}
|
||||
|
||||
// Starts BINARY from ROOT on DISPLAY with PROFILE as its data and DRIVER as
|
||||
// its test-driver environment entry. The desktop's display, session bus,
|
||||
// audio servers and recovery services are removed from its environment, and
|
||||
// ALSA reads an empty configuration, so the app reaches nothing but its own
|
||||
// display and every host alike finds no audio device.
|
||||
StartApp :: (binary: string, root: string, directory: string, profile: string,
|
||||
display: string, driver: string, app: *App) -> bool {
|
||||
app.log = JoinPath(directory, "app.log")
|
||||
display_entry: Vec(u8)
|
||||
BuilderPrint(*display_entry, "DISPLAY=%", display)
|
||||
profile_entry: Vec(u8)
|
||||
BuilderPrint(*profile_entry, "APP_DATA_ROOT=%", profile)
|
||||
environment: [17]string = .[BuilderFinish(display_entry), driver,
|
||||
BuilderFinish(profile_entry), "APP_PROFILE=1", "APP_NO_TRAY=1",
|
||||
"YUE_DESKTOP_RECOVERY=0", "SDL_VIDEODRIVER=x11", "ALSA_CONFIG_PATH=/dev/null",
|
||||
"LIBGL_ALWAYS_SOFTWARE=1", "WAYLAND_DISPLAY", "XAUTHORITY",
|
||||
"DBUS_SESSION_BUS_ADDRESS", "XDG_RUNTIME_DIR", "PULSE_SERVER",
|
||||
"PIPEWIRE_REMOTE", "SESSION_MANAGER", "GDK_DISPLAY"]
|
||||
arguments: [1]string = .[binary]
|
||||
options: ProcessOptions
|
||||
options.arguments = arguments[:]
|
||||
options.directory = root
|
||||
options.environment = environment[:]
|
||||
options.output_path = app.log
|
||||
options.merge_error = true
|
||||
options.new_session = true
|
||||
app.started_at = NowSeconds()
|
||||
return StartProcess(options, *app.run)
|
||||
}
|
||||
|
||||
// The app's log so far, into BYTES.
|
||||
ReadAppLog :: (app: *App, bytes: *Vec(u8)) {
|
||||
unused VecResize(<<bytes, 0)
|
||||
unused ReadFileInto(app.log, bytes)
|
||||
}
|
||||
|
||||
// Seconds from starting the app to its first finished frame, or -1 when
|
||||
// it exited or took longer than TIMEOUT seconds.
|
||||
WaitFirstFrame :: (app: *App, timeout: float64) -> float64 {
|
||||
deadline := app.started_at + timeout
|
||||
log: Vec(u8)
|
||||
while NowSeconds() < deadline {
|
||||
ReadAppLog(app, *log)
|
||||
if TextContains(TextView(log[:]), FIRST_FRAME_PROBE) {
|
||||
return NowSeconds() - app.started_at
|
||||
}
|
||||
if PollProcess(*app.run) {
|
||||
return -1.0
|
||||
}
|
||||
PauseMilliseconds(2)
|
||||
}
|
||||
return -1.0
|
||||
}
|
||||
|
||||
// When a frame began and the app's CPU time then, in seconds.
|
||||
FrameSample :: struct {
|
||||
wall: float64
|
||||
cpu: float64
|
||||
}
|
||||
|
||||
FieldNumber :: (line: string, name: string) -> s64 {
|
||||
at := TextFind(line, name)
|
||||
if at < 0 {
|
||||
return -1
|
||||
}
|
||||
value := line[at + name.count:]
|
||||
end: s64 = 0
|
||||
while end < value.count && value[end] >= 48 && value[end] <= 57 {
|
||||
end += 1
|
||||
}
|
||||
number, ok := TextInteger(value[:end])
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return number
|
||||
}
|
||||
|
||||
ReadFrameSamples :: (app: *App) -> Vec(FrameSample) {
|
||||
samples: Vec(FrameSample)
|
||||
log: Vec(u8)
|
||||
ReadAppLog(app, *log)
|
||||
lines := TextLines(TextView(log[:]))
|
||||
for index: cast(s64)0..lines.count - 1 {
|
||||
line := lines[index]
|
||||
if TextContains(line, SAMPLE_PREFIX) {
|
||||
wall := FieldNumber(line, "wall_us=")
|
||||
cpu := FieldNumber(line, "cpu_us=")
|
||||
if wall >= 0 && cpu >= 0 {
|
||||
VecPush(samples, FrameSample.{cast(float64)wall / 1000000.0,
|
||||
cast(float64)cpu / 1000000.0})
|
||||
}
|
||||
}
|
||||
}
|
||||
return samples
|
||||
}
|
||||
|
||||
// One APP_PROFILE report: the app's own frame time over 120 frames, its
|
||||
// longest frame, and the frame rate of those frames. Every build writes
|
||||
// these, including ones from before the per-frame samples.
|
||||
ProfileReport :: struct {
|
||||
frame_avg_ms: float64
|
||||
frame_max_ms: float64
|
||||
fps: float64
|
||||
}
|
||||
|
||||
REPORT_PREFIX :: "PROFILE: frame avg="
|
||||
|
||||
FieldDecimal :: (line: string, name: string, from: s64) -> float64 {
|
||||
at := TextFind(line, name, from)
|
||||
if at < 0 {
|
||||
return -1.0
|
||||
}
|
||||
value := line[at + name.count:]
|
||||
end: s64 = 0
|
||||
while end < value.count && value[end] != 32 {
|
||||
end += 1
|
||||
}
|
||||
number, ok := ParseFloat64(value[:end])
|
||||
if !ok {
|
||||
return -1.0
|
||||
}
|
||||
return number
|
||||
}
|
||||
|
||||
// The reports whose lines begin at a byte offset in [FROM, TO).
|
||||
ReadProfileReports :: (app: *App, from: s64, to: s64) -> Vec(ProfileReport) {
|
||||
reports: Vec(ProfileReport)
|
||||
log: Vec(u8)
|
||||
ReadAppLog(app, *log)
|
||||
text := TextView(log[:])
|
||||
start: s64 = 0
|
||||
while start < text.count && start < to {
|
||||
end := TextFind(text, "\n", start)
|
||||
if end < 0 {
|
||||
end = text.count
|
||||
}
|
||||
line := text[start:end]
|
||||
if start >= from && TextContains(line, REPORT_PREFIX) {
|
||||
report: ProfileReport
|
||||
report.frame_avg_ms = FieldDecimal(line, "frame avg=", 0)
|
||||
report.frame_max_ms = FieldDecimal(line, " max=", 0)
|
||||
report.fps = FieldDecimal(line, "fps=", 0)
|
||||
if report.frame_avg_ms >= 0.0 && report.frame_max_ms >= 0.0 && report.fps > 0.0 {
|
||||
VecPush(reports, report)
|
||||
}
|
||||
}
|
||||
start = end + 1
|
||||
}
|
||||
return reports
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// Medians, ranges and percentiles for the desktop benchmark. Every summary
|
||||
// is over a copy, so the caller's values keep their order.
|
||||
#import "sort"
|
||||
#import "vec"
|
||||
|
||||
// One measurement over several runs.
|
||||
Summary :: struct {
|
||||
count: s64
|
||||
median: float64
|
||||
minimum: float64
|
||||
maximum: float64
|
||||
}
|
||||
|
||||
SortedCopy :: (values: []float64) -> Vec(float64) {
|
||||
sorted: Vec(float64)
|
||||
for index: cast(s64)0..values.count - 1 {
|
||||
VecPush(sorted, values[index])
|
||||
}
|
||||
Sort(sorted[:])
|
||||
return sorted
|
||||
}
|
||||
|
||||
// The median of VALUES; the mean of the middle two for an even count.
|
||||
Median :: (values: []float64) -> float64 {
|
||||
if values.count == 0 {
|
||||
return 0.0
|
||||
}
|
||||
sorted := SortedCopy(values)
|
||||
middle := sorted.count / 2
|
||||
if sorted.count % 2 == 1 {
|
||||
return sorted[middle]
|
||||
}
|
||||
return (sorted[middle - 1] + sorted[middle]) / 2.0
|
||||
}
|
||||
|
||||
// The nearest-rank percentile: FRACTION 0.95 is the smallest value that is
|
||||
// at least as large as 95% of VALUES.
|
||||
Percentile :: (values: []float64, fraction: float64) -> float64 {
|
||||
if values.count == 0 {
|
||||
return 0.0
|
||||
}
|
||||
sorted := SortedCopy(values)
|
||||
rank := cast(s64)(fraction * cast(float64)sorted.count)
|
||||
if cast(float64)rank < fraction * cast(float64)sorted.count {
|
||||
rank += 1
|
||||
}
|
||||
if rank < 1 {
|
||||
rank = 1
|
||||
}
|
||||
if rank > sorted.count {
|
||||
rank = sorted.count
|
||||
}
|
||||
return sorted[rank - 1]
|
||||
}
|
||||
|
||||
Summarize :: (values: []float64) -> Summary {
|
||||
summary: Summary
|
||||
summary.count = values.count
|
||||
if values.count == 0 {
|
||||
return summary
|
||||
}
|
||||
sorted := SortedCopy(values)
|
||||
summary.minimum = sorted[0]
|
||||
summary.maximum = sorted[sorted.count - 1]
|
||||
summary.median = Median(values)
|
||||
return summary
|
||||
}
|
||||
|
||||
// Half the range as a percentage of the median: 4.0 means the runs fell
|
||||
// within about ±4% of it.
|
||||
SpreadPercent :: (summary: Summary) -> float64 {
|
||||
if summary.count == 0 || summary.median == 0.0 {
|
||||
return 0.0
|
||||
}
|
||||
half := (summary.maximum - summary.minimum) / 2.0
|
||||
if summary.median < 0.0 {
|
||||
return 100.0 * half / (0.0 - summary.median)
|
||||
}
|
||||
return 100.0 * half / summary.median
|
||||
}
|
||||
Reference in new issue
Block a user