Skip to content

Commit de9b736

Browse files
committed
[GR-54832] Print build artifact sizes in the build output.
1 parent a5e6438 commit de9b736

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

docs/reference-manual/native-image/BuildOutput.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ Recommendations:
9797
1.3s (4.8% of total time) in 88 GCs | Peak RSS: 2.14GiB | CPU load: 18.03
9898
--------------------------------------------------------------------------------
9999
Build artifacts:
100-
/home/janedoe/helloworld/gdb-debughelpers.py (debug_info)
101-
/home/janedoe/helloworld/helloworld (executable)
102-
/home/janedoe/helloworld/helloworld.debug (debug_info)
103-
/home/janedoe/helloworld/sources (debug_info)
100+
/home/janedoe/helloworld/gdb-debughelpers.py (debug_info, 80.60KiB)
101+
/home/janedoe/helloworld/helloworld (executable, 6.88MiB)
102+
/home/janedoe/helloworld/helloworld.debug (debug_info, 6.66MiB)
103+
/home/janedoe/helloworld/sources (debug_info, 37.61MiB)
104104
================================================================================
105105
Finished generating 'helloworld' in 25.5s.
106106
```

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@
5353
import java.util.stream.Collectors;
5454
import java.util.stream.Stream;
5555

56-
import com.oracle.svm.core.RuntimeAssertionsSupport;
57-
import com.oracle.svm.core.util.UserError;
58-
import com.oracle.svm.util.LogUtils;
5956
import org.graalvm.nativeimage.ImageSingletons;
6057
import org.graalvm.nativeimage.hosted.Feature;
6158
import org.graalvm.nativeimage.impl.ImageSingletonsSupport;
@@ -71,6 +68,7 @@
7168
import com.oracle.svm.common.option.CommonOptionParser;
7269
import com.oracle.svm.core.BuildArtifacts;
7370
import com.oracle.svm.core.BuildArtifacts.ArtifactType;
71+
import com.oracle.svm.core.RuntimeAssertionsSupport;
7472
import com.oracle.svm.core.SubstrateGCOptions;
7573
import com.oracle.svm.core.SubstrateOptions;
7674
import com.oracle.svm.core.SubstrateUtil;
@@ -93,6 +91,7 @@
9391
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
9492
import com.oracle.svm.core.traits.SingletonTraits;
9593
import com.oracle.svm.core.util.TimeUtils;
94+
import com.oracle.svm.core.util.UserError;
9695
import com.oracle.svm.core.util.VMError;
9796
import com.oracle.svm.hosted.ProgressReporterFeature.UserRecommendation;
9897
import com.oracle.svm.hosted.ProgressReporterJsonHelper.AnalysisResults;
@@ -108,6 +107,7 @@
108107
import com.oracle.svm.hosted.util.DiagnosticUtils;
109108
import com.oracle.svm.hosted.util.VMErrorReporter;
110109
import com.oracle.svm.util.ImageBuildStatistics;
110+
import com.oracle.svm.util.LogUtils;
111111
import com.sun.management.OperatingSystemMXBean;
112112

113113
import jdk.graal.compiler.options.OptionDescriptor;
@@ -907,7 +907,32 @@ private void printArtifacts(BuildArtifacts artifacts) {
907907
pathToTypes.computeIfAbsent(path, p -> new ArrayList<>()).add(artifactType.name().toLowerCase(Locale.ROOT));
908908
}
909909
});
910-
pathToTypes.forEach((path, typeNames) -> l().a(" ").link(path).dim().a(" (").a(String.join(", ", typeNames)).a(")").reset().println());
910+
pathToTypes.forEach((path, typeNames) -> {
911+
String artifactTypesString = String.join(", ", typeNames);
912+
long artifactSize = getArtifactSize(path);
913+
String artifactSizeString = artifactSize >= 0 ? ByteFormattingUtil.bytesToHuman(artifactSize) : "unknown size";
914+
l().a(" ").link(path).dim().a(" (").a(artifactTypesString).a(", ").a(artifactSizeString).a(")").reset().println();
915+
});
916+
}
917+
918+
private static long getArtifactSize(Path artifactPath) {
919+
try {
920+
if (Files.isRegularFile(artifactPath)) {
921+
return Files.size(artifactPath);
922+
} else {
923+
try (Stream<Path> artifactDirectorySubPaths = Files.walk(artifactPath)) {
924+
return artifactDirectorySubPaths.filter(Files::isRegularFile).mapToLong(filePath -> {
925+
try {
926+
return Files.size(filePath);
927+
} catch (IOException e) {
928+
return 0;
929+
}
930+
}).sum();
931+
}
932+
}
933+
} catch (IOException e) {
934+
return -1;
935+
}
911936
}
912937

913938
private Path reportBuildOutput(Path jsonOutputFile) {

0 commit comments

Comments
 (0)