|
6 | 6 |
|
7 | 7 | ## Overview |
8 | 8 |
|
9 | | -`metrit` is a Python package designed to simplify the process of measuring the execution resources of your functions through a straightforward decorator. |
| 9 | +`metrit` is a Python package designed to simplify the process of measuring the execution resources of your functions through a straightforward decorator. `metrit` decorator is a powerful tool for detailed performance analysis of Python functions, offering insights into resource utilization and potential bottlenecks. Its robust handling of process isolation and monitoring ensures accurate measurements, even for complex functions that involve multiple processes. |
10 | 10 |
|
11 | 11 | ## Installation |
12 | 12 |
|
@@ -214,6 +214,42 @@ If an error occurs while executing the decorated function in non-isolated mode o |
214 | 214 |
|
215 | 215 | - Deprecation warnings will be added before removing a feature. |
216 | 216 |
|
| 217 | +## How metrit works |
| 218 | + |
| 219 | +Here's a detailed explanation of how `metrit` operates: |
| 220 | + |
| 221 | +1. Function Process Execution: |
| 222 | + |
| 223 | + - The decorated function is initially executed in a separate process if `isolate = True`, referred to as the function process. |
| 224 | + - If this process crashes, the function will be executed in the main process. |
| 225 | + |
| 226 | +2. Monitor Process Setup: |
| 227 | + |
| 228 | + - Before starting the function process, another process, called the monitor process, is created to monitor the resources of the function process. |
| 229 | + - The monitor process takes an initial snapshot of the resources in the function process to use as a baseline. |
| 230 | + |
| 231 | +3. Resource Monitoring: |
| 232 | + |
| 233 | + - The monitor process continuously checks the resources of the function process, starting with an interval of 0.1 seconds, which can scale up to 5 seconds for longer-running functions. |
| 234 | + - This adaptive refresh rate minimizes the monitoring overhead for time-consuming functions. |
| 235 | + |
| 236 | +4. Completion and Data Collection: |
| 237 | + |
| 238 | + - Upon the function process completion, a signal is sent to the monitor process to stop monitoring. |
| 239 | + - The data collected by the monitor process is adjusted by subtracting the initial snapshot to ensure precision. |
| 240 | + - The final values are then printed. |
| 241 | + |
| 242 | +5. Handling Failures and Parameters: |
| 243 | + |
| 244 | + - If the function process fails, or if the `isolate` parameter is set to `False`, the function will execute in the main process while the monitor process continues its monitoring. |
| 245 | + - The recursion checker for isolated functions uses queues to communicate the function call stack. |
| 246 | + - Methods are not isolated and will always run in the main process, as if `isolate` is `False`. |
| 247 | + |
| 248 | +6. Child Process Monitoring: |
| 249 | + |
| 250 | + - When `find_children` is set to `True`, the library measures all processes spawned by the function process. |
| 251 | + - This feature is useful for nested functions or functions that spawn additional processes. |
| 252 | + |
217 | 253 | ## Contributing |
218 | 254 |
|
219 | 255 | Contributions are welcome! Please follow these guidelines when contributing: |
|
0 commit comments