Skip to main content

device_diagnostics 0.0.5 copy "device_diagnostics: ^0.0.5" to clipboard
device_diagnostics: ^0.0.5 copied to clipboard

A Flutter package for opt-in device diagnostics, performance monitoring, network instrumentation, and PDF diagnostic reports.

πŸ” device_diagnostics #

A Flutter package for opt-in device diagnostics, performance monitoring, network instrumentation, and PDF diagnostic reports. πŸ“Š

pub package likes GitHub License: MIT

Monitor your Flutter application's performance, track network activity, inspect device metrics, and generate diagnostic reports β€” all through a single package. πŸš€


✨ Features #

  • πŸ“± Device information β€” model, manufacturer, operating system, and architecture where available.
  • ⚑ CPU monitoring β€” process CPU usage estimates where supported.
  • 🧠 Memory monitoring β€” track application memory usage.
  • 🌑️ Thermal monitoring β€” inspect device thermal state where supported.
  • 🌐 Network instrumentation β€” track HTTP request and response body bytes through the provided client.
  • 🎬 Frame monitoring β€” observe frame performance and estimate dropped frames.
  • 🧭 Route tracking β€” associate diagnostic activity with application screens.
  • πŸ“„ PDF reports β€” export diagnostic sessions for inspection and sharing.
  • πŸŽ›οΈ Flexible visibility configuration β€” choose Debug, Profile, Release, Debug + Release, or All modes.
  • πŸ”’ Opt-in monitoring β€” configure diagnostics according to your application's requirements.

πŸ’‘ Metric availability varies by platform. CPU usage, network traffic, thermal state, and device details may be estimates, unavailable, or platform-dependent.

πŸ“¦ Installation #

Add the dependency to your pubspec.yaml:

dependencies:
  device_diagnostics: ^0.0.1

Then run:

flutter pub get

🚨 If you are installing a newer published version, replace 0.0.1 with the version listed on pub.dev.

πŸš€ Quick Start #

Initialize diagnostics before calling runApp():

import 'package:flutter/material.dart';
import 'package:device_diagnostics/device_diagnostics.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await DeviceDiagnostics.initialize(
    config: const DiagnosticConfig(
      visibility: DiagnosticVisibility.debug,
    ),
  );

  runApp(
    DeviceDiagnostics.observability(
      child: MaterialApp(
        navigatorObservers: [
          DeviceDiagnostics.routeObserver,
        ],
        home: const MyHomePage(),
      ),
    ),
  );
}

🧩 What's happening here? #

  1. βš™οΈ DeviceDiagnostics.initialize() initializes the package configuration.
  2. πŸŽ›οΈ DiagnosticConfig controls which build modes can display diagnostics and which metrics are enabled.
  3. 🧭 routeObserver tracks navigation events.
  4. πŸ–₯️ DeviceDiagnostics.observability() wraps your app with the diagnostic UI when enabled for the current build mode.

πŸŽ›οΈ Visibility Modes Explained #

Choose when the diagnostic interface should be visible.

Mode πŸ› Debug πŸ”¬ Profile πŸš€ Release
debug βœ… Visible ❌ Hidden ❌ Hidden
profile ❌ Hidden βœ… Visible ❌ Hidden
release ❌ Hidden ❌ Hidden βœ… Visible
debugAndRelease βœ… Visible ❌ Hidden βœ… Visible
all βœ… Visible βœ… Visible βœ… Visible

πŸ› DiagnosticVisibility.debug #

Best for everyday development and debugging.

const DiagnosticConfig(
  visibility: DiagnosticVisibility.debug,
)

πŸ”¬ DiagnosticVisibility.profile #

Use this mode when profiling performance without enabling the diagnostic UI in ordinary Debug or Release builds.

const DiagnosticConfig(
  visibility: DiagnosticVisibility.profile,
)

πŸš€ DiagnosticVisibility.release #

Enables diagnostic visibility in Release builds. Use it only when you intentionally want diagnostics available in production.

const DiagnosticConfig(
  visibility: DiagnosticVisibility.release,
)

πŸ”„ DiagnosticVisibility.debugAndRelease #

Enables diagnostic visibility in Debug and Release builds while hiding it in Profile builds.

