Skip to content

Commit

Permalink
feat: Implement GlanceNoOpImpl in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
littleGnAl committed Oct 1, 2024
1 parent facf5d7 commit 08a9dac
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ An APM library for detecting UI jank in Flutter for mobile (Android/iOS).

**NOTE:** This package is experimental. APIs may change without notice before the stable version 1.0.

`glance` detects UI jank during the build phase and from "external sources", such as `WidgetBindingObserver` callbacks, touch events, and method channel callbacks. These cover most cases that cause UI jank. It works only when you build your application with the `--split-debug-info` option, see https://docs.flutter.dev/deployment/obfuscate#obfuscate-your-app for more detail.

Run `glance` in release or profile build, as detecting UI jank in debug mode is not meaningful.
`glance` detects UI jank during the build phase as well as through various callbacks, such as, `WidgetBindingObserver` callbacks, touch events, and method channel callbacks. These cover most cases that cause UI jank. It works only in release or profile builds when your application is built with the [`--split-debug-info` option](https://docs.flutter.dev/deployment/obfuscate#obfuscate-your-app).

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion lib/src/glance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ abstract class Glance {

static Glance? _instance;
static Glance get instance {
_instance ??= GlanceImpl();
_instance ??= GlanceImpl.create(kDebugMode);
return _instance!;
}

Expand Down
20 changes: 19 additions & 1 deletion lib/src/glance_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,27 @@ import 'package:glance/src/glance.dart';
import 'package:glance/src/sampler.dart';
import 'package:meta/meta.dart' show visibleForTesting, internal;

/// No-op implementation of [Glance].
class GlanceNoOpImpl implements Glance {
@override
Future<void> end() async {}

@override
Future<void> start(
{GlanceConfiguration config = const GlanceConfiguration()}) async {}
}

/// Implementation of [Glance]
class GlanceImpl implements Glance {
GlanceImpl();
static Glance create(bool isNoOp) {
if (isNoOp) {
return GlanceNoOpImpl();
}

return GlanceImpl._();
}

GlanceImpl._();

@visibleForTesting
GlanceImpl.forTesting(Sampler sampler) : _sampler = sampler;
Expand Down
12 changes: 12 additions & 0 deletions test/glance_impl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ void main() {
glance = GlanceImpl.forTesting(sampler);
});

group('GlanceImpl.create', () {
test('return GlanceImpl', () {
final instance = GlanceImpl.create(false);
expect(instance, isInstanceOf<GlanceImpl>());
});

test('return GlanceNoOpImpl', () {
final instance = GlanceImpl.create(true);
expect(instance, isInstanceOf<GlanceNoOpImpl>());
});
});

group('GlanceWidgetBindingMixin', () {
test(
'call onCheckJank when calling traceFunctionCall if it is in SchedulerPhase.idle',
Expand Down

0 comments on commit 08a9dac

Please sign in to comment.