fn from_directories_internal(
        minimum_sample_rate_sec: i64,
        sampler_dir: impl AsRef<Path>,
        fire_dir: Option<impl AsRef<Path>>,
    ) -> Result<Self, Error> {
        // TODO(fxbug.dev/88640): Remove legacy_sampler_config_paths when
        // all config dirs use sampler_dir/foo/*.json
        let legacy_sampler_config_paths = paths_matching_name(&sampler_dir, "*.json")?;
        let sampler_config_paths = paths_matching_name(&sampler_dir, "*/*.json")?;
        let mut project_configs = load_many(sampler_config_paths)?;
        project_configs.append(&mut load_many(legacy_sampler_config_paths)?);
        if let Some(fire_dir) = fire_dir {
            let fire_project_paths = paths_matching_name(&fire_dir, "*/projects/*.json5")?;
            let fire_component_paths = paths_matching_name(&fire_dir, "*/components.json5")?;
            let fire_project_templates = load_many(fire_project_paths)?;
            let fire_components = load_many::<ComponentIdInfoList>(fire_component_paths)?;
            let fire_components =
                fire_components.into_iter().flatten().collect::<Vec<ComponentIdInfo>>();
            project_configs
                .append(&mut expand_fire_projects(fire_project_templates, fire_components)?);
        }
        // The upload_count properties should outlive the selector they're stored in, since
        // selectors for upload_once Metrics are deleted after upload.
        lazy_static::lazy_static! {
            static ref UPLOAD_COUNTS: Mutex<Vec<Arc<inspect::UintProperty>>> = Mutex::new(vec![]);
            static ref SELECTOR_STRING : inspect::StringReference<'static> = "selector".into();
            static ref UPLOAD_COUNT_STRING : inspect::StringReference<'static> = "upload_count".into();
        }
        inspect::component::inspector().root().record_child("metrics_sent", |top_node| {
            for config in project_configs.iter_mut() {
                let mut next_selector_index = 0;
                // "<unknown>" should never happen, so it's better not to make it StringReference.
                let source_name = config.source_name.clone();
                top_node.record_child(source_name, |file_node| {
                    for metric in config.metrics.iter_mut() {
                        for selector in metric.selectors.iter_mut() {
                            if let Some(ref mut selector) = selector {
                                file_node.record_child(
                                    format!("{}", next_selector_index),
                                    |selector_node| {
                                        next_selector_index += 1;
                                        selector_node.record_string(
                                            &*SELECTOR_STRING,
                                            selector.selector_string.clone(),
                                        );
                                        let upload_count = Arc::new(
                                            selector_node.create_uint(&*UPLOAD_COUNT_STRING, 0),
                                        );
                                        selector.upload_count = upload_count.clone();
                                        UPLOAD_COUNTS.lock().push(upload_count);
                                    },
                                );
                            }
                        }
                    }
                });
            }
        });
        Ok(Self { minimum_sample_rate_sec, project_configs })
    }
// Parse the ProjectConfigurations for every project from config data.
// If a FIRE directory is given, load FIRE data and convert it to ProjectConfig's.
Parse the ProjectConfigurations for every project from config data.
If a FIRE directory is given, load FIRE data and convert it to ProjectConfig's.
Parse the ProjectConfigurations for every project from config data . If a FIRE directory is given load FIRE data and convert it to ProjectConfig ' s .
fn from_directories_internal(
        minimum_sample_rate_sec: i64,
        sampler_dir: impl AsRef<Path>,
        fire_dir: Option<impl AsRef<Path>>,
    ) -> Result<Self, Error> {
        // TODO(fxbug.dev/88640): Remove legacy_sampler_config_paths when
        // all config dirs use sampler_dir/foo/*.json
        let legacy_sampler_config_paths = paths_matching_name(&sampler_dir, "*.json")?;
        let sampler_config_paths = paths_matching_name(&sampler_dir, "*/*.json")?;
        let mut project_configs = load_many(sampler_config_paths)?;
        project_configs.append(&mut load_many(legacy_sampler_config_paths)?);
        if let Some(fire_dir) = fire_dir {
            let fire_project_paths = paths_matching_name(&fire_dir, "*/projects/*.json5")?;
            let fire_component_paths = paths_matching_name(&fire_dir, "*/components.json5")?;
            let fire_project_templates = load_many(fire_project_paths)?;
            let fire_components = load_many::<ComponentIdInfoList>(fire_component_paths)?;
            let fire_components =
                fire_components.into_iter().flatten().collect::<Vec<ComponentIdInfo>>();
            project_configs
                .append(&mut expand_fire_projects(fire_project_templates, fire_components)?);
        }
        // The upload_count properties should outlive the selector they're stored in, since
        // selectors for upload_once Metrics are deleted after upload.
        lazy_static::lazy_static! {
            static ref UPLOAD_COUNTS: Mutex<Vec<Arc<inspect::UintProperty>>> = Mutex::new(vec![]);
            static ref SELECTOR_STRING : inspect::StringReference<'static> = "selector".into();
            static ref UPLOAD_COUNT_STRING : inspect::StringReference<'static> = "upload_count".into();
        }
        inspect::component::inspector().root().record_child("metrics_sent", |top_node| {
            for config in project_configs.iter_mut() {
                let mut next_selector_index = 0;
                // "<unknown>" should never happen, so it's better not to make it StringReference.
                let source_name = config.source_name.clone();
                top_node.record_child(source_name, |file_node| {
                    for metric in config.metrics.iter_mut() {
                        for selector in metric.selectors.iter_mut() {
                            if let Some(ref mut selector) = selector {
                                file_node.record_child(
                                    format!("{}", next_selector_index),
                                    |selector_node| {
                                        next_selector_index += 1;
                                        selector_node.record_string(
                                            &*SELECTOR_STRING,
                                            selector.selector_string.clone(),
                                        );
                                        let upload_count = Arc::new(
                                            selector_node.create_uint(&*UPLOAD_COUNT_STRING, 0),
                                        );
                                        selector.upload_count = upload_count.clone();
                                        UPLOAD_COUNTS.lock().push(upload_count);
                                    },
                                );
                            }
                        }
                    }
                });
            }
        });
        Ok(Self { minimum_sample_rate_sec, project_configs })
    }
