@@ -26,7 +26,9 @@ use tabled::settings::{Alignment, Border, Color, Modify};
2626use tokio:: runtime:: Runtime ;
2727
2828use collector:: api:: next_artifact:: NextArtifact ;
29- use collector:: artifact_stats:: { compile_and_get_stats, ArtifactWithStats , CargoProfile } ;
29+ use collector:: artifact_stats:: {
30+ compile_and_get_stats, ArtifactStats , ArtifactWithStats , CargoProfile ,
31+ } ;
3032use collector:: codegen:: { codegen_diff, CodegenType } ;
3133use collector:: compile:: benchmark:: category:: Category ;
3234use collector:: compile:: benchmark:: codegen_backend:: CodegenBackend ;
@@ -431,12 +433,25 @@ struct BinaryStatsCompile {
431433 codegen_backend2 : Option < CodegenBackend > ,
432434}
433435
436+ #[ derive( Debug , clap:: Args ) ]
437+ #[ command( rename_all = "snake_case" ) ]
438+ struct BinaryStatsLocal {
439+ /// Binary artifact to examine.
440+ artifact : PathBuf ,
441+
442+ /// Optional second artifact to compare with the first one.
443+ artifact2 : Option < PathBuf > ,
444+ }
445+
434446#[ derive( Debug , clap:: Subcommand ) ]
435447#[ command( rename_all = "snake_case" ) ]
436448enum BinaryStatsMode {
437449 /// Show size statistics for the selected compile benchmark(s).
438450 /// Optionally compares sizes between two compiler toolchains, if `--rustc2` is provided.
439451 Compile ( BinaryStatsCompile ) ,
452+ /// Show size statistics for the selected binary artifact on disk.
453+ /// Optionally compares sizes with a second provided artifact, if `--artifact2` is provided.
454+ Local ( BinaryStatsLocal ) ,
440455}
441456
442457// For each subcommand we list the mandatory arguments in the required
@@ -667,6 +682,9 @@ fn main_result() -> anyhow::Result<i32> {
667682 BinaryStatsMode :: Compile ( args) => {
668683 binary_stats_compile ( args, symbols, & target_triple) ?;
669684 }
685+ BinaryStatsMode :: Local ( args) => {
686+ binary_stats_local ( args, symbols) ?;
687+ }
670688 }
671689
672690 Ok ( 0 )
@@ -1168,6 +1186,29 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
11681186 }
11691187}
11701188
1189+ fn binary_stats_local ( args : BinaryStatsLocal , symbols : bool ) -> anyhow:: Result < ( ) > {
1190+ let stats = ArtifactStats :: from_path ( & args. artifact )
1191+ . with_context ( || format ! ( "Cannot load artifact from {}" , args. artifact. display( ) ) ) ?;
1192+ let stats2 = args
1193+ . artifact2
1194+ . as_ref ( )
1195+ . map ( |path| {
1196+ ArtifactStats :: from_path ( & path)
1197+ . with_context ( || format ! ( "Cannot load artifact from {}" , path. display( ) ) )
1198+ } )
1199+ . transpose ( ) ?;
1200+ print_binary_stats (
1201+ "Sections" ,
1202+ stats. sections ,
1203+ stats2. as_ref ( ) . map ( |s| s. sections . clone ( ) ) ,
1204+ ) ;
1205+ if symbols {
1206+ print_binary_stats ( "Symbols" , stats. symbols , stats2. map ( |s| s. symbols ) ) ;
1207+ }
1208+
1209+ Ok ( ( ) )
1210+ }
1211+
11711212fn binary_stats_compile (
11721213 args : BinaryStatsCompile ,
11731214 symbols : bool ,
0 commit comments