const DiagnosticConfig(
  visibility: DiagnosticVisibility.debugAndRelease,
)

🌍 DiagnosticVisibility.all #

Enables diagnostic visibility in all three build modes.

const DiagnosticConfig(
  visibility: DiagnosticVisibility.all,
)

⚠️ Important: Visibility configuration controls the diagnostic UI's build-mode visibility. It should not be treated as a security boundary or a substitute for access control, privacy safeguards, or production monitoring policies.

βš™οΈ Configuration Reference #

Configure monitoring according to your application's needs.

const DiagnosticConfig(
  visibility: DiagnosticVisibility.debug,
  sampleInterval: Duration(seconds: 1),
  enableThermalMonitoring: true,
  enableCpuMonitoring: true,
  enableMemoryMonitoring: true,
  enableNetworkMonitoring: true,
  enableFrameMonitoring: true,
  showFloatingButtonWhenIdle: true,
)
Option Description
πŸŽ›οΈ visibility Selects the build modes in which the diagnostic UI is visible.
⏱️ sampleInterval Controls how frequently diagnostic metrics are sampled.
🌑️ enableThermalMonitoring Enables thermal-state monitoring where supported.
⚑ enableCpuMonitoring Enables process CPU usage sampling where supported.
🧠 enableMemoryMonitoring Enables memory usage sampling.
🌐 enableNetworkMonitoring Controls network diagnostics when supported by the implementation.
🎬 enableFrameMonitoring Enables frame performance monitoring.
πŸ–²οΈ showFloatingButtonWhenIdle Controls whether the floating diagnostic button is shown while a session is idle.

πŸ’‘ The configured sampling interval must be at least 250 milliseconds if your configuration validation enforces that minimum.

🌐 HTTP Network Instrumentation #

Use DiagnosticHttpClient to record HTTP body-byte metrics for requests made through the diagnostic client.

final client = DiagnosticHttpClient();

try {
  final response = await client.get(
    Uri.parse('https://example.com/api'),
  );

  debugPrint('Status code: ${response.statusCode}');
} finally {
  client.close();
}

πŸ“‘ What can it track? #

  • πŸ“€ Outgoing request body bytes.
  • πŸ“₯ Incoming response body bytes.
  • 🧭 Network activity associated with diagnostic routes, subject to the implementation's attribution behavior.

⚠️ These measurements are not necessarily total network usage. They may exclude headers, TLS overhead, retransmissions, and traffic sent through other HTTP clients or networking APIs.

πŸ“Š Diagnostic Sessions #

Start a diagnostic session using the controller:

final controller = DeviceDiagnostics.controller;

await controller.start();

When you have finished collecting diagnostics, export the session report:

await controller.stopAndExportPdf(
  share: false,
);

πŸ” Typical workflow #

  1. ▢️ Start a diagnostic session.
  2. πŸ“ˆ Reproduce the performance issue or user-reported bug.
  3. 🧭 Navigate through the relevant screens.
  4. ⏹️ Stop the session and generate the report.
  5. πŸ“„ Inspect or share the PDF, depending on your configuration.

πŸ“„ PDF Diagnostic Reports #

Generate a report to help investigate performance issues and reproduce bugs.

Depending on the data collected and platform support, reports can include:

  • πŸ“± Device and operating-system information.
  • ⚑ CPU and 🧠 memory measurements.
  • 🎬 Frame-performance observations.
  • 🌐 Recorded network byte metrics.
  • 🧭 Screen visits and session timing.
  • πŸ“‹ Diagnostic samples and summary information.

πŸ“ Reports contain diagnostic data from the recorded session. Review the contents before sharing them, especially if they may reveal information about your application or its usage.

🧭 Route Tracking #

Add the package's route observer to your MaterialApp:

MaterialApp(
  navigatorObservers: [
    DeviceDiagnostics.routeObserver,
  ],
  home: const MyHomePage(),
);

This allows the package to observe supported navigation events and associate diagnostic activity with routes.

πŸ’‘ For the clearest route names, use named routes where appropriate. Route attribution may depend on how navigation is implemented.

πŸ“± Platform Support #

Platform support depends on the metric and the underlying operating-system APIs.

