Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement GlanceNoOpImpl in debug mode #39

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading