/// Attach an inspect node to the DebugDataSet under |parent_node|.
Attach an inspect node to the DebugDataSet under |parent_node|.
Attach an inspect node to the DebugDataSet under |parent_node| .
pub fn with_inspect(self, parent_node: &Node, name: &str) -> Arc<Mutex<Self>> {
            let arc_self = Arc::new(Mutex::new(self));
            let weak_self = Arc::downgrade(&arc_self);
            let lazy_node_fn = move || {
                let weak_clone = weak_self.clone();
                async move {
                    let inspector = fuchsia_inspect::Inspector::new();
                    let root = inspector.root();
                    if let Some(this_mutex) = weak_clone.upgrade() {
                        let this_lock = this_mutex.lock().await;
                        let this = &*this_lock;
                        root.record_child("realms", |realm_node| {
                            for (realm, url) in this.realms.iter() {
                                realm_node.record_string(realm.as_str(), &url);
                            }
                        });
                        root.record_int(
                            "num_running_components",
                            this.running_components.len() as i64,
                        );
                        let running_components = root.create_string_array(
                            "running_components",
                            std::cmp::min(
                                this.running_components.len(),
                                Self::MAX_INSPECT_ARRAY_SIZE,
                            ),
                        );
                        for (idx, cmp) in this
                            .running_components
                            .iter()
                            .take(Self::MAX_INSPECT_ARRAY_SIZE)
                            .enumerate()
                        {
                            running_components.set(idx, format!("{}", cmp))
                        }
                        root.record(running_components);
                        root.record_int(
                            "num_destroyed_before_start",
                            this.destroyed_before_start.len() as i64,
                        );
                        let destroyed_before_start = root.create_string_array(
                            "destroyed_before_start",
                            std::cmp::min(
                                this.destroyed_before_start.len(),
                                Self::MAX_INSPECT_ARRAY_SIZE,
                            ),
                        );
                        for (idx, cmp) in this
                            .destroyed_before_start
                            .iter()
                            .take(Self::MAX_INSPECT_ARRAY_SIZE)
                            .enumerate()
                        {
                            destroyed_before_start.set(idx, format!("{}", cmp))
                        }
                        root.record(destroyed_before_start);
                        root.record_int("num_seen_realms", this.seen_realms.len() as i64);
                        let seen_realms = root.create_string_array(
                            "seen_realms",
                            std::cmp::min(this.seen_realms.len(), Self::MAX_INSPECT_ARRAY_SIZE),
                        );
                        for (idx, cmp) in
                            this.seen_realms.iter().take(Self::MAX_INSPECT_ARRAY_SIZE).enumerate()
                        {
                            seen_realms.set(idx, format!("{}", cmp))
                        }
                        root.record(seen_realms);
                        root.record_bool("done_adding_realms", this.done_adding_realms);
                    }
                    Ok(inspector)
                }
                .boxed()
            };
            // Lock can't fail since we created the mutex above and control all the handles.
            arc_self
                .try_lock()
                .unwrap()
                .inspect_node
                .replace(parent_node.create_lazy_child(name, lazy_node_fn));
            arc_self
        }
pub fn with_inspect ( self , parent_node : & Node , name : & str ) -> Arc < Mutex < Self > > { let arc_self = Arc :: new ( Mutex :: new ( self ) ) ; let weak_self = Arc :: downgrade ( & arc_self ) ; let lazy_node_fn = move | | { let weak_clone = weak_self . clone ( ) ; async move { let inspector = fuchsia_inspect :: Inspector :: new ( ) ; let root = inspector . root ( ) ; if let Some ( this_mutex ) = weak_clone . upgrade ( ) { let this_lock = this_mutex . lock ( ) . await ; let this = & * this_lock ; root . record_child ( " " , | realm_node | { for ( realm , url ) in this . realms . iter ( ) { realm_node . record_string ( realm . as_str ( ) , & url ) ; } } ) ; root . record_int ( " " , this . running_components . len ( ) as i64 , ) ; let running_components = root . create_string_array ( " " , std :: cmp :: min ( this . running_components . len ( ) , Self :: MAX_INSPECT_ARRAY_SIZE , ) , ) ; for ( idx , cmp ) in this . running_components . iter ( ) . take ( Self :: MAX_INSPECT_ARRAY_SIZE ) . enumerate ( ) { running_components . set ( idx , format ! ( " " cmp ) ) } root . record ( running_components ) ; root . record_int ( " " , this . destroyed_before_start . len ( ) as i64 , ) ; let destroyed_before_start = root . create_string_array ( " " , std :: cmp :: min ( this . destroyed_before_start . len ( ) , Self :: MAX_INSPECT_ARRAY_SIZE , ) , ) ; for ( idx , cmp ) in this . destroyed_before_start . iter ( ) . take ( Self :: MAX_INSPECT_ARRAY_SIZE ) . enumerate ( ) { destroyed_before_start . set ( idx , format ! ( " " cmp ) ) } root . record ( destroyed_before_start ) ; root . record_int ( " " , this . seen_realms . len ( ) as i64 ) ; let seen_realms = root . create_string_array ( " " , std :: cmp :: min ( this . seen_realms . len ( ) , Self :: MAX_INSPECT_ARRAY_SIZE ) , ) ; for ( idx , cmp ) in this . seen_realms . iter ( ) . take ( Self :: MAX_INSPECT_ARRAY_SIZE ) . enumerate ( ) { seen_realms . set ( idx , format ! ( " " cmp ) ) } root . record ( seen_realms ) ; root . record_bool ( " " , this . done_adding_realms ) ; } Ok ( inspector ) } . boxed ( ) } ; // Lock can't fail since we created the mutex above and control all the handles. arc_self . try_lock ( ) . unwrap ( ) . inspect_node . replace ( parent_node . create_lazy_child ( name , lazy_node_fn ) ) ; arc_self }
Attach an inspect node to the DebugDataSet under |parent_node|.
Attach an inspect node to the DebugDataSet under |parent_node| .
self
parent_node
&Node
name
&str