@@ -43,15 +43,6 @@ cargo run --quiet -p codehelion -- scan \
4343 --output " $temporary_root /source-scan.json"
4444source_run=$( sed -n ' s/^[[:space:]]*"run_id": \([0-9][0-9]*\),\{0,1\}$/\1/p' " $temporary_root /source-scan.json" )
4545test -n " $source_run "
46- calibration_group=$( awk '
47- /"groups": \[/ { groups = 1; next }
48- groups && /"fingerprint":/ {
49- fingerprint = $2
50- gsub(/[",]/, "", fingerprint)
51- }
52- groups && /"scope": "fragment"/ { print fingerprint; exit }
53- ' " $temporary_root /source-scan.json" )
54- test -n " $calibration_group "
5546
5647cargo run --quiet -p codehelion -- artifact analyze \
5748 " $fixture_root /build/debug/duplicates.wasm" \
@@ -68,11 +59,26 @@ cargo run --quiet -p codehelion -- artifact analyze \
6859 --linker-map " $fixture_root /build/debug/libduplicates.map" \
6960 --db " $temporary_root /artifact.sqlite" \
7061 --output " $temporary_root /elf.json"
62+ # Calibration measures the savings model over one clone group, so it needs a
63+ # group the analysis actually attributed artifact bytes to. Only a group whose
64+ # every non-canonical member was attributed carries an estimate, and reading it
65+ # out of the report says which one that was instead of assuming.
66+ calibration_group=$( awk '
67+ /"clone_group_fingerprint":/ {
68+ fingerprint = $2
69+ gsub(/[",]/, "", fingerprint)
70+ }
71+ /"estimated_refactor_savings_bytes": -?[0-9]/ { print fingerprint; exit }
72+ ' " $temporary_root /elf.json" )
73+ test -n " $calibration_group "
7174objcopy --only-keep-debug \
7275 " $fixture_root /build/debug/libduplicates.so" \
7376 " $temporary_root /libduplicates.debug"
7477cp " $fixture_root /build/debug/libduplicates.so" " $temporary_root /libduplicates-split.so"
7578objcopy --strip-debug " $temporary_root /libduplicates-split.so"
79+ cp " $fixture_root /build/debug-deduplicated/libduplicates.so" \
80+ " $temporary_root /libduplicates-split-deduplicated.so"
81+ objcopy --strip-debug " $temporary_root /libduplicates-split-deduplicated.so"
7682cargo run --quiet -p codehelion -- artifact analyze \
7783 " $temporary_root /libduplicates-split.so" \
7884 --format json \
@@ -137,16 +143,22 @@ cargo run --quiet -p codehelion -- artifact calibration \
137143 --db " $temporary_root /artifact.sqlite" \
138144 --format json \
139145 --output " $temporary_root /calibration-baseline.json"
146+ # A second measurement, so the baseline comparison above has something to
147+ # compare. It is the same code with its debug information in a separate file:
148+ # a different artifact, separately analysed, whose estimate is its own. The
149+ # optimized builds cannot stand here — an optimizer leaves no line evidence
150+ # tying each member of a clone group to its own bytes, so nothing in them is
151+ # attributed and there is no estimate to measure.
140152cargo run --quiet -p codehelion -- artifact compare \
141- " $fixture_root /build/release-lto/ libduplicates.so" \
142- " $fixture_root /build/release-lto -deduplicated/libduplicates .so" \
143- --before-build-variant " $fixture_root /build/release-lto /build-variant.json" \
144- --after-build-variant " $fixture_root /build/release-lto -deduplicated/build-variant.json" \
153+ " $temporary_root / libduplicates-split .so" \
154+ " $temporary_root /libduplicates-split -deduplicated.so" \
155+ --before-build-variant " $fixture_root /build/debug /build-variant.json" \
156+ --after-build-variant " $fixture_root /build/debug -deduplicated/build-variant.json" \
145157 --source-run " $source_run " \
146158 --clone-group " $calibration_group " \
147159 --db " $temporary_root /artifact.sqlite" \
148160 --format json \
149- --output " $temporary_root /compare-calibration-release-lto .json"
161+ --output " $temporary_root /compare-calibration-split-debug .json"
150162cargo run --quiet -p codehelion -- artifact calibration \
151163 --source-run " $source_run " \
152164 --baseline " $temporary_root /calibration-baseline.json" \
@@ -169,9 +181,26 @@ grep -qE '"source_mappings": [1-9]' "$temporary_root/elf-split-debug.json"
169181grep -qE ' "mappings": [1-9]' " $temporary_root /elf-split-debug.json"
170182grep -qE ' "estimated_refactor_savings_bytes": -?[1-9][0-9]*' " $temporary_root /elf.json"
171183grep -qE ' "exact_groups": [1-9]' " $temporary_root /elf.json"
172- grep -qE ' "normalized_groups": [1-9]' " $temporary_root /elf.json"
184+ # Normalized duplicate detection reads machine instructions, and the only
185+ # normalizer here is for x86-64. Elsewhere the count is nothing rather than
186+ # something missed, and saying which is expected keeps the run honest on a
187+ # machine of either kind.
188+ case " $( uname -m) " in
189+ x86_64 | amd64)
190+ grep -qE ' "normalized_groups": [1-9]' " $temporary_root /elf.json"
191+ ;;
192+ * )
193+ grep -qE ' "normalized_groups": 0' " $temporary_root /elf.json"
194+ ;;
195+ esac
173196grep -qE ' "format": "elf"' " $temporary_root /elf-release-lto.json"
174- grep -qE ' "estimated_refactor_savings_bytes": -?[1-9][0-9]*' " $temporary_root /elf-release-lto.json"
197+ # The optimized build is read and correlated like any other, and it estimates
198+ # nothing: an optimizer leaves no line evidence tying each member of a clone
199+ # group to its own bytes, so no group has every member attributed. Saying so
200+ # is the point — an estimate here would be one nothing in the artifact
201+ # supports.
202+ grep -qE ' "correlation": \{' " $temporary_root /elf-release-lto.json"
203+ grep -qE ' "estimated_refactor_savings": \[\]' " $temporary_root /elf-release-lto.json"
175204grep -qE ' "format": "wasm"' " $temporary_root /wasm-deduplicated.json"
176205grep -qE ' "size_inferred": true' " $temporary_root /elf-stripped.json"
177206for field in \
183212 grep -qE " \" $field \" " " $temporary_root /wasm.json"
184213 grep -qE " \" $field \" " " $temporary_root /elf.json"
185214done
186- grep -qE ' "verified_savings_bytes": [0-9]+' " $temporary_root /compare.json"
215+ # A comparison measures the difference between two artifacts, which is an
216+ # observation and not a verified saving: nothing here says the difference came
217+ # from removing a duplicate. Only the calibrated comparisons below, which name
218+ # a source run and a clone group, produce a verified figure.
219+ grep -qE ' "observed_size_reduction_bytes": -?[0-9]+' " $temporary_root /compare.json"
187220grep -qE ' "build_variant_warning": "build variants differ' " $temporary_root /compare.json"
188- grep -qE ' "verified_savings_bytes ": [0-9]+' " $temporary_root /compare-elf.json"
221+ grep -qE ' "observed_size_reduction_bytes ": -? [0-9]+' " $temporary_root /compare-elf.json"
189222grep -qE ' "build_variant_warning": "build variants differ' " $temporary_root /compare-elf.json"
190- grep -qE ' "verified_savings_bytes": [1-9][0-9]*' " $temporary_root /compare-deduplicated.json"
223+ # The deduplicated pair is the one case where the difference has a direction:
224+ # the same build with the duplicate removed is smaller.
225+ grep -qE ' "observed_size_reduction_bytes": [1-9][0-9]*' " $temporary_root /compare-deduplicated.json"
191226grep -qE ' "calibration": \{' " $temporary_root /compare-calibration.json"
192227grep -qE ' "verified_savings_bytes": [1-9][0-9]*' " $temporary_root /compare-calibration.json"
193- grep -qE ' "calibration": \{' " $temporary_root /compare-calibration-release-lto .json"
194- grep -qE ' "verified_savings_bytes": [1-9][0-9]*' " $temporary_root /compare-calibration-release-lto .json"
228+ grep -qE ' "calibration": \{' " $temporary_root /compare-calibration-split-debug .json"
229+ grep -qE ' "verified_savings_bytes": [1-9][0-9]*' " $temporary_root /compare-calibration-split-debug .json"
195230grep -qE ' "samples": 2' " $temporary_root /calibration.json"
196231grep -qE ' "comparison": \{' " $temporary_root /calibration.json"
197232grep -qE ' "baseline_schema_version": "artifact-calibration-report-v1"' " $temporary_root /calibration.json"
0 commit comments