Gallery demo start-time performance test (#3655)
* Gallery demo start-time performance test
This commit is contained in:
@@ -15,7 +15,8 @@ export 'src/driver.dart' show
|
||||
find,
|
||||
CommonFinders,
|
||||
EvaluatorFunction,
|
||||
FlutterDriver;
|
||||
FlutterDriver,
|
||||
TracingCategory;
|
||||
|
||||
export 'src/error.dart' show
|
||||
DriverError,
|
||||
|
||||
@@ -15,13 +15,39 @@ import 'health.dart';
|
||||
import 'message.dart';
|
||||
import 'timeline.dart';
|
||||
|
||||
enum TracingCategory {
|
||||
all, api, compiler, dart, debugger, embedder, gc, isolate, vm
|
||||
}
|
||||
|
||||
const List<TracingCategory> _defaultCategories = const <TracingCategory>[TracingCategory.all];
|
||||
|
||||
// See https://github.com/dart-lang/sdk/blob/master/runtime/vm/timeline.cc#L32
|
||||
String _tracingCategoriesToString(List<TracingCategory> categories) {
|
||||
final String contents = categories.map((TracingCategory category) {
|
||||
switch(category) {
|
||||
case TracingCategory.all: return 'all';
|
||||
case TracingCategory.api: return 'API';
|
||||
case TracingCategory.compiler: return 'Compiler';
|
||||
case TracingCategory.dart: return 'Dart';
|
||||
case TracingCategory.debugger: return 'Debugger';
|
||||
case TracingCategory.embedder: return 'Embedder';
|
||||
case TracingCategory.gc: return 'GC';
|
||||
case TracingCategory.isolate: return 'Isolate';
|
||||
case TracingCategory.vm: return 'VM';
|
||||
default:
|
||||
throw 'Unknown tracing category $category';
|
||||
}
|
||||
}).join(', ');
|
||||
return '[$contents]';
|
||||
}
|
||||
|
||||
final Logger _log = new Logger('FlutterDriver');
|
||||
|
||||
/// A convenient accessor to frequently used finders.
|
||||
///
|
||||
/// Examples:
|
||||
///
|
||||
/// driver.tap(find.byText('Save'));
|
||||
/// driver.tap(find.text('Save'));
|
||||
/// driver.scroll(find.byValueKey(42));
|
||||
const CommonFinders find = const CommonFinders._();
|
||||
|
||||
@@ -211,15 +237,24 @@ class FlutterDriver {
|
||||
return await _sendCommand(new Scroll(finder, dx, dy, duration, frequency)).then((Map<String, dynamic> _) => null);
|
||||
}
|
||||
|
||||
/// Scrolls the Scrollable ancestor of the widget located by [finder]
|
||||
/// until the widget is completely visible.
|
||||
Future<Null> scrollIntoView(SerializableFinder finder) async {
|
||||
return await _sendCommand(new ScrollIntoView(finder)).then((Map<String, dynamic> _) => null);
|
||||
}
|
||||
|
||||
/// Returns the text in the `Text` widget located by [finder].
|
||||
Future<String> getText(SerializableFinder finder) async {
|
||||
return GetTextResult.fromJson(await _sendCommand(new GetText(finder))).text;
|
||||
}
|
||||
|
||||
/// Starts recording performance traces.
|
||||
Future<Null> startTracing() async {
|
||||
Future<Null> startTracing({List<TracingCategory> categories: _defaultCategories}) async {
|
||||
assert(categories != null && categories.length > 0);
|
||||
try {
|
||||
await _peer.sendRequest(_kSetVMTimelineFlagsMethod, {'recordedStreams': '[all]'});
|
||||
await _peer.sendRequest(_kSetVMTimelineFlagsMethod, {
|
||||
'recordedStreams': _tracingCategoriesToString(categories)
|
||||
});
|
||||
return null;
|
||||
} catch(error, stackTrace) {
|
||||
throw new DriverError(
|
||||
@@ -251,8 +286,8 @@ class FlutterDriver {
|
||||
///
|
||||
/// This is merely a convenience wrapper on top of [startTracing] and
|
||||
/// [stopTracingAndDownloadTimeline].
|
||||
Future<Timeline> traceAction(Future<dynamic> action()) async {
|
||||
await startTracing();
|
||||
Future<Timeline> traceAction(Future<dynamic> action(), { List<TracingCategory> categories: _defaultCategories }) async {
|
||||
await startTracing(categories: categories);
|
||||
await action();
|
||||
return stopTracingAndDownloadTimeline();
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ class FlutterDriverExtension {
|
||||
'tap': tap,
|
||||
'get_text': getText,
|
||||
'scroll': scroll,
|
||||
'scrollIntoView': scrollIntoView,
|
||||
'waitFor': waitFor,
|
||||
});
|
||||
|
||||
@@ -71,6 +72,7 @@ class FlutterDriverExtension {
|
||||
'tap': Tap.deserialize,
|
||||
'get_text': GetText.deserialize,
|
||||
'scroll': Scroll.deserialize,
|
||||
'scrollIntoView': ScrollIntoView.deserialize,
|
||||
'waitFor': WaitFor.deserialize,
|
||||
});
|
||||
|
||||
@@ -207,6 +209,12 @@ class FlutterDriverExtension {
|
||||
return new ScrollResult();
|
||||
}
|
||||
|
||||
Future<ScrollResult> scrollIntoView(ScrollIntoView command) async {
|
||||
Finder target = await _waitForElement(_createFinder(command.finder));
|
||||
await Scrollable.ensureVisible(target.evaluate().single);
|
||||
return new ScrollResult();
|
||||
}
|
||||
|
||||
Future<GetTextResult> getText(GetText command) async {
|
||||
Finder target = await _waitForElement(_createFinder(command.finder));
|
||||
// TODO(yjbanov): support more ways to read text
|
||||
|
||||
@@ -73,6 +73,19 @@ class Scroll extends CommandWithTarget {
|
||||
});
|
||||
}
|
||||
|
||||
/// Command the driver to ensure that the element represented by [finder]
|
||||
/// has been scrolled completely into view.
|
||||
class ScrollIntoView extends CommandWithTarget {
|
||||
@override
|
||||
final String kind = 'scrollIntoView';
|
||||
|
||||
ScrollIntoView(SerializableFinder finder) : super(finder);
|
||||
|
||||
static ScrollIntoView deserialize(Map<String, dynamic> json) {
|
||||
return new ScrollIntoView(SerializableFinder.deserialize(json));
|
||||
}
|
||||
}
|
||||
|
||||
class ScrollResult extends Result {
|
||||
static ScrollResult fromJson(Map<String, dynamic> json) {
|
||||
return new ScrollResult();
|
||||
|
||||
@@ -235,6 +235,50 @@ void main() {
|
||||
expect(timeline.events.single.name, 'test event');
|
||||
});
|
||||
});
|
||||
|
||||
group('traceAction categories', () {
|
||||
test('specify non-default categories', () async {
|
||||
bool actionCalled = false;
|
||||
bool startTracingCalled = false;
|
||||
bool stopTracingCalled = false;
|
||||
|
||||
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals({'recordedStreams': '[Dart, GC, Compiler]'}))))
|
||||
.thenAnswer((_) async {
|
||||
startTracingCalled = true;
|
||||
return null;
|
||||
});
|
||||
|
||||
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals({'recordedStreams': '[]'}))))
|
||||
.thenAnswer((_) async {
|
||||
stopTracingCalled = true;
|
||||
return null;
|
||||
});
|
||||
|
||||
when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((_) async {
|
||||
return <String, dynamic> {
|
||||
'traceEvents': [
|
||||
{
|
||||
'name': 'test event'
|
||||
}
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
Timeline timeline = await driver.traceAction(() {
|
||||
actionCalled = true;
|
||||
},
|
||||
categories: const <TracingCategory>[
|
||||
TracingCategory.dart,
|
||||
TracingCategory.gc,
|
||||
TracingCategory.compiler
|
||||
]);
|
||||
|
||||
expect(actionCalled, isTrue);
|
||||
expect(startTracingCalled, isTrue);
|
||||
expect(stopTracingCalled, isTrue);
|
||||
expect(timeline.events.single.name, 'test event');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user