Skip to content

Commit aa46724

Browse files
willcl-arkgithub-actions[bot]
authored andcommitted
use commit date in chart data points
1 parent dc30fe0 commit aa46724

3 files changed

Lines changed: 42 additions & 10 deletions

File tree

.github/workflows/nightly-benchmark.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ jobs:
2626
BITCOIN_SHA=$(git merge-base HEAD upstream/master)
2727
echo "BITCOIN_SHA=$BITCOIN_SHA" >> "$GITHUB_ENV"
2828
29+
# Get commit date for the Bitcoin commit (for chart X-axis)
30+
COMMIT_DATE=$(git log -1 --format=%cd --date=short "$BITCOIN_SHA")
31+
echo "COMMIT_DATE=$COMMIT_DATE" >> "$GITHUB_ENV"
32+
2933
echo "Benchcoin: $(git rev-parse HEAD)"
3034
echo "Bitcoin merge-base: $BITCOIN_SHA"
35+
echo "Commit date: $COMMIT_DATE"
3136
3237
- name: Build master binary
3338
run: |
@@ -44,10 +49,13 @@ jobs:
4449
- name: Upload commit info
4550
run: |
4651
echo "$BITCOIN_SHA" > ${{ runner.temp }}/commit.txt
52+
echo "$COMMIT_DATE" > ${{ runner.temp }}/commit-date.txt
4753
- uses: actions/upload-artifact@v4
4854
with:
4955
name: commit-info
50-
path: ${{ runner.temp }}/commit.txt
56+
path: |
57+
${{ runner.temp }}/commit.txt
58+
${{ runner.temp }}/commit-date.txt
5159
5260
- name: Capture machine specs
5361
run: |
@@ -151,9 +159,13 @@ jobs:
151159
with:
152160
python-version: '3.12'
153161

154-
- name: Get current date
162+
- name: Get dates
155163
run: |
156-
echo "DATE=$(date -u +%Y-%m-%d)" >> "$GITHUB_ENV"
164+
# Commit date (for chart X-axis)
165+
COMMIT_DATE=$(cat ./commit-info/commit-date.txt)
166+
echo "COMMIT_DATE=$COMMIT_DATE" >> "$GITHUB_ENV"
167+
# Run date (for reference)
168+
echo "RUN_DATE=$(date -u +%Y-%m-%d)" >> "$GITHUB_ENV"
157169
158170
- name: Append results to history
159171
run: |
@@ -167,7 +179,8 @@ jobs:
167179
../nightly-450-results/results.json \
168180
"$COMMIT" \
169181
450 \
170-
--date "$DATE" \
182+
--date "$COMMIT_DATE" \
183+
--run-date "$RUN_DATE" \
171184
--benchmark-config bench/configs/nightly.toml \
172185
--machine-specs ../machine-specs/machine-specs.json
173186
@@ -178,7 +191,8 @@ jobs:
178191
../nightly-32000-results/results.json \
179192
"$COMMIT" \
180193
32000 \
181-
--date "$DATE" \
194+
--date "$COMMIT_DATE" \
195+
--run-date "$RUN_DATE" \
182196
--benchmark-config bench/configs/nightly.toml \
183197
--machine-specs ../machine-specs/machine-specs.json
184198
@@ -195,5 +209,5 @@ jobs:
195209
git config --global user.name "github-actions[bot]"
196210
git config --global user.email "github-actions[bot]@users.noreply.github.com"
197211
git add nightly-history.json index.html
198-
git commit -m "Update nightly benchmark results for $DATE" || echo "No changes to commit"
212+
git commit -m "Update nightly benchmark results for $COMMIT_DATE" || echo "No changes to commit"
199213
git push origin gh-pages

bench.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ def cmd_nightly(args: argparse.Namespace) -> int:
323323
benchmark_config_file=benchmark_config_file,
324324
instrumentation=args.instrumentation,
325325
machine_specs_file=machine_specs_file,
326+
run_date=args.run_date or "",
326327
)
327328
logger.info(f"Appended result to {history_file}")
328329
elif args.nightly_command == "chart":
@@ -566,6 +567,11 @@ def main() -> int:
566567
metavar="PATH",
567568
help="Path to pre-captured machine specs JSON (default: detect current machine)",
568569
)
570+
nightly_append.add_argument(
571+
"--run-date",
572+
metavar="YYYY-MM-DD",
573+
help="Date when benchmark was executed (default: today). Stored for reference.",
574+
)
569575

