| # SQLite — steady-state query execution SimPoint traces |
|
|
| DynamoRIO (drmemtrace) SimPoint traces of **SQLite 3.53.4** executing queries |
| against an already-populated on-disk database. Database creation, schema |
| initialization and dataset loading are deliberately **not** in these traces. |
|
|
| | | | |
| |---|---| |
| | Traces | 4 SimPoints | |
| | Instructions per trace | 120,000,000 fetched (60M warmup chunk + 60M SimPoint chunk) | |
| | Format | drmemtrace offline trace (encoded), one `.zip` per SimPoint | |
| | Threads | 1 | |
| | System calls in traced region | 0 | |
| | Total size | 870 MB | |
| | Recommended Scarab `--inst_limit` | 120000000 | |
|
|
| ``` |
| sqlite/ |
| ├── README.md this file |
| ├── README_RELEASE.md release notes, layout, PC->source instructions |
| ├── RELEASE_MANIFEST.json per-SimPoint segment / cluster / weight / sha256 |
| ├── SHA256SUMS checksums for every file |
| ├── trace_clustering_info.json segment size, warmup chunks, flow, excluded phases |
| ├── fingerprint/ BBV fingerprint (bbfp, inscount, pcmap, pieces/) |
| ├── simpoints/ SimPoint 3.2 output + selection/substitution record |
| ├── traces_simp/ |
| │ ├── trace/{12,22,27,54}.zip the traces |
| │ └── bin/ modules.log + the module images it references |
| ├── validation/ counts, zip/invariant checks, steady-state evidence |
| └── workload/ workload description, driver sources, scripts |
| ``` |
|
|
| ## The application |
|
|
| SQLite is an embedded relational database — the query engine runs in-process, |
| so a trace of the client is a trace of the database. Nothing is CPU-idle |
| waiting on a server. |
|
|
| - Source: official amalgamation `sqlite-amalgamation-3530400.zip` |
| from <https://www.sqlite.org/2026/> |
| - Version 3.53.4, source id |
| `2026-07-24 19:02:57 bf7c7f30031888f4e796e429ab3978879485813aaca6f641c7b33e4e09459bcc` |
| - `sqlite3.c` sha256 `b1dd5d74ec7f29055a6684fa06fb3c2f6821c87dd38f9a458dfd2e8a1db28189` |
| - Built with |
| `gcc -O2 -g -no-pie -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_MAX_MMAP_SIZE=4294967296` |
|
|
| `-no-pie` is deliberate: it makes runtime PCs in the trace equal link-time |
| addresses, so they map straight back to source. |
|
|
| ## The dataset |
|
|
| Synthetic, generated by the untraced setup binary (`workload/src/sqlite_setup.c`) |
| with a fixed LCG seed, so it is reproducible bit-for-bit: |
|
|
| ```sql |
| CREATE TABLE records( |
| id INTEGER PRIMARY KEY, -- 1 .. 3,000,000, dense |
| k INTEGER NOT NULL, -- scattered over [0, 6,000,000), ~1.27 rows/key |
| v0 INTEGER NOT NULL, |
| v1 INTEGER NOT NULL, |
| payload TEXT NOT NULL); -- 64 bytes |
| CREATE INDEX idx_k ON records(k); |
| ANALYZE; |
| ``` |
|
|
| 3,000,000 rows, 4 KiB pages, **302 MB** database file. `k` is scattered so the |
| secondary index imposes a different B-tree order than the rowid table, making |
| index lookups a genuine second descent plus a rowid seek rather than a |
| sequential walk. |
|
|
| Connection settings for the traced process: `SQLITE_OPEN_READONLY`, |
| `PRAGMA query_only=ON`, `PRAGMA locking_mode=EXCLUSIVE`, |
| `PRAGMA mmap_size=2GiB`, `PRAGMA cache_size=-524288`. |
| `locking_mode=EXCLUSIVE` takes the shared file lock once instead of `fcntl()`-ing |
| on every implicit read transaction — without it two syscalls per query dominate |
| the profile and bury the B-tree work. `mmap_size` covers the whole database, so |
| page reads are served from the mapping and there is no long page-cache warm-up |
| phase to pollute clustering. |
|
|
| ## Query mix |
|
|
| Three rounds of four read-only query phases, all issued from statements |
| prepared once and `sqlite3_reset()` per iteration: |
|
|
| | phase | query | per round | exercises | |
| |---|---|---|---| |
| | 1 | `SELECT v0,v1,payload FROM records WHERE id = ?` | 60,000 | rowid B-tree descent, record lookup | |
| | 2 | `SELECT id,v0 FROM records INDEXED BY idx_k WHERE k = ?` | 50,000 | index B-tree descent + rowid table seek, key comparison | |
| | 3 | `SELECT id,v0,v1 FROM records WHERE id BETWEEN ? AND ?` (64 rows) | 4,900 | cursor movement across leaf pages, cell parsing | |
| | 4 | `SELECT id,k FROM records INDEXED BY idx_k WHERE k BETWEEN ? AND ?` | 5,000 | covering-index cursor movement, record compare | |
|
|
| Whole traced run: **3,383,340,000 fetched instructions**. |
|
|
| ## How the excluded phases were excluded |
|
|
| The workload is split into **two separate binaries**, so no excluded-phase code |
| path is even reachable from the traced process: |
|
|
| | binary | phase | traced | |
| |---|---|---| |
| | `sqlite_setup` | database file allocation, `CREATE TABLE`, `CREATE INDEX`, schema initialization, bulk `INSERT` of 3M rows, `ANALYZE` | no | |
| | `sqlite_query` | steady-state query execution against the existing database | **yes** | |
|
|
| `sqlite_query` contains no DDL and no DML. Its only non-query work is |
| `sqlite3_open_v2()` plus four `sqlite3_prepare_v2()` calls: **480,604 |
| instructions**, measured on a query-free run. That is 0.014% of the traced run |
| and under 1% of a single fingerprint segment. The earliest released SimPoint |
| region starts 660,000,000 instructions in, so none of it appears in any trace. |
|
|
| ## Collection method |
|
|
| Flow: `cluster_then_trace` — fingerprint natively, cluster, then capture one |
| DynamoRIO trace per selected SimPoint. This matches |
| `scarab-infra/common/scripts/run_simpoint_trace.py` and avoids materializing a |
| ~16 GB whole-run trace. |
|
|
| 1. **Fingerprint.** `drrun -disable_traces -max_bb_instrs 256 -opt_cleancall 2 |
| -c libfpg.so -no_use_bb_pc -segment_size 60000000` over the whole |
| `sqlite_query` run → 57 segments of 60,000,000 instructions. |
| 2. **Cluster.** SimPoint 3.2, `-maxK 5 -dim 100 -fixedLength off -numInitSeeds 10 |
| -coveragePct .99`. BIC chose **k = 4**, and the clusters recovered exactly the |
| four query phases and their three repetitions: |
|
|
| | cluster | segments | query phase | representative | |
| |---|---|---|---| |
| | 2 | 0-4, 19-22, 38-41 | rowid point lookups | 22 | |
| | 3 | 5-8, 23-27, 42-46 | index lookups | 27 | |
| | 1 | 9-13, 28-32, 47-51 | rowid range scans | 12 | |
| | 0 | 14-18, 33-37, 52-56 | index range scans | 54 | |
|
|
| SimPoint's own representative for cluster 0 was segment 56, the partial |
| trailing segment (16,512,018 instructions). It was replaced by segment 54, |
| the next-closest full segment to the centroid (0.0371956 vs 0.0366442); |
| recorded in `simpoints/substitutions.txt`. Every representative's preceding |
| segment is in the same cluster, so each archive's warmup chunk is in the same |
| query phase as its measured chunk. |
| 3. **Trace.** Per SimPoint, |
| `drrun -t drcachesim -offline -count_fetched_instrs -trace_after_instrs <seg-1>*60M |
| -trace_for_instrs 120000000`. |
| 4. **Convert.** `portabilize_trace.py`, then |
| `drraw2trace -chunk_instr_count 60000000`. |
| 5. **Minimize.** Keep `chunk.0000` (warmup) + `chunk.0001` (SimPoint region) → |
| 120,000,000 instructions per released archive. |
| |
| Tooling: DynamoRIO 10.0.0, SimPoint 3.2, fingerprint client `libfpg.so`, all |
| inside container image `allbench_traces:00022fc`. Capture host |
| `clnode130.clemson.cloudlab.us`. |
| |
| ## The traces |
| |
| | file | segment | cluster | weight | query phase | size | |
| |---|---|---|---|---|---| |
| | `traces_simp/trace/22.zip` | 22 | 2 | 0.231008 | rowid point lookups | 387 MB | |
| | `traces_simp/trace/27.zip` | 27 | 3 | 0.248778 | index lookups | 367 MB | |
| | `traces_simp/trace/12.zip` | 12 | 1 | 0.266548 | rowid range scans | 75 MB | |
| | `traces_simp/trace/54.zip` | 54 | 0 | 0.253666 | index range scans | 69 MB | |
| |
| Weights sum to 1.0. All four archives contain exactly 120,000,000 fetched |
| instructions, pass `unzip -t`, pass `drcachesim -simulator_type |
| invariant_checker`, and have distinct sha256 values. |
| |
| ## Verification that this is the steady state |
| |
| Two independent methods, both under `validation/steady_state/`. |
| |
| **Exhaustive, instruction-exact.** `function_profile-segment-<N>.txt` attributes |
| 100% of each archive's 120,000,000 instructions to functions, computed from the |
| BBV fingerprint of the identical deterministic run. Query execution accounts for |
| 85.2-96.3% of every window: |
| |
| | segment | query phase | query-execution share | dominant functions | |
| |---|---|---|---| |
| | 22 | rowid point lookups | 85.24% | `sqlite3VdbeExec` 18.4%, `sqlite3BtreeTableMoveto` 12.1%, `sqlite3GetVarint` 10.7%, `getPageMMap` 5.3% | |
| | 27 | index lookups | 86.36% | `sqlite3BtreeIndexMoveto` 13.6%, `sqlite3VdbeExec` 12.9%, `vdbeRecordCompareInt` 7.9%, `getPageMMap` 6.2% | |
| | 12 | rowid range scans | 96.31% | `sqlite3VdbeExec` 59.7%, `btreeParseCellPtr` 5.2%, `sqlite3VdbeSerialGet` 3.8%, `sqlite3BtreeNext` 1.7% | |
| | 54 | index range scans | 96.34% | `sqlite3VdbeExec` 49.2%, `sqlite3VdbeRecordCompareWithSkip` 8.9%, `sqlite3VdbeMemFromBtreeZeroOffset` 4.8% | |
| |
| The remainder is SQLite support code (memory management, `sqlite3VdbeMemRelease`, |
| value conversion) plus a fraction of a percent of libc. |
| |
| **Independent, from the trace files themselves.** |
| `trace_hot_functions-segment-<N>.txt` runs `drcachesim -simulator_type histogram` |
| on each `.zip` and maps the hot instruction-fetch lines through `nm` and |
| `modules.log`. Same functions, same ordering. |
| |
| **Negative check.** `excluded_phase_check.tsv` reports the instruction count of |
| every database-creation, schema-initialization, dataset-population and |
| SQL-compilation function in each archive — `sqlite3BtreeInsert`, |
| `balance_nonroot`, `allocateBtreePage`, `sqlite3PagerWrite`, `insertCell`, |
| `sqlite3CreateIndex`, `sqlite3StartTable`, `sqlite3InitOne`, `sqlite3AnalysisLoad`, |
| `sqlite3RunParser`, `sqlite3Prepare`, `sqlite3WhereBegin`, and others: |
| |
| > **0 instructions, in all four archives, in all four categories.** |
| |
| Note on classification: `sqlite3BtreeBeginTrans` / `sqlite3BtreeCommitPhaseTwo` |
| do appear. On a read-only, `query_only=ON` connection these are the per-query |
| *read*-transaction begin and teardown — query execution state management, not |
| writes — so they are counted as query execution. No write path is reachable. |
| |
| `validation/basic_counts/` additionally shows 1 thread and **0 system-call |
| markers** per archive: the traced regions are pure userspace B-tree work. |
| |
| ## Mapping runtime PCs back to source |
| |
| `traces_simp/bin/modules.log` is the DynamoRIO module table recorded at capture |
| time (load base, extent, path for every module). The module images it references |
| are shipped alongside it, so PCs resolve all the way to source. The main binary |
| is at `0x400000` (`-no-pie`) and carries `-g` debug info, so a trace PC in that |
| range is already a link-time address: |
| |
| ```bash |
| addr2line -f -C -e traces_simp/bin/sqlite_query 0x497d40 |
| ``` |
| |
| For other modules subtract the module `start` from `modules.log`, or pass |
| `-alt_module_dir traces_simp/bin` to drcachesim tools. |
| `workload/bin/sqlite_query.nm` holds the symbol table. |
| |
| ## Reproducing |
| |
| `workload/src/` contains everything: `sqlite_setup.c`, `sqlite_query.c`, |
| `build.sh`, `trace_simpoints.sh`, `validate.sh`, `verify_steady_state.py`, |
| `fp_funcs.py`, `trace_pc_funcs.py`. |
| |
| ```bash |
| bash build.sh # build both binaries |
| ./sqlite_setup /path/records.db 3000000 # untraced: create + load |
| ./sqlite_query /path/records.db 3 60000 50000 4900 5000 3000000 # the traced phase |
| ``` |
| |
| ## Layout note |
| |
| `fingerprint/` holds `bbfp`, `bbfp.inscount`, `pcmap`, `pieces/segment.N` and |
| `segment_size`. It does not have the `fingerprint/0..N/PARAMS.in` directories or |
| `footprint_pieces/` seen in the `leveldb` / `duckdb` / `rocksdb` folders of this |
| dataset — those are artifacts of the `trace_then_cluster` flow, which |
| fingerprints a materialized whole-run trace with Scarab. Everything else matches |
| that layout exactly. The flow used here is recorded in |
| `trace_clustering_info.json`. |
| |