@@ -12,36 +12,53 @@ use crate::not_bash::{fs2, pushd, rm_rf, run};
1212
1313type Unit = & ' static str ;
1414
15- pub fn run_metrics ( ) -> Result < ( ) > {
16- let mut metrics = Metrics :: new ( ) ?;
17- metrics. measure_build ( ) ?;
18-
19- {
20- let _d = pushd ( "target" ) ;
21- let metrics_token = env:: var ( "METRICS_TOKEN" ) . unwrap ( ) ;
22- let repo = format ! ( "https://{}@github.com/rust-analyzer/metrics.git" , metrics_token) ;
23- run ! ( "git clone --depth 1 {}" , repo) ?;
24- let _d = pushd ( "metrics" ) ;
25-
26- let mut file = std:: fs:: OpenOptions :: new ( ) . append ( true ) . open ( "metrics.json" ) ?;
27- writeln ! ( file, "{}" , metrics. json( ) ) ?;
28- run ! ( "git add ." ) ?;
29- run ! ( "git -c user.name=Bot -c [email protected] commit --message 📈" ) ?
; 30- run ! ( "git push origin master" ) ?;
31- }
32- eprintln ! ( "{:#?}" , metrics) ;
33- Ok ( ( ) )
15+ pub struct MetricsCmd {
16+ pub dry_run : bool ,
17+ }
18+
19+ impl MetricsCmd {
20+ pub fn run ( self ) -> Result < ( ) > {
21+ let mut metrics = Metrics :: new ( ) ?;
22+ if !self . dry_run {
23+ rm_rf ( "./target/release" ) ?;
24+ }
25+
26+ metrics. measure_build ( ) ?;
27+ metrics. measure_analysis_stats_self ( ) ?;
28+
29+ if !self . dry_run {
30+ let _d = pushd ( "target" ) ;
31+ let metrics_token = env:: var ( "METRICS_TOKEN" ) . unwrap ( ) ;
32+ let repo = format ! ( "https://{}@github.com/rust-analyzer/metrics.git" , metrics_token) ;
33+ run ! ( "git clone --depth 1 {}" , repo) ?;
34+ let _d = pushd ( "metrics" ) ;
35+
36+ let mut file = std:: fs:: OpenOptions :: new ( ) . append ( true ) . open ( "metrics.json" ) ?;
37+ writeln ! ( file, "{}" , metrics. json( ) ) ?;
38+ run ! ( "git add ." ) ?;
39+ run ! ( "git -c user.name=Bot -c [email protected] commit --message 📈" ) ?
; 40+ run ! ( "git push origin master" ) ?;
41+ }
42+ eprintln ! ( "{:#?}" , metrics) ;
43+ Ok ( ( ) )
44+ }
3445}
3546
3647impl Metrics {
3748 fn measure_build ( & mut self ) -> Result < ( ) > {
3849 run ! ( "cargo fetch" ) ?;
39- rm_rf ( "./target/release" ) ?;
4050
41- let build = Instant :: now ( ) ;
51+ let time = Instant :: now ( ) ;
4252 run ! ( "cargo build --release --package rust-analyzer --bin rust-analyzer" ) ?;
43- let build = build. elapsed ( ) ;
44- self . report ( "build" , build. as_millis ( ) as u64 , "ms" ) ;
53+ let time = time. elapsed ( ) ;
54+ self . report ( "build" , time. as_millis ( ) as u64 , "ms" ) ;
55+ Ok ( ( ) )
56+ }
57+ fn measure_analysis_stats_self ( & mut self ) -> Result < ( ) > {
58+ let time = Instant :: now ( ) ;
59+ run ! ( "./target/release/rust-analyzer analysis-stats ." ) ?;
60+ let time = time. elapsed ( ) ;
61+ self . report ( "analysis-stats/self" , time. as_millis ( ) as u64 , "ms" ) ;
4562 Ok ( ( ) )
4663 }
4764}
0 commit comments