quantrs2_circuit/profiler/
sessions.rs1use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8use std::sync::Arc;
9use std::time::{Duration, SystemTime};
10
11use super::analyzers::*;
13use super::collectors::*;
14use super::metrics::*;
15
16pub struct SessionManager {
17 pub active_sessions: HashMap<String, ProfilingSession>,
19 pub session_config: SessionConfig,
21 pub session_storage: SessionStorage,
23 pub session_analytics: SessionAnalytics,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct ProfilingSession {
30 pub id: String,
32 pub start_time: SystemTime,
34 pub end_time: Option<SystemTime>,
36 pub status: SessionStatus,
38 pub collected_data: SessionData,
40 pub metadata: HashMap<String, String>,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46pub enum SessionStatus {
47 Starting,
49 Running,
51 Paused,
53 Stopping,
55 Completed,
57 Failed { error: String },
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct SessionData {
64 pub metrics: Vec<PerformanceMetric>,
66 pub gate_profiles: HashMap<String, GateProfile>,
68 pub memory_snapshots: Vec<MemorySnapshot>,
70 pub resource_data: Vec<ResourceUsage>,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct SessionConfig {
77 pub default_duration: Duration,
79 pub collection_interval: Duration,
81 pub max_concurrent_sessions: usize,
83 pub session_timeout: Duration,
85}
86
87#[derive(Debug, Clone)]
89pub struct SessionStorage {
90 pub backend: StorageBackend,
92 pub config: StorageConfig,
94 pub serialization: SerializationConfig,
96}
97
98#[derive(Debug, Clone)]
100pub enum StorageBackend {
101 InMemory,
103 FileSystem { path: String },
105 Database { connection_string: String },
107 Cloud {
109 provider: String,
110 config: HashMap<String, String>,
111 },
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
116pub struct StorageConfig {
117 pub enable_compression: bool,
119 pub enable_encryption: bool,
121 pub retention_policy: DataRetentionPolicy,
123 pub backup_config: Option<BackupConfig>,
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
129pub struct BackupConfig {
130 pub frequency: Duration,
132 pub location: String,
134 pub retention: Duration,
136 pub incremental: bool,
138}
139
140#[derive(Debug, Clone, Serialize, Deserialize)]
142pub struct SerializationConfig {
143 pub format: SerializationFormat,
145 pub schema_validation: bool,
147 pub version_compatibility: bool,
149}
150
151#[derive(Debug, Clone, Serialize, Deserialize)]
153pub enum SerializationFormat {
154 JSON,
156 Binary,
158 ProtocolBuffers,
160 MessagePack,
162}
163
164#[derive(Debug, Clone)]
166pub struct SessionAnalytics {
167 pub config: AnalyticsConfig,
169 pub statistics: SessionStatistics,
171 pub insights: Vec<PerformanceInsight>,
173 pub trend_analysis: SessionTrendAnalysis,
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize)]
179pub struct AnalyticsConfig {
180 pub enable_realtime: bool,
182 pub depth: AnalysisDepth,
184 pub reporting_frequency: Duration,
186 pub custom_metrics: Vec<String>,
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize)]
192pub struct SessionStatistics {
193 pub total_sessions: usize,
195 pub avg_duration: Duration,
197 pub success_rate: f64,
199 pub collection_efficiency: f64,
201}
202
203#[derive(Debug, Clone, Serialize, Deserialize)]
205pub struct PerformanceInsight {
206 pub insight_type: InsightType,
208 pub description: String,
210 pub confidence: f64,
212 pub impact: f64,
214 pub actions: Vec<String>,
216}
217
218#[derive(Debug, Clone, Serialize, Deserialize)]
220pub enum InsightType {
221 OptimizationOpportunity,
223 ResourceUtilization,
225 ScalingRecommendation,
227 ConfigurationImprovement,
229 ArchitectureRecommendation,
231}
232
233#[derive(Debug, Clone, Serialize, Deserialize)]
235pub struct SessionTrendAnalysis {
236 pub performance_trends: HashMap<String, TrendDirection>,
238 pub resource_trends: HashMap<String, TrendDirection>,
240 pub quality_trends: HashMap<String, TrendDirection>,
242 pub prediction_trends: HashMap<String, f64>,
244}