Skip to content

Commit 7e9796a

Browse files
authored
Merge pull request #274 from gradle/erichaagdev/display-potential-build-time-savings
Display potential build time savings in experiment summaries
2 parents 322d555 + a3f0dad commit 7e9796a

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

components/fetch-build-scan-data-cmdline-tool/src/main/java/com/gradle/enterprise/cli/Fields.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public enum Fields {
3333
EXECUTED_NOT_CACHEABLE_DURATION("Executed not cacheable duration", d -> totalDuration(d, "executed_not_cacheable")),
3434
EFFECTIVE_TASK_EXECUTION_DURATION("Effective task execution duration", d -> String.valueOf(d.getEffectiveTaskExecutionDuration().toMillis())),
3535
SERIALIZATION_FACTOR("Serialization factor", d -> formatBigDecimal(d.getSerializationFactor())),
36+
EXECUTED_CACHEABLE_DURATION_MILLISECONDS("Executed cacheable duration milliseconds", d -> totalDurationMillis(d, "executed_cacheable")),
3637
;
3738

3839
public final String label;
@@ -77,6 +78,15 @@ private static String totalDuration(BuildValidationData data, String avoidanceOu
7778
);
7879
}
7980

81+
private static String totalDurationMillis(BuildValidationData data, String avoidanceOutcome) {
82+
return String.valueOf(
83+
data.getTasksByAvoidanceOutcome()
84+
.getOrDefault(avoidanceOutcome, TaskExecutionSummary.ZERO)
85+
.totalDuration()
86+
.toMillis()
87+
);
88+
}
89+
8090
private static String formatDuration(Duration duration) {
8191
long hours = duration.toHours();
8292
long minutes = duration.minusHours(hours).toMinutes();

components/scripts/lib/build-scan-parse.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ executed_not_cacheable_duration=()
2828
# Build duration metrics
2929
effective_task_execution_duration=()
3030
serialization_factors=()
31+
executed_cacheable_duration_milliseconds=()
3132

3233
parse_build_scan_csv() {
3334
# This isn't the most robust way to read a CSV,
@@ -46,7 +47,7 @@ parse_build_scan_csv() {
4647
idx=0
4748

4849
# shellcheck disable=SC2034 # not all scripts use all of the fetched data
49-
while IFS=, read -r field_1 field_2 field_3 field_4 field_5 field_6 field_7 field_8 field_9 field_10 field_11 field_12 field_13 field_14 field_15 field_16 field_17 field_18 field_19 field_20 field_21; do
50+
while IFS=, read -r field_1 field_2 field_3 field_4 field_5 field_6 field_7 field_8 field_9 field_10 field_11 field_12 field_13 field_14 field_15 field_16 field_17 field_18 field_19 field_20 field_21 field_22; do
5051
if [[ "$header_row_read" == "false" ]]; then
5152
header_row_read=true
5253
continue;
@@ -86,6 +87,10 @@ parse_build_scan_csv() {
8687
serialization_factors[idx]="${field_21}"
8788
fi
8889

90+
if [[ -n "$field_22" ]]; then
91+
executed_cacheable_duration_milliseconds[idx]="${field_22}"
92+
fi
93+
8994
((idx++))
9095
done <<< "${build_scan_csv}"
9196
}

components/scripts/lib/info.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ print_performance_characteristics() {
140140

141141
print_realized_build_time_savings
142142

143+
print_potential_build_time_savings
144+
143145
print_build_caching_leverage_metrics
144146

145147
print_serialization_factor
@@ -172,6 +174,35 @@ print_realized_build_time_savings() {
172174
fi
173175
}
174176

177+
print_potential_build_time_savings() {
178+
local build_1_effective_execution_duration="${effective_task_execution_duration[0]}"
179+
180+
local build_2_effective_execution_duration="${effective_task_execution_duration[1]}"
181+
local build_2_executed_cacheable_duration="${executed_cacheable_duration_milliseconds[1]}"
182+
local build_2_serialization_factor="${serialization_factors[1]}"
183+
184+
# Do not print potential build time savings at all if these values do not exist
185+
# This can happen since build-scan-support-tool does not yet support these fields
186+
if [[ -z "${build_1_effective_execution_duration}" || -z "${build_2_effective_execution_duration}" || -z "${build_2_executed_cacheable_duration}" || -z "${build_2_serialization_factor}" ]]; then
187+
return 0
188+
fi
189+
190+
local value
191+
value=""
192+
# Only calculate realized build time savings when these have valid values
193+
# These values can be returned as zero when an error occurs processing the Build Scan data
194+
if [[ "${build_1_effective_execution_duration}" && "${build_2_effective_execution_duration}" && -n "${build_2_serialization_factor}" ]]; then
195+
local first_build second_build potential_build_duration potential_savings
196+
first_build=$(format_duration "${effective_task_execution_duration[0]}")
197+
# shellcheck disable=SC2034 # it's used on the next few lines
198+
potential_build_duration=$(echo "${build_2_effective_execution_duration}-(${build_2_executed_cacheable_duration}/${build_2_serialization_factor})" | bc)
199+
potential_savings=$(format_duration build_1_effective_execution_duration-potential_build_duration)
200+
second_build=$(format_duration potential_build_duration)
201+
value="${potential_savings} wall-clock time (from ${first_build} to ${second_build})"
202+
fi
203+
summary_row "Potential build time savings:" "${value}"
204+
}
205+
175206
print_build_caching_leverage_metrics() {
176207
local task_count_padding
177208
task_count_padding=$(max_length "${avoided_from_cache_num_tasks[1]}" "${executed_cacheable_num_tasks[1]}" "${executed_not_cacheable_num_tasks[1]}")

0 commit comments

Comments
 (0)