mirror of
https://github.com/R0m1k3/xtremobile.git
synced 2026-10-11 17:29:26 +02:00
Phase 2: Performance Profiling Setup - Add profiling utilities
- Add StartupProfiler: Measure cold/warm start times - Add VideoProfiler: Profile video load, playback metrics - Add MemoryProfiler: Detect memory leaks, monitor heap growth - Add HiveEncryptionBenchmark: Measure encryption overhead - Add PHASE_2_PROFILING_PLAN.md: Complete testing procedures Ready for profiling execution once Flutter SDK is initialized
This commit is contained in:
1 parent
1293a159ee
commit
c5fcafcce1
553 files changed
+85219
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// Profiler for startup time measurements
|
||||
class StartupProfiler {
|
||||
static final _timings = <String, Stopwatch>{};
|
||||
static final _marks = <String, DateTime>{};
|
||||
|
||||
/// Start timing a phase
|
||||
static void start(String label) {
|
||||
_timings[label] = Stopwatch()..start();
|
||||
_marks[label] = DateTime.now();
|
||||
if (kDebugMode) {
|
||||
print('⏱️ START: $label (${DateTime.now().toIso8601String()})');
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark completion of a phase
|
||||
static void mark(String label) {
|
||||
final watch = _timings[label];
|
||||
if (watch != null) {
|
||||
watch.stop();
|
||||
final ms = watch.elapsedMilliseconds;
|
||||
if (kDebugMode) {
|
||||
print('✅ $label: ${ms}ms');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get elapsed time for a label
|
||||
static int? getElapsedMs(String label) {
|
||||
return _timings[label]?.elapsedMilliseconds;
|
||||
}
|
||||
|
||||
/// Report all metrics
|
||||
static Future<void> reportAll() async {
|
||||
if (kDebugMode) {
|
||||
print('\n' + ('=' * 50));
|
||||
print('⏱️ STARTUP METRICS');
|
||||
print('=' * 50);
|
||||
_timings.forEach((key, watch) {
|
||||
print(' $key: ${watch.elapsedMilliseconds}ms');
|
||||
});
|
||||
print('=' * 50 + '\n');
|
||||
}
|
||||
}
|
||||
|
||||
/// Export metrics as JSON for logging
|
||||
static Map<String, int> toJson() {
|
||||
return _timings
|
||||
.map((key, watch) => MapEntry(key, watch.elapsedMilliseconds));
|
||||
}
|
||||
|
||||
/// Reset all timings
|
||||
static void reset() {
|
||||
_timings.clear();
|
||||
_marks.clear();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user