namespace.rs 1.05 KB
Newer Older
1
// SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Ryan Olson's avatar
Ryan Olson committed
2
3
// SPDX-License-Identifier: Apache-2.0

4
use crate::component::Namespace;
5
use crate::metrics::{MetricsHierarchy, MetricsRegistry};
6

7
impl MetricsHierarchy for Namespace {
8
9
10
11
    fn basename(&self) -> String {
        self.name.clone()
    }

12
13
    fn parent_hierarchies(&self) -> Vec<&dyn MetricsHierarchy> {
        let mut parents = vec![];
14

15
16
17
        // Walk up the namespace parent chain (grandparents to immediate parent)
        let parent_chain: Vec<&Namespace> =
            std::iter::successors(self.parent.as_deref(), |ns| ns.parent.as_deref()).collect();
18

19
20
21
22
23
24
25
26
27
28
29
30
31
        // Add DRT first (root)
        parents.push(&*self.runtime as &dyn MetricsHierarchy);

        // Then add parent namespaces in reverse order (root -> leaf)
        for parent_ns in parent_chain.iter().rev() {
            parents.push(*parent_ns as &dyn MetricsHierarchy);
        }

        parents
    }

    fn get_metrics_registry(&self) -> &MetricsRegistry {
        &self.metrics_registry
32
    }
33
}