570576
# nightly chart
571577
nightly_chart = nightly_subparsers.add_parser(

bench/nightly.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def series_label(result: "NightlyResult") -> str:
138138
class NightlyResult:
139139
"""A single nightly benchmark result with embedded config and machine info."""
140140

141-
date: str
141+
date: str # Commit date (YYYY-MM-DD) - displayed on chart X-axis
142142
commit: str
143143
mean: float
144144
stddev: float
@@ -147,6 +147,7 @@ class NightlyResult:
147147
str, Any
148148
] # Full benchmark config (dbcache inside config.bitcoind.dbcache)
149149
machine: dict[str, Any] # Full machine specs
150+
run_date: str = "" # When benchmark was executed (reference only)
150151

151152
@property
152153
def dbcache(self) -> int:
@@ -168,7 +169,7 @@ def instrumentation(self) -> str:
168169

169170
def to_dict(self) -> dict[str, Any]:
170171
"""Convert to dictionary for JSON serialization."""
171-
return {
172+
result = {
172173
"date": self.date,
173174
"commit": self.commit,
174175
"mean": self.mean,
@@ -177,6 +178,9 @@ def to_dict(self) -> dict[str, Any]:
177178
"config": self.config,
178179
"machine": self.machine,
179180
}
181+
if self.run_date:
182+
result["run_date"] = self.run_date
183+
return result
180184

181185
@classmethod
182186
def from_dict(cls, data: dict[str, Any]) -> NightlyResult:
@@ -194,6 +198,7 @@ def from_dict(cls, data: dict[str, Any]) -> NightlyResult:
194198
runs=data["runs"],
195199
config=data["config"],
196200
machine=data.get("machine", {}),
201+
run_date=data.get("run_date", ""),
197202
)
198203

199204
# Legacy format - convert to new format
@@ -209,6 +214,7 @@ def from_dict(cls, data: dict[str, Any]) -> NightlyResult:
209214
"instrumentation": "uninstrumented",
210215
},
211216
machine={},
217+
run_date=data.get("run_date", ""),
212218
)
213219

214220

@@ -316,6 +322,7 @@ def append_from_results_json(
316322
benchmark_config: dict[str, Any],
317323
machine_specs: dict[str, Any],
318324
date_str: str | None = None,
325+
run_date: str = "",
319326
) -> None:
320327
"""Append result from a hyperfine results.json file.
321328
@@ -324,7 +331,8 @@ def append_from_results_json(
324331
commit: Git commit hash
325332
benchmark_config: Full benchmark config dict (includes bitcoind.dbcache)
326333
machine_specs: Machine specs dict
327-
date_str: Date string (YYYY-MM-DD), defaults to today
334+
date_str: Commit date string (YYYY-MM-DD), defaults to today
335+
run_date: When the benchmark was executed (YYYY-MM-DD), for reference
328336
"""
329337
if not results_file.exists():
330338
raise FileNotFoundError(f"Results file not found: {results_file}")
@@ -355,6 +363,7 @@ def append_from_results_json(
355363
runs=runs,
356364
config=benchmark_config,
357365
machine=machine_specs,
366+
run_date=run_date,
358367
)
359368
self.append(result)
360369

@@ -391,17 +400,19 @@ def append(
391400
benchmark_config_file: Path | None = None,
392401
instrumentation: str = "uninstrumented",
393402
machine_specs_file: Path | None = None,
403+
run_date: str = "",
394404
) -> None:
395405
"""Append a result from hyperfine results.json to history.
396406
397407
Args:
398408
results_file: Path to hyperfine results.json
399409
commit: Git commit hash
400410
dbcache: DB cache size in MB
401-
date_str: Date string (YYYY-MM-DD), defaults to today
411+
date_str: Commit date string (YYYY-MM-DD), defaults to today
402412
benchmark_config_file: Path to benchmark config TOML
403413
instrumentation: Instrumentation mode ('uninstrumented' or 'instrumented')
404414
machine_specs_file: Path to pre-captured machine specs JSON (optional)
415+
run_date: When the benchmark was executed (YYYY-MM-DD), for reference
405416
"""
406417
from bench.benchmark_config import BenchmarkConfig
407418

@@ -435,6 +446,7 @@ def append(
435446
benchmark_config=config_dict,
436447
machine_specs=machine_specs,
437448
date_str=date_str,
449+
run_date=run_date,
438450
)
439451
history.save()
440452

0 commit comments

Comments
 (0)