mblt-tracker 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Mobilint, Inc.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,206 @@
1
+ Metadata-Version: 2.4
2
+ Name: mblt-tracker
3
+ Version: 0.0.1
4
+ Summary: A Python library to track device usage, such as Mobilint NPU, NVIDIA GPU, Intel CPU, ...
5
+ Author-email: "Mobilint Inc." <tech-support@mobilint.com>
6
+ License: BSD-3-Clause
7
+ Project-URL: Home, https://www.mobilint.com/
8
+ Project-URL: Repository, https://github.com/mobilint/mblt-tracker
9
+ Project-URL: Documentation, https://github.com/mobilint/mblt-tracker#readme
10
+ Project-URL: Issues, https://github.com/mobilint/mblt-tracker/issues
11
+ Keywords: python,energy,power,utilization,memory,energy-consumption,NPU,Mobilint,GPU,NVIDIA,CPU,Intel,monitoring
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Education
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Intended Audience :: System Administrators
18
+ Classifier: License :: OSI Approved :: BSD License
19
+ Classifier: Operating System :: Microsoft :: Windows
20
+ Classifier: Operating System :: POSIX :: Linux
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Topic :: Scientific/Engineering
27
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
28
+ Classifier: Topic :: Software Development
29
+ Classifier: Topic :: Software Development :: Libraries
30
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
31
+ Classifier: Topic :: System :: Monitoring
32
+ Requires-Python: <3.13,>=3.9
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE
35
+ Requires-Dist: numpy>=1.26.0
36
+ Requires-Dist: setuptools>=70.0.0
37
+ Requires-Dist: nvidia-ml-py>=12.560.30
38
+ Requires-Dist: apscheduler>=3.11.2
39
+ Requires-Dist: pyRAPL>=0.2.3.1
40
+ Requires-Dist: psutil>=7.0.0
41
+ Dynamic: license-file
42
+
43
+ # Mobilint Device Tracker
44
+
45
+ <!-- markdownlint-disable MD033 -->
46
+ <div align="center">
47
+ <p>
48
+ <a href="https://www.mobilint.com/" target="_blank">
49
+ <img src="https://raw.githubusercontent.com/mobilint/mblt-tracker/master/assets/Mobilint_Logo_Primary.png" alt="Mobilint Logo" width="60%">
50
+ </a>
51
+ </p>
52
+ <p>
53
+ <b>A lightweight Python library for tracking hardware metrics (Power, Utilization, Memory) across CPU, GPU, and NPU.</b>
54
+ </p>
55
+ </div>
56
+ <!-- markdownlint-enable MD033 -->
57
+
58
+ ## Overview
59
+
60
+ **mblt-tracker** is designed to help developers and researchers measure hardware performance with fair and consistent criteria. It provides a unified interface to poll metrics in the background while your code runs, producing both summarized statistics and detailed time-series traces.
61
+
62
+ ### ✨ Key Features
63
+
64
+ - **Multi-Backend Support**: Unified interface for Intel CPU, NVIDIA GPU, and Mobilint NPU.
65
+ - **Background Tracking**: Uses a background scheduler to poll metrics without blocking your main execution.
66
+ - **Comprehensive Metrics**: Capture Power (Watts), Utilization (%), and Memory Usage (MB/%).
67
+ - **Statistical Summaries**: Automatically calculates averages, peaks (max), and p99 values.
68
+ - **Time-Series Traces**: Export raw data for custom plotting and analysis.
69
+ - **Lightweight**: Minimal overhead, designed for production and research environments.
70
+
71
+ ---
72
+
73
+ ## 🚀 Installation
74
+
75
+ [![PyPI - Version](https://img.shields.io/pypi/v/mblt-tracker?logo=pypi&logoColor=white)](https://pypi.org/project/mblt-tracker/)
76
+ [![PyPI Downloads](https://static.pepy.tech/badge/mblt-tracker?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads)](https://clickpy.clickhouse.com/dashboard/mblt-tracker)
77
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mblt-tracker?logo=python&logoColor=gold)](https://pypi.org/project/mblt-tracker/)
78
+
79
+ ```bash
80
+ pip install mblt-tracker
81
+ ```
82
+
83
+ For the latest features, install directly from source:
84
+
85
+ ```bash
86
+ git clone https://github.com/mobilint/mblt-tracker.git
87
+ cd mblt-tracker
88
+ pip install -e .
89
+ ```
90
+
91
+ ---
92
+
93
+ ## 📖 Quick Start Guide
94
+
95
+ The typical workflow involves initializing a tracker, starting it before your target workload, and stopping it after.
96
+
97
+ ```python
98
+ from mblt_tracker import CPUDeviceTracker # or GPUDeviceTracker, NPUDeviceTracker
99
+
100
+ # 1. Initialize with a polling interval (seconds)
101
+ tracker = CPUDeviceTracker(interval=0.1)
102
+
103
+ # 2. Start tracking (best to run after warm-up)
104
+ tracker.start()
105
+
106
+ # --- Your workload starts here ---
107
+ # e.g., model.inference(data)
108
+ # --- Your workload ends here ---
109
+
110
+ # 3. Stop tracking
111
+ tracker.stop()
112
+
113
+ # 4. Access results
114
+ metrics = tracker.get_metric()
115
+ print(f"Average Power: {metrics['avg_power_w']:.2f} W")
116
+ print(f"Max Utilization: {metrics['max_utilization_pct']:.2f} %")
117
+
118
+ # 5. Export time-series trace (list of (timestamp, power_w))
119
+ trace = tracker.get_trace()
120
+ ```
121
+
122
+ ---
123
+
124
+ ## 📊 Metrics Coverage
125
+
126
+ | Metric | Intel CPU | NVIDIA GPU | Mobilint NPU |
127
+ | :--- | :---: | :---: | :---: |
128
+ | **Power (W)** | ✅ (RAPL) | ✅ (NVML) | ✅ (`mobilint-cli`) |
129
+ | **Utilization (%)** | ✅ (`psutil`) | ✅ (NVML) | ✅ (`mobilint-cli`) |
130
+ | **Memory (MB/%)** | ✅ (`psutil`) | ✅ (NVML) | ✅ (`mobilint-cli`) |
131
+ | **Per-Device Stats** | ✅ (Sockets) | ✅ (GPU Indices) | ❌ (Global/Total) |
132
+
133
+ ---
134
+
135
+ ## 🛠️ Hardware Specifics
136
+
137
+ ### Intel CPU
138
+
139
+ Uses **pyRAPL** for power measurements and **psutil** for utilization/memory.
140
+
141
+ - **Permission**: Requires read access to Intel RAPL sysfs.
142
+
143
+ ```bash
144
+ sudo chmod -R a+r /sys/class/powercap/intel-rapl/
145
+ ```
146
+
147
+ - **Docker**: Run containers with `--privileged` or mount the powercap directory.
148
+
149
+ - **Features**: Tracks total system CPU usage or specific indices (e.g., `CPUDeviceTracker(cpu_id=[0, 1])`).
150
+
151
+ ### NVIDIA GPU
152
+
153
+ Uses **NVML** (via `nvidia-ml-py`) for high-fidelity hardware monitoring.
154
+
155
+ - **Features**: Tracks total system GPU usage or specific indices (e.g., `GPUDeviceTracker(gpu_id=[0, 1])`).
156
+ - **Dependencies**: Requires NVIDIA Drivers and NVML library installed.
157
+
158
+ ### Mobilint NPU
159
+
160
+ Polls the `mobilint-cli status` command.
161
+
162
+ - **Platform**: Currently supports **Linux only**.
163
+ - **Requirement**: Ensure [Mobilint Utility Tool](https://docs.mobilint.com/v1.0/en/installing_utility.html) is installed and `mobilint-cli` is in your PATH.
164
+ - **NPU Power**: Distinguishes between NPU-specific power and total system power.
165
+
166
+ ---
167
+
168
+ ## 📝 Metric Output Format
169
+
170
+ Calling `get_metric()` returns a dictionary with the following standard keys (where applicable):
171
+
172
+ ```json
173
+ {
174
+ "avg_power_w": 25.4, // Average total power in Watts
175
+ "max_power_w": 45.2, // Peak power observed
176
+ "p99_power_w": 40.1, // 99th percentile power
177
+ "avg_utilization_pct": 78.5, // Average device utilization
178
+ "max_utilization_pct": 95.0, // Peak device utilization
179
+ "avg_memory_used_mb": 2048.0, // Average memory usage
180
+ "total_memory_mb": 8192.0, // Total available memory
181
+ "samples": 100 // Number of data points collected
182
+ }
183
+ ```
184
+
185
+ *Note: Some trackers provide additional keys like `cpu` or `gpu` for per-socket/per-device breakdown.*
186
+
187
+ ---
188
+
189
+ ## 🤝 Contributing
190
+
191
+ We welcome contributions! To set up for development:
192
+
193
+ 1. Install dev dependencies: `pip install -e ".[dev]"`
194
+ 2. Run tests: `pytest tests/`
195
+
196
+ ## 📄 License
197
+
198
+ This project is licensed under the **BSD-3-Clause License**. See the [LICENSE](https://github.com/mobilint/mblt-tracker/blob/master/LICENSE) file for details.
199
+
200
+ ---
201
+
202
+ <!-- markdownlint-disable MD033 -->
203
+ <div align="center">
204
+ <small>Developed with ❤️ by <a href="https://www.mobilint.com/">Mobilint Inc.</a></small>
205
+ </div>
206
+ <!-- markdownlint-enable MD033 -->
@@ -0,0 +1,164 @@
1
+ # Mobilint Device Tracker
2
+
3
+ <!-- markdownlint-disable MD033 -->
4
+ <div align="center">
5
+ <p>
6
+ <a href="https://www.mobilint.com/" target="_blank">
7
+ <img src="https://raw.githubusercontent.com/mobilint/mblt-tracker/master/assets/Mobilint_Logo_Primary.png" alt="Mobilint Logo" width="60%">
8
+ </a>
9
+ </p>
10
+ <p>
11
+ <b>A lightweight Python library for tracking hardware metrics (Power, Utilization, Memory) across CPU, GPU, and NPU.</b>
12
+ </p>
13
+ </div>
14
+ <!-- markdownlint-enable MD033 -->
15
+
16
+ ## Overview
17
+
18
+ **mblt-tracker** is designed to help developers and researchers measure hardware performance with fair and consistent criteria. It provides a unified interface to poll metrics in the background while your code runs, producing both summarized statistics and detailed time-series traces.
19
+
20
+ ### ✨ Key Features
21
+
22
+ - **Multi-Backend Support**: Unified interface for Intel CPU, NVIDIA GPU, and Mobilint NPU.
23
+ - **Background Tracking**: Uses a background scheduler to poll metrics without blocking your main execution.
24
+ - **Comprehensive Metrics**: Capture Power (Watts), Utilization (%), and Memory Usage (MB/%).
25
+ - **Statistical Summaries**: Automatically calculates averages, peaks (max), and p99 values.
26
+ - **Time-Series Traces**: Export raw data for custom plotting and analysis.
27
+ - **Lightweight**: Minimal overhead, designed for production and research environments.
28
+
29
+ ---
30
+
31
+ ## 🚀 Installation
32
+
33
+ [![PyPI - Version](https://img.shields.io/pypi/v/mblt-tracker?logo=pypi&logoColor=white)](https://pypi.org/project/mblt-tracker/)
34
+ [![PyPI Downloads](https://static.pepy.tech/badge/mblt-tracker?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads)](https://clickpy.clickhouse.com/dashboard/mblt-tracker)
35
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mblt-tracker?logo=python&logoColor=gold)](https://pypi.org/project/mblt-tracker/)
36
+
37
+ ```bash
38
+ pip install mblt-tracker
39
+ ```
40
+
41
+ For the latest features, install directly from source:
42
+
43
+ ```bash
44
+ git clone https://github.com/mobilint/mblt-tracker.git
45
+ cd mblt-tracker
46
+ pip install -e .
47
+ ```
48
+
49
+ ---
50
+
51
+ ## 📖 Quick Start Guide
52
+
53
+ The typical workflow involves initializing a tracker, starting it before your target workload, and stopping it after.
54
+
55
+ ```python
56
+ from mblt_tracker import CPUDeviceTracker # or GPUDeviceTracker, NPUDeviceTracker
57
+
58
+ # 1. Initialize with a polling interval (seconds)
59
+ tracker = CPUDeviceTracker(interval=0.1)
60
+
61
+ # 2. Start tracking (best to run after warm-up)
62
+ tracker.start()
63
+
64
+ # --- Your workload starts here ---
65
+ # e.g., model.inference(data)
66
+ # --- Your workload ends here ---
67
+
68
+ # 3. Stop tracking
69
+ tracker.stop()
70
+
71
+ # 4. Access results
72
+ metrics = tracker.get_metric()
73
+ print(f"Average Power: {metrics['avg_power_w']:.2f} W")
74
+ print(f"Max Utilization: {metrics['max_utilization_pct']:.2f} %")
75
+
76
+ # 5. Export time-series trace (list of (timestamp, power_w))
77
+ trace = tracker.get_trace()
78
+ ```
79
+
80
+ ---
81
+
82
+ ## 📊 Metrics Coverage
83
+
84
+ | Metric | Intel CPU | NVIDIA GPU | Mobilint NPU |
85
+ | :--- | :---: | :---: | :---: |
86
+ | **Power (W)** | ✅ (RAPL) | ✅ (NVML) | ✅ (`mobilint-cli`) |
87
+ | **Utilization (%)** | ✅ (`psutil`) | ✅ (NVML) | ✅ (`mobilint-cli`) |
88
+ | **Memory (MB/%)** | ✅ (`psutil`) | ✅ (NVML) | ✅ (`mobilint-cli`) |
89
+ | **Per-Device Stats** | ✅ (Sockets) | ✅ (GPU Indices) | ❌ (Global/Total) |
90
+
91
+ ---
92
+
93
+ ## 🛠️ Hardware Specifics
94
+
95
+ ### Intel CPU
96
+
97
+ Uses **pyRAPL** for power measurements and **psutil** for utilization/memory.
98
+
99
+ - **Permission**: Requires read access to Intel RAPL sysfs.
100
+
101
+ ```bash
102
+ sudo chmod -R a+r /sys/class/powercap/intel-rapl/
103
+ ```
104
+
105
+ - **Docker**: Run containers with `--privileged` or mount the powercap directory.
106
+
107
+ - **Features**: Tracks total system CPU usage or specific indices (e.g., `CPUDeviceTracker(cpu_id=[0, 1])`).
108
+
109
+ ### NVIDIA GPU
110
+
111
+ Uses **NVML** (via `nvidia-ml-py`) for high-fidelity hardware monitoring.
112
+
113
+ - **Features**: Tracks total system GPU usage or specific indices (e.g., `GPUDeviceTracker(gpu_id=[0, 1])`).
114
+ - **Dependencies**: Requires NVIDIA Drivers and NVML library installed.
115
+
116
+ ### Mobilint NPU
117
+
118
+ Polls the `mobilint-cli status` command.
119
+
120
+ - **Platform**: Currently supports **Linux only**.
121
+ - **Requirement**: Ensure [Mobilint Utility Tool](https://docs.mobilint.com/v1.0/en/installing_utility.html) is installed and `mobilint-cli` is in your PATH.
122
+ - **NPU Power**: Distinguishes between NPU-specific power and total system power.
123
+
124
+ ---
125
+
126
+ ## 📝 Metric Output Format
127
+
128
+ Calling `get_metric()` returns a dictionary with the following standard keys (where applicable):
129
+
130
+ ```json
131
+ {
132
+ "avg_power_w": 25.4, // Average total power in Watts
133
+ "max_power_w": 45.2, // Peak power observed
134
+ "p99_power_w": 40.1, // 99th percentile power
135
+ "avg_utilization_pct": 78.5, // Average device utilization
136
+ "max_utilization_pct": 95.0, // Peak device utilization
137
+ "avg_memory_used_mb": 2048.0, // Average memory usage
138
+ "total_memory_mb": 8192.0, // Total available memory
139
+ "samples": 100 // Number of data points collected
140
+ }
141
+ ```
142
+
143
+ *Note: Some trackers provide additional keys like `cpu` or `gpu` for per-socket/per-device breakdown.*
144
+
145
+ ---
146
+
147
+ ## 🤝 Contributing
148
+
149
+ We welcome contributions! To set up for development:
150
+
151
+ 1. Install dev dependencies: `pip install -e ".[dev]"`
152
+ 2. Run tests: `pytest tests/`
153
+
154
+ ## 📄 License
155
+
156
+ This project is licensed under the **BSD-3-Clause License**. See the [LICENSE](https://github.com/mobilint/mblt-tracker/blob/master/LICENSE) file for details.
157
+
158
+ ---
159
+
160
+ <!-- markdownlint-disable MD033 -->
161
+ <div align="center">
162
+ <small>Developed with ❤️ by <a href="https://www.mobilint.com/">Mobilint Inc.</a></small>
163
+ </div>
164
+ <!-- markdownlint-enable MD033 -->
@@ -0,0 +1,17 @@
1
+ """Mobilint Device Tracker package for monitoring CPU, GPU, and NPU metrics.
2
+
3
+ This package provides classes for tracking power usage, utilization, and memory
4
+ consumption across different hardware backends.
5
+ """
6
+
7
+ __version__ = "0.0.1"
8
+
9
+ from .device_tracker_cpu import CPUDeviceTracker
10
+ from .device_tracker_gpu import GPUDeviceTracker
11
+ from .device_tracker_npu import NPUDeviceTracker
12
+
13
+ __all__ = [
14
+ "CPUDeviceTracker",
15
+ "GPUDeviceTracker",
16
+ "NPUDeviceTracker",
17
+ ]
@@ -0,0 +1,84 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Optional
3
+
4
+ from apscheduler.schedulers.background import BackgroundScheduler
5
+ from apscheduler.schedulers.base import STATE_RUNNING
6
+
7
+
8
+ class BaseDeviceTracker(ABC):
9
+ """Abstract base class for device trackers."""
10
+
11
+ def __init__(self, interval: float, **kwargs):
12
+ """Initialize the device tracker.
13
+
14
+ Args:
15
+ interval (float): The interval in seconds at which the device should be polled.
16
+ **kwargs: Additional keyword arguments for parent classes.
17
+
18
+ Raises:
19
+ ValueError: If the interval is not positive.
20
+ """
21
+ super().__init__(**kwargs)
22
+ if interval <= 0:
23
+ raise ValueError("interval must be positive")
24
+ self._interval = interval
25
+ self._scheduler: Optional[BackgroundScheduler] = None
26
+ self._job_id: str = "device_track"
27
+
28
+ def start(self) -> None:
29
+ """Start tracking device metrics periodically."""
30
+ self.reset()
31
+ try:
32
+ self._func_for_sched()
33
+ except Exception:
34
+ pass
35
+ if self._scheduler is None or self._scheduler.state != STATE_RUNNING:
36
+ self._scheduler = BackgroundScheduler()
37
+ self._scheduler.start()
38
+
39
+ # Ensure _scheduler is not None for the linter
40
+ if self._scheduler is not None:
41
+ if self._scheduler.get_job(self._job_id) is not None:
42
+ self._scheduler.remove_job(self._job_id)
43
+ self._scheduler.add_job(
44
+ self._func_for_sched,
45
+ "interval",
46
+ seconds=self._interval,
47
+ id=self._job_id,
48
+ )
49
+
50
+ def stop(self) -> None:
51
+ """Stop tracking device metrics and shut down the scheduler."""
52
+ try:
53
+ self._func_for_sched()
54
+ except Exception:
55
+ pass
56
+ if self._scheduler is not None:
57
+ try:
58
+ self._scheduler.shutdown(wait=True)
59
+ finally:
60
+ self._scheduler = None
61
+
62
+ @abstractmethod
63
+ def _func_for_sched(self) -> None:
64
+ """Scheduled function to capture a single sample of metrics."""
65
+
66
+ @abstractmethod
67
+ def get_metric(self) -> dict:
68
+ """Return summarized device metrics since start or last reset.
69
+
70
+ Returns:
71
+ Dict: A dictionary containing averaged and peak metrics.
72
+ """
73
+
74
+ @abstractmethod
75
+ def get_trace(self) -> list[tuple[float, float]]:
76
+ """Return a time-series trace of power measurements.
77
+
78
+ Returns:
79
+ List[Tuple[float, float]]: A list of (timestamp, power_watt) pairs.
80
+ """
81
+
82
+ @abstractmethod
83
+ def reset(self) -> None:
84
+ """Clear all collected metrics and traces."""