Reports and Benchmarks
Reports
Use ReportBuilder to collect results and findings:
from storq import ReportBuilder, ReportFinding
report = (
ReportBuilder(title="Database inspection")
.add({"header_valid": True, "page_count": 4}, source_module="format_inspection")
.add_finding(ReportFinding(
finding_id="example",
title="Inspection completed",
severity="info",
description="The sample header passed inspection.",
))
.build()
)
report.export("report.json", format="json")
Report models
ReportMetadata: ID, type, title, generated time, Storq version, engine and format labels.Report: metadata, description, sections, findings, statistics, evidence, source modules, limitations, and export metadata. Methods:section(section_id),add_finding(finding),to_dict(),export(path, format="json"),save(...), andvisualize(...).ReportSection: one named section with content, tables, charts, and optional timeline.ReportFinding: finding title, severity, category, status, description, and evidence references.ReportEvidence: a source/type/reference/details record.ReportStatistics: arbitrary named values.ReportTable,ReportChart,ReportTimeline: tabular, chart, and event timeline payloads.ReportExportResult: output path, format, bytes written.
Building and normalizing reports
ReportBuilder(title="Storq Report", report_type="comprehensive", description="", config=None):
add(result, source_module="module_result")normalizes arbitrary result values into sections and may infer a finding.- Convenience methods
add_inspection,add_page_analysis,add_wal_analysis,add_fault,add_crash,add_recovery,add_forensics,add_workload, andadd_workflowlabel the source module. add_finding,add_evidence,description,metadata,include_sections,exclude_sections,filter_findings, andlimit_recordscustomize output.build()returns theReport; an empty builder records a limitation.
ReportDataNormalizer.normalize() converts results to report payloads;
finding_from_result() may derive a finding from a result object. Keep derived
findings separate from observed source data when interpreting reports.
ReportingEngine.create_report(source=None, template="comprehensive", title=None) wraps an optional source in a report. Unknown template names fall
back to the comprehensive report type. create_report_from_workflow is an
alias.
ReportTemplateRegistry.register/unregister/get/names manages template
definitions. The exporter currently chooses formats directly; templates are
not equivalent to native subsystem implementations.
Export, history, compare, visualize
report.export(path, format)andreport.save(...)supportjson,csv,html/htm, andpdf.ExportManager.export(report, path, format)selects the exporter. PDF export needs the optionalreportsdependency (reportlab).report_history(directory=None)returns aReportHistory;add(report),get(id), andlist(...)persist/retrieve report history.compare_reports(previous, current)returns aReportComparisondescribing report differences.report.visualize(chart_type, output=None, interactive=False)delegates toVisualizationEngine.render. Visualization may need optional packages: installstorq[visualization]with pip for matplotlib/plotly.OptionalDependencyErrorsignals a missing visualization dependency. Install it withpython -m pip install "storq[visualization]".page_distribution(report)is a visualization helper for page-distribution data; it is not a storage analyzer.
ReportingConfig controls theme, evidence/raw-data inclusion, chart
dimensions/backend, page size, HTML behavior, and maximum displayed records.
validate() rejects invalid themes, non-positive dimensions/DPI, or a negative
record limit.
Compare reports and keep history
Use the returned report ID to find a saved report later. History is stored in
the directory passed to report_history().
from pathlib import Path
from tempfile import TemporaryDirectory
import storq
before = storq.ReportBuilder("Before").build()
after = storq.ReportBuilder("After").build()
comparison = storq.compare_reports(before, after)
print(comparison)
with TemporaryDirectory() as directory:
history = storq.report_history(Path(directory))
history.add(after)
saved = history.get(after.metadata.report_id)
print(saved["metadata"]["title"])
Reports are compared by their report contents; a comparison does not rerun the inspected operation. History writes files in the chosen directory.
Callback benchmarks
The Python benchmark runner measures a caller-provided function. It does not open the supplied database path or generate/run SQL.
import asyncio
import sqlite3
from contextlib import closing
from storq import Benchmark
database = "benchmark.sqlite"
def read_one():
with closing(sqlite3.connect(database)) as connection:
connection.execute("SELECT 1").fetchone()
async def main():
result = await Benchmark("sqlite-read", database, profile="read").run(
iterations=5,
warmup=1,
operation_count=100,
concurrency=4,
operation=read_one,
)
print(result.status)
print(result.aggregate["latency_ns"])
print(result.aggregate["throughput_mean"])
asyncio.run(main())
Benchmark.run(...) creates BenchmarkConfig and delegates to
BenchmarkEngine.run(config, operation=...). The operation is required and
must be callable. Synchronous callbacks execute in worker threads; async
callbacks are awaited. A timed-out synchronous call cannot be forcibly stopped
and may continue running in its thread.
Benchmark configuration and results
BenchmarkConfig fields:
name,database,profile,seediterations(at least 1),warmup(non-negative)operation_count(positive),concurrency(positive)timeout(finite positive number)read_ratio(0..1),resource_interval(finite positive number)workloadmetadata dictionary
Config validation raises ValueError for invalid limits. BenchmarkMeasurement
records operation latencies, elapsed time, success/failure counts and optional
transaction counters. BenchmarkResult contains status, timestamps,
environment/configuration snapshots, measurements, aggregate statistics, and
errors.
Measured operations are split into at most concurrency workers. Every
iteration attempts exactly operation_count calls. Errors are recorded per
call and make the result status failed; warmup errors also make the overall
result fail. profile, read_ratio, seed, and workload do not modify an
opaque callback's behavior.
Benchmark suite, workloads, and utilities
BenchmarkSuite(name).add_database(engine, path)registers a target.await run(profile, iterations, warmup, operation)runs only entries whose engine issqlite; other engines returnunsupportedentries. The callback is still required for actual measurements.BenchmarkWorkload(name, operation, category="mixed", configuration={})describes a callback.create_workload(...)validates that the operation is callable.@workload(name, category)annotates a function.WorkloadManager.register(item)and.get(name)manage those definitions; registration does not itself execute them.mean,median,stddev,percentile,latency_stats, andcoefficient_of_variationcompute descriptive statistics.percentileaccepts a value from 0 to 100 and linearly interpolates between samples.environment_fingerprint(database_engine=None, config=None)captures environment metadata.compare_benchmarks(baseline, current, thresholds=None)compares compatible results.percentage_change(...)anddetect_regressions(...)provide lower-level regression helpers.export_json(result, path)andexport_csv(result, path)serialize benchmark output.BenchmarkHistory.add/get/listpersists and retrieves benchmark results.BenchmarkComparison,RegressionThresholds, andBenchmarkHistoryare result/configuration types for those operations.
Statistics helpers operate on caller-provided samples. For example,
latency_stats() summarizes a list and percentile() uses a 0-to-100
percentile value:
from storq.benchmarking import latency_stats, percentile
latencies = [10, 15, 20, 25, 30]
print(latency_stats(latencies))
print("p95:", percentile(latencies, 95))
History/export writes to caller-selected paths. Choose a directory the application is permitted to write, and do not assume benchmark results are portable across different environments.
