exonware-xwlazy 0.1.0.23__py3-none-any.whl → 1.0.1.2__py3-none-any.whl
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.
- exonware/__init__.py +85 -34
- exonware/xwlazy/version.py +5 -5
- exonware/xwlazy.py +2546 -0
- exonware/xwlazy_external_libs.toml +716 -0
- {exonware_xwlazy-0.1.0.23.dist-info → exonware_xwlazy-1.0.1.2.dist-info}/METADATA +5 -1
- exonware_xwlazy-1.0.1.2.dist-info/RECORD +8 -0
- exonware/xwlazy/__init__.py +0 -379
- exonware/xwlazy/common/__init__.py +0 -55
- exonware/xwlazy/common/base.py +0 -65
- exonware/xwlazy/common/cache.py +0 -504
- exonware/xwlazy/common/logger.py +0 -257
- exonware/xwlazy/common/services/__init__.py +0 -72
- exonware/xwlazy/common/services/dependency_mapper.py +0 -250
- exonware/xwlazy/common/services/install_async_utils.py +0 -170
- exonware/xwlazy/common/services/install_cache_utils.py +0 -245
- exonware/xwlazy/common/services/keyword_detection.py +0 -283
- exonware/xwlazy/common/services/spec_cache.py +0 -165
- exonware/xwlazy/common/services/state_manager.py +0 -84
- exonware/xwlazy/common/strategies/__init__.py +0 -28
- exonware/xwlazy/common/strategies/caching_dict.py +0 -44
- exonware/xwlazy/common/strategies/caching_installation.py +0 -88
- exonware/xwlazy/common/strategies/caching_lfu.py +0 -66
- exonware/xwlazy/common/strategies/caching_lru.py +0 -63
- exonware/xwlazy/common/strategies/caching_multitier.py +0 -59
- exonware/xwlazy/common/strategies/caching_ttl.py +0 -59
- exonware/xwlazy/common/utils.py +0 -142
- exonware/xwlazy/config.py +0 -193
- exonware/xwlazy/contracts.py +0 -1533
- exonware/xwlazy/defs.py +0 -378
- exonware/xwlazy/errors.py +0 -276
- exonware/xwlazy/facade.py +0 -1137
- exonware/xwlazy/host/__init__.py +0 -8
- exonware/xwlazy/host/conf.py +0 -16
- exonware/xwlazy/module/__init__.py +0 -18
- exonware/xwlazy/module/base.py +0 -622
- exonware/xwlazy/module/data.py +0 -17
- exonware/xwlazy/module/facade.py +0 -246
- exonware/xwlazy/module/importer_engine.py +0 -2964
- exonware/xwlazy/module/partial_module_detector.py +0 -275
- exonware/xwlazy/module/strategies/__init__.py +0 -22
- exonware/xwlazy/module/strategies/module_helper_lazy.py +0 -93
- exonware/xwlazy/module/strategies/module_helper_simple.py +0 -65
- exonware/xwlazy/module/strategies/module_manager_advanced.py +0 -111
- exonware/xwlazy/module/strategies/module_manager_simple.py +0 -95
- exonware/xwlazy/package/__init__.py +0 -18
- exonware/xwlazy/package/base.py +0 -863
- exonware/xwlazy/package/conf.py +0 -324
- exonware/xwlazy/package/data.py +0 -17
- exonware/xwlazy/package/facade.py +0 -480
- exonware/xwlazy/package/services/__init__.py +0 -84
- exonware/xwlazy/package/services/async_install_handle.py +0 -87
- exonware/xwlazy/package/services/config_manager.py +0 -249
- exonware/xwlazy/package/services/discovery.py +0 -435
- exonware/xwlazy/package/services/host_packages.py +0 -180
- exonware/xwlazy/package/services/install_async.py +0 -291
- exonware/xwlazy/package/services/install_cache.py +0 -145
- exonware/xwlazy/package/services/install_interactive.py +0 -59
- exonware/xwlazy/package/services/install_policy.py +0 -156
- exonware/xwlazy/package/services/install_registry.py +0 -54
- exonware/xwlazy/package/services/install_result.py +0 -17
- exonware/xwlazy/package/services/install_sbom.py +0 -153
- exonware/xwlazy/package/services/install_utils.py +0 -79
- exonware/xwlazy/package/services/installer_engine.py +0 -406
- exonware/xwlazy/package/services/lazy_installer.py +0 -803
- exonware/xwlazy/package/services/manifest.py +0 -503
- exonware/xwlazy/package/services/strategy_registry.py +0 -324
- exonware/xwlazy/package/strategies/__init__.py +0 -57
- exonware/xwlazy/package/strategies/package_discovery_file.py +0 -129
- exonware/xwlazy/package/strategies/package_discovery_hybrid.py +0 -84
- exonware/xwlazy/package/strategies/package_discovery_manifest.py +0 -101
- exonware/xwlazy/package/strategies/package_execution_async.py +0 -113
- exonware/xwlazy/package/strategies/package_execution_cached.py +0 -90
- exonware/xwlazy/package/strategies/package_execution_pip.py +0 -99
- exonware/xwlazy/package/strategies/package_execution_wheel.py +0 -106
- exonware/xwlazy/package/strategies/package_mapping_discovery_first.py +0 -100
- exonware/xwlazy/package/strategies/package_mapping_hybrid.py +0 -105
- exonware/xwlazy/package/strategies/package_mapping_manifest_first.py +0 -100
- exonware/xwlazy/package/strategies/package_policy_allow_list.py +0 -57
- exonware/xwlazy/package/strategies/package_policy_deny_list.py +0 -57
- exonware/xwlazy/package/strategies/package_policy_permissive.py +0 -46
- exonware/xwlazy/package/strategies/package_timing_clean.py +0 -67
- exonware/xwlazy/package/strategies/package_timing_full.py +0 -66
- exonware/xwlazy/package/strategies/package_timing_smart.py +0 -68
- exonware/xwlazy/package/strategies/package_timing_temporary.py +0 -66
- exonware/xwlazy/runtime/__init__.py +0 -18
- exonware/xwlazy/runtime/adaptive_learner.py +0 -129
- exonware/xwlazy/runtime/base.py +0 -274
- exonware/xwlazy/runtime/facade.py +0 -94
- exonware/xwlazy/runtime/intelligent_selector.py +0 -170
- exonware/xwlazy/runtime/metrics.py +0 -60
- exonware/xwlazy/runtime/performance.py +0 -37
- exonware_xwlazy-0.1.0.23.dist-info/RECORD +0 -93
- xwlazy/__init__.py +0 -14
- xwlazy/lazy.py +0 -30
- {exonware_xwlazy-0.1.0.23.dist-info → exonware_xwlazy-1.0.1.2.dist-info}/WHEEL +0 -0
- {exonware_xwlazy-0.1.0.23.dist-info → exonware_xwlazy-1.0.1.2.dist-info}/licenses/LICENSE +0 -0
exonware/xwlazy/runtime/base.py
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
#exonware/xwlazy/src/exonware/xwlazy/runtime/base.py
|
|
3
|
-
|
|
4
|
-
Company: eXonware.com
|
|
5
|
-
Author: Eng. Muhammad AlShehri
|
|
6
|
-
Email: connect@exonware.com
|
|
7
|
-
|
|
8
|
-
Generation Date: 10-Oct-2025
|
|
9
|
-
|
|
10
|
-
Abstract Base Class for Runtime Services
|
|
11
|
-
|
|
12
|
-
This module defines the abstract base class for runtime services.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
import threading
|
|
16
|
-
from abc import ABC, abstractmethod
|
|
17
|
-
from typing import Optional, Any
|
|
18
|
-
|
|
19
|
-
from ..contracts import (
|
|
20
|
-
IRuntime,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
# =============================================================================
|
|
24
|
-
# ABSTRACT RUNTIME (Unified - Merges all runtime services)
|
|
25
|
-
# =============================================================================
|
|
26
|
-
|
|
27
|
-
class ARuntimeHelper(IRuntime, ABC):
|
|
28
|
-
"""
|
|
29
|
-
Unified abstract base for runtime services.
|
|
30
|
-
|
|
31
|
-
Merges functionality from all runtime service interfaces.
|
|
32
|
-
Provides runtime services for state management, learning, monitoring, and caching.
|
|
33
|
-
|
|
34
|
-
This abstract class combines:
|
|
35
|
-
- State management (persistent state for lazy installation)
|
|
36
|
-
- Adaptive learning (learning import patterns and optimizing loading)
|
|
37
|
-
- Intelligent selection (selecting optimal modes based on load characteristics)
|
|
38
|
-
- Metrics collection (collecting and aggregating performance metrics)
|
|
39
|
-
- Performance monitoring (monitoring lazy loading performance)
|
|
40
|
-
- Multi-tier caching (L1/L2/L3 caching)
|
|
41
|
-
- Registry (managing instances by key)
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
__slots__ = (
|
|
45
|
-
# From IStateManager
|
|
46
|
-
'_manual_state', '_auto_state',
|
|
47
|
-
# From IMetricsCollector
|
|
48
|
-
'_metrics',
|
|
49
|
-
# From IPerformanceMonitor
|
|
50
|
-
'_load_times', '_access_counts',
|
|
51
|
-
# From IMultiTierCache
|
|
52
|
-
'_l1_cache', '_l2_cache', '_l3_cache',
|
|
53
|
-
# From IRegistry
|
|
54
|
-
'_registry',
|
|
55
|
-
# Common
|
|
56
|
-
'_lock'
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
def __init__(self):
|
|
60
|
-
"""Initialize unified runtime services."""
|
|
61
|
-
# From IStateManager
|
|
62
|
-
self._manual_state: Optional[bool] = None
|
|
63
|
-
self._auto_state: Optional[bool] = None
|
|
64
|
-
|
|
65
|
-
# From IMetricsCollector
|
|
66
|
-
self._metrics: dict[str, list[float]] = {}
|
|
67
|
-
|
|
68
|
-
# From IPerformanceMonitor
|
|
69
|
-
self._load_times: dict[str, list[float]] = {}
|
|
70
|
-
self._access_counts: dict[str, int] = {}
|
|
71
|
-
|
|
72
|
-
# From IMultiTierCache
|
|
73
|
-
self._l1_cache: dict[str, Any] = {}
|
|
74
|
-
self._l2_cache: dict[str, Any] = {}
|
|
75
|
-
self._l3_cache: dict[str, Any] = {}
|
|
76
|
-
|
|
77
|
-
# From IRegistry
|
|
78
|
-
self._registry: dict[str, Any] = {}
|
|
79
|
-
|
|
80
|
-
# Common
|
|
81
|
-
self._lock = threading.RLock()
|
|
82
|
-
|
|
83
|
-
# ========================================================================
|
|
84
|
-
# State Management Methods (from IStateManager)
|
|
85
|
-
# ========================================================================
|
|
86
|
-
|
|
87
|
-
def get_manual_state(self) -> Optional[bool]:
|
|
88
|
-
"""Get manual state override (from IStateManager)."""
|
|
89
|
-
return self._manual_state
|
|
90
|
-
|
|
91
|
-
def set_manual_state(self, value: Optional[bool]) -> None:
|
|
92
|
-
"""Set manual state override (from IStateManager)."""
|
|
93
|
-
with self._lock:
|
|
94
|
-
self._manual_state = value
|
|
95
|
-
|
|
96
|
-
def get_cached_auto_state(self) -> Optional[bool]:
|
|
97
|
-
"""Get cached auto-detected state (from IStateManager)."""
|
|
98
|
-
return self._auto_state
|
|
99
|
-
|
|
100
|
-
def set_auto_state(self, value: Optional[bool]) -> None:
|
|
101
|
-
"""Set cached auto-detected state (from IStateManager)."""
|
|
102
|
-
with self._lock:
|
|
103
|
-
self._auto_state = value
|
|
104
|
-
|
|
105
|
-
# ========================================================================
|
|
106
|
-
# Adaptive Learning Methods (from IAdaptiveLearner)
|
|
107
|
-
# ========================================================================
|
|
108
|
-
|
|
109
|
-
@abstractmethod
|
|
110
|
-
def record_import(self, module_name: str, import_time: float) -> None:
|
|
111
|
-
"""Record an import event (from IAdaptiveLearner)."""
|
|
112
|
-
pass
|
|
113
|
-
|
|
114
|
-
@abstractmethod
|
|
115
|
-
def predict_next_imports(self, current_module: str, count: int = 3) -> list[str]:
|
|
116
|
-
"""Predict next likely imports based on patterns (from IAdaptiveLearner)."""
|
|
117
|
-
pass
|
|
118
|
-
|
|
119
|
-
@abstractmethod
|
|
120
|
-
def get_module_score(self, module_name: str) -> float:
|
|
121
|
-
"""Get priority score for a module (from IAdaptiveLearner)."""
|
|
122
|
-
pass
|
|
123
|
-
|
|
124
|
-
# ========================================================================
|
|
125
|
-
# Intelligent Selection Methods (from IIntelligentSelector)
|
|
126
|
-
# ========================================================================
|
|
127
|
-
|
|
128
|
-
@abstractmethod
|
|
129
|
-
def detect_load_level(
|
|
130
|
-
self,
|
|
131
|
-
module_count: int = 0,
|
|
132
|
-
total_import_time: float = 0.0,
|
|
133
|
-
import_count: int = 0,
|
|
134
|
-
memory_usage_mb: float = 0.0
|
|
135
|
-
) -> Any:
|
|
136
|
-
"""Detect current load level (from IIntelligentSelector)."""
|
|
137
|
-
pass
|
|
138
|
-
|
|
139
|
-
@abstractmethod
|
|
140
|
-
def get_optimal_mode(self, load_level: Any) -> tuple[Any, Any]:
|
|
141
|
-
"""Get optimal mode for a load level (from IIntelligentSelector)."""
|
|
142
|
-
pass
|
|
143
|
-
|
|
144
|
-
@abstractmethod
|
|
145
|
-
def update_mode_map(self, mode_map: dict[Any, tuple[Any, Any]]) -> None:
|
|
146
|
-
"""Update mode mapping with benchmark results (from IIntelligentSelector)."""
|
|
147
|
-
pass
|
|
148
|
-
|
|
149
|
-
# ========================================================================
|
|
150
|
-
# Metrics Collection Methods (from IMetricsCollector)
|
|
151
|
-
# ========================================================================
|
|
152
|
-
|
|
153
|
-
def record_metric(self, name: str, value: float, timestamp: Optional[Any] = None) -> None:
|
|
154
|
-
"""Record a metric value (from IMetricsCollector)."""
|
|
155
|
-
with self._lock:
|
|
156
|
-
if name not in self._metrics:
|
|
157
|
-
self._metrics[name] = []
|
|
158
|
-
self._metrics[name].append(value)
|
|
159
|
-
|
|
160
|
-
@abstractmethod
|
|
161
|
-
def get_metric_stats(self, name: str) -> dict[str, Any]:
|
|
162
|
-
"""Get statistics for a metric (from IMetricsCollector)."""
|
|
163
|
-
pass
|
|
164
|
-
|
|
165
|
-
@abstractmethod
|
|
166
|
-
def get_all_stats(self) -> dict[str, dict[str, Any]]:
|
|
167
|
-
"""Get statistics for all metrics (from IMetricsCollector)."""
|
|
168
|
-
pass
|
|
169
|
-
|
|
170
|
-
def clear_metrics(self) -> None:
|
|
171
|
-
"""Clear all collected metrics (from IMetricsCollector)."""
|
|
172
|
-
with self._lock:
|
|
173
|
-
self._metrics.clear()
|
|
174
|
-
|
|
175
|
-
# ========================================================================
|
|
176
|
-
# Performance Monitoring Methods (from IPerformanceMonitor)
|
|
177
|
-
# ========================================================================
|
|
178
|
-
|
|
179
|
-
def record_load_time(self, module: str, load_time: float) -> None:
|
|
180
|
-
"""Record module load time (from IPerformanceMonitor)."""
|
|
181
|
-
with self._lock:
|
|
182
|
-
if module not in self._load_times:
|
|
183
|
-
self._load_times[module] = []
|
|
184
|
-
self._load_times[module].append(load_time)
|
|
185
|
-
|
|
186
|
-
def record_access(self, module: str) -> None:
|
|
187
|
-
"""Record module access (from IPerformanceMonitor)."""
|
|
188
|
-
with self._lock:
|
|
189
|
-
self._access_counts[module] = self._access_counts.get(module, 0) + 1
|
|
190
|
-
|
|
191
|
-
@abstractmethod
|
|
192
|
-
def get_performance_stats(self) -> dict[str, Any]:
|
|
193
|
-
"""Get performance statistics (from IPerformanceMonitor)."""
|
|
194
|
-
pass
|
|
195
|
-
|
|
196
|
-
# ========================================================================
|
|
197
|
-
# Multi-Tier Cache Methods (from IMultiTierCache)
|
|
198
|
-
# ========================================================================
|
|
199
|
-
|
|
200
|
-
def get_multi_tier_cached(self, key: str) -> Optional[Any]:
|
|
201
|
-
"""Get value from cache (L1 -> L2 -> L3) (from IMultiTierCache)."""
|
|
202
|
-
with self._lock:
|
|
203
|
-
# Check L1 first
|
|
204
|
-
if key in self._l1_cache:
|
|
205
|
-
return self._l1_cache[key]
|
|
206
|
-
# Check L2
|
|
207
|
-
if key in self._l2_cache:
|
|
208
|
-
value = self._l2_cache[key]
|
|
209
|
-
# Promote to L1
|
|
210
|
-
self._l1_cache[key] = value
|
|
211
|
-
return value
|
|
212
|
-
# Check L3
|
|
213
|
-
if key in self._l3_cache:
|
|
214
|
-
value = self._l3_cache[key]
|
|
215
|
-
# Promote to L2
|
|
216
|
-
self._l2_cache[key] = value
|
|
217
|
-
return value
|
|
218
|
-
return None
|
|
219
|
-
|
|
220
|
-
def set_multi_tier_cached(self, key: str, value: Any) -> None:
|
|
221
|
-
"""Set value in cache (L1 and L2) (from IMultiTierCache)."""
|
|
222
|
-
with self._lock:
|
|
223
|
-
self._l1_cache[key] = value
|
|
224
|
-
self._l2_cache[key] = value
|
|
225
|
-
|
|
226
|
-
def clear_multi_tier_cache(self) -> None:
|
|
227
|
-
"""Clear all cache tiers (from IMultiTierCache)."""
|
|
228
|
-
with self._lock:
|
|
229
|
-
self._l1_cache.clear()
|
|
230
|
-
self._l2_cache.clear()
|
|
231
|
-
self._l3_cache.clear()
|
|
232
|
-
|
|
233
|
-
@abstractmethod
|
|
234
|
-
def shutdown_multi_tier_cache(self) -> None:
|
|
235
|
-
"""Shutdown cache (flush L2, cleanup threads) (from IMultiTierCache)."""
|
|
236
|
-
pass
|
|
237
|
-
|
|
238
|
-
# Alias method for backward compatibility
|
|
239
|
-
def shutdown_cache(self) -> None:
|
|
240
|
-
"""Alias for shutdown_multi_tier_cache (backward compatibility)."""
|
|
241
|
-
self.shutdown_multi_tier_cache()
|
|
242
|
-
|
|
243
|
-
# ========================================================================
|
|
244
|
-
# Registry Methods (from IRegistry)
|
|
245
|
-
# ========================================================================
|
|
246
|
-
|
|
247
|
-
def get_instance(self, key: str) -> Any:
|
|
248
|
-
"""Get instance by key (from IRegistry)."""
|
|
249
|
-
with self._lock:
|
|
250
|
-
return self._registry.get(key)
|
|
251
|
-
|
|
252
|
-
def register(self, key: str, instance: Any) -> None:
|
|
253
|
-
"""Register an instance (from IRegistry)."""
|
|
254
|
-
with self._lock:
|
|
255
|
-
self._registry[key] = instance
|
|
256
|
-
|
|
257
|
-
def unregister(self, key: str) -> None:
|
|
258
|
-
"""Unregister an instance (from IRegistry)."""
|
|
259
|
-
with self._lock:
|
|
260
|
-
self._registry.pop(key, None)
|
|
261
|
-
|
|
262
|
-
def has_key(self, key: str) -> bool:
|
|
263
|
-
"""Check if key is registered (from IRegistry)."""
|
|
264
|
-
with self._lock:
|
|
265
|
-
return key in self._registry
|
|
266
|
-
|
|
267
|
-
# =============================================================================
|
|
268
|
-
# EXPORT ALL
|
|
269
|
-
# =============================================================================
|
|
270
|
-
|
|
271
|
-
__all__ = [
|
|
272
|
-
'ARuntimeHelper',
|
|
273
|
-
]
|
|
274
|
-
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Runtime Services Facade
|
|
3
|
-
|
|
4
|
-
Main facade: XWRuntimeHelper extends ARuntimeHelper
|
|
5
|
-
Provides concrete implementation for all runtime services.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from typing import Optional, Any
|
|
9
|
-
from .base import ARuntimeHelper
|
|
10
|
-
from ..defs import LazyLoadMode, LazyInstallMode
|
|
11
|
-
|
|
12
|
-
class XWRuntimeHelper(ARuntimeHelper):
|
|
13
|
-
"""
|
|
14
|
-
Concrete implementation of ARuntimeHelper.
|
|
15
|
-
|
|
16
|
-
Provides runtime services for state management, learning, monitoring, and caching.
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
def __init__(self):
|
|
20
|
-
"""Initialize XW runtime services."""
|
|
21
|
-
super().__init__()
|
|
22
|
-
|
|
23
|
-
# Abstract methods from ARuntime that need implementation
|
|
24
|
-
def record_import(self, module_name: str, import_time: float) -> None:
|
|
25
|
-
"""Record an import event."""
|
|
26
|
-
# TODO: Implement import recording
|
|
27
|
-
pass
|
|
28
|
-
|
|
29
|
-
def predict_next_imports(self, current_module: str, count: int = 3) -> list[str]:
|
|
30
|
-
"""Predict next likely imports based on patterns."""
|
|
31
|
-
# TODO: Implement prediction logic
|
|
32
|
-
return []
|
|
33
|
-
|
|
34
|
-
def get_module_score(self, module_name: str) -> float:
|
|
35
|
-
"""Get priority score for a module."""
|
|
36
|
-
# TODO: Implement scoring logic
|
|
37
|
-
return 0.0
|
|
38
|
-
|
|
39
|
-
def detect_load_level(
|
|
40
|
-
self,
|
|
41
|
-
module_count: int = 0,
|
|
42
|
-
total_import_time: float = 0.0,
|
|
43
|
-
import_count: int = 0,
|
|
44
|
-
memory_usage_mb: float = 0.0
|
|
45
|
-
):
|
|
46
|
-
"""Detect current load level."""
|
|
47
|
-
# TODO: Implement load level detection
|
|
48
|
-
from .intelligent_selector import LoadLevel
|
|
49
|
-
return LoadLevel.LIGHT
|
|
50
|
-
|
|
51
|
-
def get_optimal_mode(self, load_level) -> tuple[LazyLoadMode, LazyInstallMode]:
|
|
52
|
-
"""Get optimal mode for a load level."""
|
|
53
|
-
# TODO: Implement mode selection
|
|
54
|
-
return LazyLoadMode.AUTO, LazyInstallMode.SMART
|
|
55
|
-
|
|
56
|
-
def update_mode_map(self, mode_map: dict[Any, tuple[LazyLoadMode, LazyInstallMode]]) -> None:
|
|
57
|
-
"""Update mode mapping with benchmark results."""
|
|
58
|
-
# TODO: Implement mode map update
|
|
59
|
-
pass
|
|
60
|
-
|
|
61
|
-
def get_metric_stats(self, name: str) -> dict[str, Any]:
|
|
62
|
-
"""Get statistics for a metric."""
|
|
63
|
-
with self._lock:
|
|
64
|
-
values = self._metrics.get(name, [])
|
|
65
|
-
if not values:
|
|
66
|
-
return {'count': 0, 'total': 0.0, 'average': 0.0, 'min': 0.0, 'max': 0.0}
|
|
67
|
-
return {
|
|
68
|
-
'count': len(values),
|
|
69
|
-
'total': sum(values),
|
|
70
|
-
'average': sum(values) / len(values),
|
|
71
|
-
'min': min(values),
|
|
72
|
-
'max': max(values)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
def get_all_stats(self) -> dict[str, dict[str, Any]]:
|
|
76
|
-
"""Get statistics for all metrics."""
|
|
77
|
-
with self._lock:
|
|
78
|
-
return {name: self.get_metric_stats(name) for name in self._metrics.keys()}
|
|
79
|
-
|
|
80
|
-
def get_performance_stats(self) -> dict[str, Any]:
|
|
81
|
-
"""Get performance statistics."""
|
|
82
|
-
with self._lock:
|
|
83
|
-
return {
|
|
84
|
-
'load_times': {k: {'count': len(v), 'total': sum(v), 'average': sum(v) / len(v) if v else 0.0}
|
|
85
|
-
for k, v in self._load_times.items()},
|
|
86
|
-
'access_counts': self._access_counts.copy(),
|
|
87
|
-
'memory_usage': 0.0 # TODO: Implement memory usage tracking
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
def shutdown_multi_tier_cache(self) -> None:
|
|
91
|
-
"""Shutdown cache (flush L2, cleanup threads)."""
|
|
92
|
-
# TODO: Implement cache shutdown
|
|
93
|
-
pass
|
|
94
|
-
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
#exonware/xwlazy/src/exonware/xwlazy/loading/intelligent_utils.py
|
|
3
|
-
|
|
4
|
-
Intelligent mode utilities for automatic mode switching.
|
|
5
|
-
|
|
6
|
-
Company: eXonware.com
|
|
7
|
-
Author: Eng. Muhammad AlShehri
|
|
8
|
-
Email: connect@exonware.com
|
|
9
|
-
|
|
10
|
-
Generation Date: 19-Nov-2025
|
|
11
|
-
|
|
12
|
-
This module provides intelligent mode switching based on load level.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
from typing import Optional
|
|
16
|
-
|
|
17
|
-
from ..defs import LazyLoadMode, LazyInstallMode, LoadLevel
|
|
18
|
-
|
|
19
|
-
# Lazy import to avoid circular dependency
|
|
20
|
-
logger = None
|
|
21
|
-
|
|
22
|
-
def _get_logger():
|
|
23
|
-
"""Get logger (lazy import to avoid circular dependency)."""
|
|
24
|
-
global logger
|
|
25
|
-
if logger is None:
|
|
26
|
-
from ..common.logger import get_logger
|
|
27
|
-
logger = get_logger("xwlazy.loading.intelligent")
|
|
28
|
-
return logger
|
|
29
|
-
|
|
30
|
-
# Optimal mode mappings based on benchmark results (updated from consistency test)
|
|
31
|
-
# Format: {LoadLevel: (LazyLoadMode, LazyInstallMode)}
|
|
32
|
-
# Updated: 2025-11-19 - Based on 20-iteration consistency test averages
|
|
33
|
-
# Light: ultra+full (0.568ms avg), Medium: hyperparallel+full (5.134ms avg)
|
|
34
|
-
# Heavy: preload+size_aware (18.475ms avg), Enterprise: preload+full (44.742ms avg)
|
|
35
|
-
INTELLIGENT_MODE_MAP: dict[LoadLevel, tuple[LazyLoadMode, LazyInstallMode]] = {
|
|
36
|
-
LoadLevel.LIGHT: (LazyLoadMode.ULTRA, LazyInstallMode.FULL), # Winner: 0.568ms avg (±26.1% CV)
|
|
37
|
-
LoadLevel.MEDIUM: (LazyLoadMode.HYPERPARALLEL, LazyInstallMode.FULL), # Winner: 5.134ms avg (±4.7% CV)
|
|
38
|
-
LoadLevel.HEAVY: (LazyLoadMode.PRELOAD, LazyInstallMode.SIZE_AWARE), # Winner: 18.475ms avg (±10.2% CV)
|
|
39
|
-
LoadLevel.ENTERPRISE: (LazyLoadMode.PRELOAD, LazyInstallMode.FULL), # Winner: 44.742ms avg (±1.5% CV)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
class IntelligentModeSelector:
|
|
43
|
-
"""Selects optimal mode based on current load characteristics."""
|
|
44
|
-
|
|
45
|
-
def __init__(self, mode_map: Optional[dict[LoadLevel, tuple[LazyLoadMode, LazyInstallMode]]] = None):
|
|
46
|
-
"""
|
|
47
|
-
Initialize intelligent mode selector.
|
|
48
|
-
|
|
49
|
-
Args:
|
|
50
|
-
mode_map: Custom mode mapping (defaults to INTELLIGENT_MODE_MAP)
|
|
51
|
-
"""
|
|
52
|
-
self._mode_map = mode_map or INTELLIGENT_MODE_MAP.copy()
|
|
53
|
-
self._current_load_level: Optional[LoadLevel] = None
|
|
54
|
-
self._module_count = 0
|
|
55
|
-
self._total_import_time = 0.0
|
|
56
|
-
self._import_count = 0
|
|
57
|
-
|
|
58
|
-
def update_mode_map(self, mode_map: dict[LoadLevel, tuple[LazyLoadMode, LazyInstallMode]]) -> None:
|
|
59
|
-
"""Update the mode mapping with benchmark results."""
|
|
60
|
-
self._mode_map = mode_map.copy()
|
|
61
|
-
_get_logger().info(f"Updated INTELLIGENT mode mapping: {mode_map}")
|
|
62
|
-
|
|
63
|
-
def detect_load_level(
|
|
64
|
-
self,
|
|
65
|
-
module_count: int = 0,
|
|
66
|
-
total_import_time: float = 0.0,
|
|
67
|
-
import_count: int = 0,
|
|
68
|
-
memory_usage_mb: float = 0.0
|
|
69
|
-
) -> LoadLevel:
|
|
70
|
-
"""
|
|
71
|
-
Detect current load level based on system characteristics.
|
|
72
|
-
|
|
73
|
-
Args:
|
|
74
|
-
module_count: Number of modules loaded
|
|
75
|
-
total_import_time: Total time spent on imports (seconds)
|
|
76
|
-
import_count: Number of imports performed
|
|
77
|
-
memory_usage_mb: Current memory usage in MB
|
|
78
|
-
|
|
79
|
-
Returns:
|
|
80
|
-
Detected LoadLevel
|
|
81
|
-
"""
|
|
82
|
-
# Update internal state
|
|
83
|
-
self._module_count = module_count
|
|
84
|
-
self._total_import_time = total_import_time
|
|
85
|
-
self._import_count = import_count
|
|
86
|
-
|
|
87
|
-
# Simple heuristics based on module count and import patterns
|
|
88
|
-
# These thresholds can be tuned based on actual usage patterns
|
|
89
|
-
|
|
90
|
-
if import_count == 0:
|
|
91
|
-
# Initial state - default to light
|
|
92
|
-
self._current_load_level = LoadLevel.LIGHT
|
|
93
|
-
elif module_count < 5 and import_count < 10:
|
|
94
|
-
# Light load: few modules, few imports
|
|
95
|
-
self._current_load_level = LoadLevel.LIGHT
|
|
96
|
-
elif module_count < 20 and import_count < 50:
|
|
97
|
-
# Medium load: moderate number of modules/imports
|
|
98
|
-
self._current_load_level = LoadLevel.MEDIUM
|
|
99
|
-
elif module_count < 100 and import_count < 200:
|
|
100
|
-
# Heavy load: many modules, many imports
|
|
101
|
-
self._current_load_level = LoadLevel.HEAVY
|
|
102
|
-
else:
|
|
103
|
-
# Enterprise load: very large scale
|
|
104
|
-
self._current_load_level = LoadLevel.ENTERPRISE
|
|
105
|
-
|
|
106
|
-
# Override based on memory usage if significant
|
|
107
|
-
if memory_usage_mb > 300:
|
|
108
|
-
self._current_load_level = LoadLevel.ENTERPRISE
|
|
109
|
-
elif memory_usage_mb > 150:
|
|
110
|
-
self._current_load_level = LoadLevel.HEAVY
|
|
111
|
-
|
|
112
|
-
return self._current_load_level
|
|
113
|
-
|
|
114
|
-
def get_optimal_mode(self, load_level: Optional[LoadLevel] = None) -> tuple[LazyLoadMode, LazyInstallMode]:
|
|
115
|
-
"""
|
|
116
|
-
Get optimal mode combination for given load level.
|
|
117
|
-
|
|
118
|
-
Args:
|
|
119
|
-
load_level: Load level (if None, uses detected level)
|
|
120
|
-
|
|
121
|
-
Returns:
|
|
122
|
-
Tuple of (LazyLoadMode, LazyInstallMode)
|
|
123
|
-
"""
|
|
124
|
-
if load_level is None:
|
|
125
|
-
load_level = self._current_load_level or LoadLevel.LIGHT
|
|
126
|
-
|
|
127
|
-
optimal = self._mode_map.get(load_level)
|
|
128
|
-
if optimal is None:
|
|
129
|
-
# Fallback to default
|
|
130
|
-
_get_logger().warning(f"No optimal mode found for {load_level}, using default")
|
|
131
|
-
optimal = (LazyLoadMode.AUTO, LazyInstallMode.SMART)
|
|
132
|
-
|
|
133
|
-
return optimal
|
|
134
|
-
|
|
135
|
-
def should_switch_mode(
|
|
136
|
-
self,
|
|
137
|
-
current_mode: tuple[LazyLoadMode, LazyInstallMode],
|
|
138
|
-
detected_level: LoadLevel
|
|
139
|
-
) -> bool:
|
|
140
|
-
"""
|
|
141
|
-
Determine if mode should be switched based on detected load level.
|
|
142
|
-
|
|
143
|
-
Args:
|
|
144
|
-
current_mode: Current (load_mode, install_mode) tuple
|
|
145
|
-
detected_level: Detected load level
|
|
146
|
-
|
|
147
|
-
Returns:
|
|
148
|
-
True if mode should be switched
|
|
149
|
-
"""
|
|
150
|
-
optimal_mode = self.get_optimal_mode(detected_level)
|
|
151
|
-
return current_mode != optimal_mode
|
|
152
|
-
|
|
153
|
-
def get_stats(self) -> Dict:
|
|
154
|
-
"""Get intelligent mode statistics."""
|
|
155
|
-
return {
|
|
156
|
-
'current_load_level': self._current_load_level.value if self._current_load_level else None,
|
|
157
|
-
'module_count': self._module_count,
|
|
158
|
-
'import_count': self._import_count,
|
|
159
|
-
'total_import_time': self._total_import_time,
|
|
160
|
-
'mode_map': {
|
|
161
|
-
level.value: {
|
|
162
|
-
'load_mode': mode[0].value,
|
|
163
|
-
'install_mode': mode[1].value
|
|
164
|
-
}
|
|
165
|
-
for level, mode in self._mode_map.items()
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
__all__ = ['LoadLevel', 'INTELLIGENT_MODE_MAP', 'IntelligentModeSelector']
|
|
170
|
-
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Performance metrics tracking for lazy loading system.
|
|
3
|
-
|
|
4
|
-
This module provides utilities for tracking and aggregating performance metrics.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from typing import Any, Optional
|
|
8
|
-
from datetime import datetime
|
|
9
|
-
from collections import defaultdict
|
|
10
|
-
|
|
11
|
-
class MetricsCollector:
|
|
12
|
-
"""Collects and aggregates performance metrics."""
|
|
13
|
-
|
|
14
|
-
def __init__(self):
|
|
15
|
-
"""Initialize metrics collector."""
|
|
16
|
-
self._metrics: dict[str, list[float]] = defaultdict(list)
|
|
17
|
-
self._counts: dict[str, int] = defaultdict(int)
|
|
18
|
-
self._timestamps: dict[str, list[datetime]] = defaultdict(list)
|
|
19
|
-
|
|
20
|
-
def record_metric(self, name: str, value: float, timestamp: Optional[datetime] = None) -> None:
|
|
21
|
-
"""Record a metric value."""
|
|
22
|
-
self._metrics[name].append(value)
|
|
23
|
-
self._counts[name] += 1
|
|
24
|
-
if timestamp is None:
|
|
25
|
-
timestamp = datetime.now()
|
|
26
|
-
self._timestamps[name].append(timestamp)
|
|
27
|
-
|
|
28
|
-
def get_metric_stats(self, name: str) -> dict[str, Any]:
|
|
29
|
-
"""Get statistics for a specific metric."""
|
|
30
|
-
values = self._metrics.get(name, [])
|
|
31
|
-
if not values:
|
|
32
|
-
return {}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
'count': len(values),
|
|
36
|
-
'total': sum(values),
|
|
37
|
-
'average': sum(values) / len(values),
|
|
38
|
-
'min': min(values),
|
|
39
|
-
'max': max(values),
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
def get_all_stats(self) -> dict[str, dict[str, Any]]:
|
|
43
|
-
"""Get statistics for all metrics."""
|
|
44
|
-
return {name: self.get_metric_stats(name) for name in self._metrics.keys()}
|
|
45
|
-
|
|
46
|
-
def clear(self) -> None:
|
|
47
|
-
"""Clear all collected metrics."""
|
|
48
|
-
self._metrics.clear()
|
|
49
|
-
self._counts.clear()
|
|
50
|
-
self._timestamps.clear()
|
|
51
|
-
|
|
52
|
-
# Global metrics collector instance
|
|
53
|
-
_global_metrics = MetricsCollector()
|
|
54
|
-
|
|
55
|
-
def get_metrics_collector() -> MetricsCollector:
|
|
56
|
-
"""Get the global metrics collector instance."""
|
|
57
|
-
return _global_metrics
|
|
58
|
-
|
|
59
|
-
__all__ = ['MetricsCollector', 'get_metrics_collector']
|
|
60
|
-
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Performance monitoring for lazy loading system.
|
|
3
|
-
|
|
4
|
-
This module contains LazyPerformanceMonitor extracted from lazy_core.py Section 4.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from typing import Any
|
|
8
|
-
|
|
9
|
-
class LazyPerformanceMonitor:
|
|
10
|
-
"""Performance monitor for lazy loading operations."""
|
|
11
|
-
|
|
12
|
-
__slots__ = ('_load_times', '_access_counts', '_memory_usage')
|
|
13
|
-
|
|
14
|
-
def __init__(self):
|
|
15
|
-
"""Initialize performance monitor."""
|
|
16
|
-
self._load_times: dict[str, float] = {}
|
|
17
|
-
self._access_counts: dict[str, int] = {}
|
|
18
|
-
self._memory_usage: dict[str, Any] = {}
|
|
19
|
-
|
|
20
|
-
def record_load_time(self, module: str, load_time: float) -> None:
|
|
21
|
-
"""Record module load time."""
|
|
22
|
-
self._load_times[module] = load_time
|
|
23
|
-
|
|
24
|
-
def record_access(self, module: str) -> None:
|
|
25
|
-
"""Record module access."""
|
|
26
|
-
self._access_counts[module] = self._access_counts.get(module, 0) + 1
|
|
27
|
-
|
|
28
|
-
def get_stats(self) -> dict[str, Any]:
|
|
29
|
-
"""Get performance statistics."""
|
|
30
|
-
return {
|
|
31
|
-
'load_times': self._load_times.copy(),
|
|
32
|
-
'access_counts': self._access_counts.copy(),
|
|
33
|
-
'memory_usage': self._memory_usage.copy()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
__all__ = ['LazyPerformanceMonitor']
|
|
37
|
-
|