1- use std:: sync:: Arc ;
1+ use std:: { str :: FromStr , sync:: Arc } ;
22
33use database:: {
44 metric:: Metric ,
@@ -7,16 +7,95 @@ use database::{
77} ;
88use tabled:: { Table , Tabled } ;
99
10+ static ALL_METRICS : & [ Metric ] = & [
11+ Metric :: InstructionsUser ,
12+ Metric :: Cycles ,
13+ Metric :: WallTime ,
14+ Metric :: MaxRSS ,
15+ Metric :: LinkedArtifactSize ,
16+ Metric :: AssemblyFileSize ,
17+ Metric :: BranchMisses ,
18+ Metric :: CacheMisses ,
19+ Metric :: CodegenUnitLlvmIrCount ,
20+ Metric :: CodegenUnitSize ,
21+ Metric :: ContextSwitches ,
22+ Metric :: CpuClock ,
23+ Metric :: CpuClockUser ,
24+ Metric :: CrateMetadataSize ,
25+ Metric :: CyclesUser ,
26+ Metric :: DepGraphSize ,
27+ Metric :: DocByteSize ,
28+ Metric :: DwoFileSize ,
29+ Metric :: Faults ,
30+ Metric :: FaultsUser ,
31+ Metric :: LlvmBitcodeSize ,
32+ Metric :: LlvmIrSize ,
33+ Metric :: ObjectFileSize ,
34+ Metric :: QueryCacheSize ,
35+ Metric :: TaskClock ,
36+ Metric :: TaskClockUser ,
37+ Metric :: WorkProductIndexSize ,
38+ ] ;
39+
1040/// Compare 2 artifacts and print the result.
1141pub async fn compare_artifacts (
1242 mut conn : Box < dyn Connection > ,
13- base : String ,
14- modified : String ,
43+ metric : Option < Metric > ,
44+ base : Option < String > ,
45+ modified : Option < String > ,
1546) -> anyhow:: Result < ( ) > {
1647 let index = database:: Index :: load ( & mut * conn) . await ;
1748
18- let query = CompileBenchmarkQuery :: default ( )
19- . metric ( database:: selector:: Selector :: One ( Metric :: InstructionsUser ) ) ;
49+ let metric = match metric {
50+ Some ( v) => v,
51+ None => {
52+ let metric_str = inquire:: Select :: new (
53+ "Choose metric:" ,
54+ ALL_METRICS . iter ( ) . map ( |m| m. as_str ( ) ) . collect :: < Vec < _ > > ( ) ,
55+ )
56+ . prompt ( ) ?;
57+ Metric :: from_str ( metric_str) . map_err ( |e| anyhow:: anyhow!( e) ) ?
58+ }
59+ } ;
60+
61+ let mut aids = index. artifacts ( ) . map ( str:: to_string) . collect :: < Vec < _ > > ( ) ;
62+ if aids. len ( ) < 2 {
63+ return Err ( anyhow:: anyhow!(
64+ "There are not enough artifacts to compare, at least two are needed"
65+ ) ) ;
66+ }
67+
68+ let select_artifact_id = |name : & str , aids : & Vec < String > | {
69+ anyhow:: Ok (
70+ inquire:: Select :: new (
71+ & format ! ( "Choose {} artifact to compare:" , name) ,
72+ aids. clone ( ) ,
73+ )
74+ . prompt ( ) ?,
75+ )
76+ } ;
77+
78+ let base = match base {
79+ Some ( v) => v,
80+ None => select_artifact_id ( "base" , & aids) ?. to_string ( ) ,
81+ } ;
82+ aids. retain ( |id| id != & base) ;
83+ let modified = if aids. len ( ) == 1 {
84+ let new_modified = aids[ 0 ] . clone ( ) ;
85+ println ! (
86+ "Only 1 artifact remains, automatically selecting: {}" ,
87+ new_modified
88+ ) ;
89+
90+ new_modified
91+ } else {
92+ match modified {
93+ Some ( v) => v,
94+ None => select_artifact_id ( "modified" , & aids) ?. to_string ( ) ,
95+ }
96+ } ;
97+
98+ let query = CompileBenchmarkQuery :: default ( ) . metric ( database:: selector:: Selector :: One ( metric) ) ;
2099 let resp = query
21100 . execute (
22101 & mut * conn,
0 commit comments