flutter_perf_monitor 0.2.1
flutter_perf_monitor: ^0.2.1 copied to clipboard
Real-time performance monitoring with FPS tracking and memory usage for Flutter applications
Flutter Performance Monitor #
A lightweight package to track real-time performance metrics in your Flutter applications, including FPS and system-level memory and CPU usage.
Key Features #
- Real-time FPS tracking.
- Memory and CPU usage monitoring with native implementations for iOS and Android.
- Live metric updates with minimal performance impact.
- Cross-platform support (iOS, Android, Web, and Desktop).
Getting Started #
Add the dependency to your pubspec.yaml file:
dependencies:
flutter_perf_monitor: ^0.2.1
Basic Usage #
Initialize the monitor and add the widget to your widget tree:
import 'package:flutter_perf_monitor/flutter_perf_monitor.dart';
void main() {
FlutterPerfMonitor.initialize();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(
children: [
PerfMonitorWidget(),
Expanded(
child: YourAppContent(),
),
],
),
),
);
}
}
API Reference #
The primary interface is FlutterPerfMonitor, which exposes the following methods:
initialize(): Sets up the performance monitor.startMonitoring()/stopMonitoring(): Controls the monitoring lifecycle.getFPS(): Returns the current frame rate.getMemoryUsage(): Returns total, available, and used memory.getPerCoreCpuUsage(): Returns CPU usage percentages.
For displaying metrics, use the PerfMonitorWidget.
Platform Specifics #
We provide native integrations for accurate hardware metrics where possible, and fallback mechanisms for others.
Native Support (Android & iOS) #
- Android: CPU usage is read from
/proc/stat. Memory is fetched viaActivityManager.MemoryInfo. - iOS: CPU usage leverages
task_threads. Memory is fetched viaProcessInfoandmach_task_basic_info.
Fallback Behavior #
When native metrics are unavailable, the package uses fallbacks:
- Desktop: Process memory via
ProcessInfo.currentRss. CPU relies on FPS-based estimation. - Web (JS): Uses
window.performance.memory.usedJSHeapSizewhen the browser allows it (e.g., Chrome/Edge). Otherwise, defaults to 0. - Web (WASM): Wasm sandbox restrictions prevent direct heap access, so memory is reported as 0. FPS tracking remains active.
For more details on implementation, please refer to SETUP.md.
Contributing & Support #
We welcome contributions. Please review CONTRIBUTING.md for our guidelines.
If you encounter issues or have feedback, feel free to open an issue on our GitHub repository.
See CHANGELOG.md for version history.
License: MIT