fn from_directories_internal ( minimum_sample_rate_sec : i64 , sampler_dir : impl AsRef < Path > , fire_dir : Option < impl AsRef < Path > > , ) -> Result < Self , Error > { // TODO(fxbug.dev/88640): Remove legacy_sampler_config_paths when // all config dirs use sampler_dir/foo/*.json let legacy_sampler_config_paths = paths_matching_name ( & sampler_dir , " " ) ? ; let sampler_config_paths = paths_matching_name ( & sampler_dir , " " ) ? ; let mut project_configs = load_many ( sampler_config_paths ) ? ; project_configs . append ( & mut load_many ( legacy_sampler_config_paths ) ? ) ; if let Some ( fire_dir ) = fire_dir { let fire_project_paths = paths_matching_name ( & fire_dir , " " ) ? ; let fire_component_paths = paths_matching_name ( & fire_dir , " " ) ? ; let fire_project_templates = load_many ( fire_project_paths ) ? ; let fire_components = load_many :: < ComponentIdInfoList > ( fire_component_paths ) ? ; let fire_components = fire_components . into_iter ( ) . flatten ( ) . collect :: < Vec < ComponentIdInfo > > ( ) ; project_configs . append ( & mut expand_fire_projects ( fire_project_templates , fire_components ) ? ) ; } // The upload_count properties should outlive the selector they're stored in, since // selectors for upload_once Metrics are deleted after upload. lazy_static :: lazy_static ! { static ref UPLOAD_COUNTS Mutex Vec Arc inspect UintProperty Mutex new ( vec [ ] ) static ref SELECTOR_STRING inspect StringReference ' static " " into ( ) static ref UPLOAD_COUNT_STRING inspect StringReference ' static " " into ( ) } inspect :: component :: inspector ( ) . root ( ) . record_child ( " " , | top_node | { for config in project_configs . iter_mut ( ) { let mut next_selector_index = 0 ; // "<unknown>" should never happen, so it's better not to make it StringReference. let source_name = config . source_name . clone ( ) ; top_node . record_child ( source_name , | file_node | { for metric in config . metrics . iter_mut ( ) { for selector in metric . selectors . iter_mut ( ) { if let Some ( ref mut selector ) = selector { file_node . record_child ( format ! ( " " next_selector_index ) , | selector_node | { next_selector_index += 1 ; selector_node . record_string ( & * SELECTOR_STRING , selector . selector_string . clone ( ) , ) ; let upload_count = Arc :: new ( selector_node . create_uint ( & * UPLOAD_COUNT_STRING , 0 ) , ) ; selector . upload_count = upload_count . clone ( ) ; UPLOAD_COUNTS . lock ( ) . push ( upload_count ) ; } , ) ; } } } } ) ; } } ) ; Ok ( Self { minimum_sample_rate_sec , project_configs } ) }
Parse the ProjectConfigurations for every project from config data.
Parse the ProjectConfigurations for every project from config data .
minimum_sample_rate_sec
i64
sampler_dir
impl AsRef<Path>
fire_dir
Option<impl AsRef<Path>>
minimum_sample_rate_sec
i64
sampler_dir
impl AsRef<Path>
fire_dir
Option<impl AsRef<Path>>