@@ -6,8 +6,11 @@ use pet::resolve::resolve_environment;
66use pet_conda:: Conda ;
77use pet_conda:: CondaLocator ;
88use pet_core:: python_environment:: PythonEnvironment ;
9+ use pet_core:: telemetry:: refresh_performance:: RefreshPerformance ;
10+ use pet_core:: telemetry:: TelemetryEvent ;
911use pet_core:: {
1012 os_environment:: { Environment , EnvironmentApi } ,
13+ reporter:: Reporter ,
1114 Configuration , Locator ,
1215} ;
1316use pet_env_var_path:: get_search_paths_from_env_variables;
@@ -21,14 +24,17 @@ use pet_reporter::collect;
2124use pet_reporter:: { cache:: CacheReporter , jsonrpc} ;
2225use pet_telemetry:: report_inaccuracies_identified_after_resolving;
2326use serde:: { Deserialize , Serialize } ;
27+ use serde_json:: json;
2428use serde_json:: { self , Value } ;
29+ use std:: collections:: BTreeMap ;
2530use std:: sync:: atomic:: { AtomicBool , Ordering } ;
31+ use std:: time:: Duration ;
2632use std:: {
2733 ops:: Deref ,
2834 path:: PathBuf ,
2935 sync:: { Arc , RwLock } ,
3036 thread,
31- time:: { Duration , SystemTime } ,
37+ time:: SystemTime ,
3238} ;
3339
3440use crate :: find:: find_and_report_envs;
@@ -132,6 +138,10 @@ impl RefreshResult {
132138}
133139
134140pub fn handle_refresh ( context : Arc < Context > , id : u32 , params : Value ) {
141+ let params = match params {
142+ Value :: Null => json ! ( { } ) ,
143+ _ => params,
144+ } ;
135145 match serde_json:: from_value :: < RefreshOptions > ( params. clone ( ) ) {
136146 Ok ( refres_options) => {
137147 // Start in a new thread, we can have multiple requests.
@@ -148,25 +158,31 @@ pub fn handle_refresh(context: Arc<Context>, id: u32, params: Value) {
148158 refres_options. search_scope ,
149159 ) ;
150160 let summary = summary. lock ( ) . unwrap ( ) ;
151- for locator in summary. find_locators_times . iter ( ) {
161+ for locator in summary. locators . iter ( ) {
152162 info ! ( "Locator {} took {:?}" , locator. 0 , locator. 1 ) ;
153163 }
154- info ! (
155- "Environments found using locators in {:?}" ,
156- summary. find_locators_time
157- ) ;
158- info ! ( "Environments in PATH found in {:?}" , summary. find_path_time) ;
159- info ! (
160- "Environments in global virtual env paths found in {:?}" ,
161- summary. find_global_virtual_envs_time
162- ) ;
163- info ! (
164- "Environments in workspace folders found in {:?}" ,
165- summary. find_workspace_directories_time
166- ) ;
167- trace ! ( "Finished refreshing environments in {:?}" , summary. time) ;
168- send_reply ( id, Some ( RefreshResult :: new ( summary. time ) ) ) ;
164+ for item in summary. breakdown . iter ( ) {
165+ info ! ( "Locator {} took {:?}" , item. 0 , item. 1 ) ;
166+ }
167+ trace ! ( "Finished refreshing environments in {:?}" , summary. total) ;
168+ send_reply ( id, Some ( RefreshResult :: new ( summary. total ) ) ) ;
169169
170+ let perf = RefreshPerformance {
171+ total : summary. total . as_millis ( ) ,
172+ locators : summary
173+ . locators
174+ . clone ( )
175+ . iter ( )
176+ . map ( |( k, v) | ( k. to_string ( ) , v. as_millis ( ) ) )
177+ . collect :: < BTreeMap < String , u128 > > ( ) ,
178+ breakdown : summary
179+ . breakdown
180+ . clone ( )
181+ . iter ( )
182+ . map ( |( k, v) | ( k. to_string ( ) , v. as_millis ( ) ) )
183+ . collect :: < BTreeMap < String , u128 > > ( ) ,
184+ } ;
185+ reporter. report_telemetry ( & TelemetryEvent :: RefreshPerformance ( perf) ) ;
170186 // Find an report missing envs for the first launch of this process.
171187 if MISSING_ENVS_REPORTED
172188 . compare_exchange ( false , true , Ordering :: Acquire , Ordering :: Relaxed )
0 commit comments