Metric πŸ€– Android 🍎 iOS
Device information βœ… Supported fields βœ… Supported fields
Memory usage βœ… Where available βœ… Where available
Process CPU estimate βœ… Where available βœ… Where available
Network type βœ… Where available βœ… Where available
Network byte counters βœ… Where available ⚠️ May be unavailable
Thermal state βœ… On supported Android versions βœ… On supported iOS versions
Frame monitoring πŸ“Š Flutter-side monitoring πŸ“Š Flutter-side monitoring
PDF report generation πŸ“„ Subject to package/platform support πŸ“„ Subject to package/platform support

Legend: βœ… Available where implemented Β· ⚠️ Limited or unavailable Β· πŸ“Š Collected by Flutter-side instrumentation

πŸ—οΈ Architecture Overview #

The package is organized into layers:

  • πŸŽ›οΈ Configuration β€” controls visibility and metric options.
  • 🧠 Diagnostic controller β€” manages session state, sampling, and collected data.
  • πŸ“± Native integrations β€” retrieve platform-specific metrics through a method channel.
  • 🌐 Network instrumentation β€” records HTTP traffic passing through the provided client.
  • 🧭 Route observer β€” tracks supported navigation events.
  • πŸ–₯️ Diagnostic overlay β€” displays diagnostic controls and information.
  • πŸ“„ Report generator β€” produces PDF diagnostic reports.

πŸ”’ Privacy and Performance Considerations #

  • πŸ” Enable diagnostics intentionally, especially in Release builds.
  • πŸ“‹ Review diagnostic reports before sharing them.
  • 🌐 Remember that only traffic passing through the instrumented client can be counted by that client.
  • βš™οΈ Choose a sampling interval suitable for your workload.
  • πŸ§ͺ Validate performance and metric behavior on real devices.
  • πŸ›‘οΈ Do not use UI visibility settings as access control for sensitive diagnostic information.

πŸ› οΈ Troubleshooting #

❓ The diagnostic overlay is not visible #

  • βœ… Verify that the selected DiagnosticVisibility matches the current build mode.
  • βš™οΈ Initialize the package before runApp().
  • 🧩 Ensure your app is wrapped using DeviceDiagnostics.observability().
  • πŸ”Ž Confirm that the idle floating button setting matches your expectations.

❓ Some metrics are missing #

  • πŸ“± Support varies by platform and operating-system version.
  • πŸ” Some native APIs require permissions or return unavailable values.
  • 🌐 iOS network byte counters may not be available through the current implementation.
  • πŸ§ͺ Test on a physical device when emulator results are incomplete.

❓ No network activity is recorded #

  • 🌐 Make requests through DiagnosticHttpClient.
  • πŸ”Ž Confirm that network monitoring is enabled.
  • ⚠️ Traffic from unrelated clients and networking APIs may not be captured.

πŸ§‘β€πŸ’» Development #

Run the project's checks before submitting changes:

flutter pub get
flutter analyze
flutter test
flutter pub publish --dry-run

πŸ—ΊοΈ Roadmap #

Potential future improvements include:

  • πŸ“ˆ More diagnostic visualizations.
  • πŸ§ͺ Expanded automated tests.
  • πŸ“± Broader platform-specific metric support.
  • πŸ“„ Additional report customization.
  • πŸ” More detailed performance insights.

🀝 Contributing #

Contributions, bug reports, and feature suggestions are welcome!

  1. 🍴 Fork the repository.
  2. 🌿 Create a feature branch.
  3. πŸ› οΈ Implement and test your changes.
  4. πŸ“¬ Submit a pull request with a clear description.

πŸ“¬ Support #

Found a bug or have a feature request?

πŸ“œ License #

This package is distributed under the MIT License.


Made with ❀️ and Flutter by Rajat Das.

3
likes
0
points
314
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for opt-in device diagnostics, performance monitoring, network instrumentation, and PDF diagnostic reports.

Repository (GitHub)
View/report issues

Topics

#diagnostics #performance #monitoring #flutter #debugging

License

unknown (license)

Dependencies

device_info_plus, flutter, http, path_provider, pdf, share_plus

More

Packages that depend on device_diagnostics

Packages that implement device_diagnostics