clear timeline events prior to starting a new action (#12984)
* clear timeline events prior to starting a new action * trailing commas
This commit is contained in:
@@ -127,6 +127,7 @@ class FlutterDriver {
|
||||
static const String _kFlutterExtensionMethod = 'ext.flutter.driver';
|
||||
static const String _kSetVMTimelineFlagsMethod = '_setVMTimelineFlags';
|
||||
static const String _kGetVMTimelineMethod = '_getVMTimeline';
|
||||
static const String _kClearVMTimelineMethod = '_clearVMTimeline';
|
||||
|
||||
static int _nextDriverId = 0;
|
||||
|
||||
@@ -182,9 +183,9 @@ class FlutterDriver {
|
||||
}
|
||||
|
||||
final FlutterDriver driver = new FlutterDriver.connectedTo(
|
||||
client, connection.peer, isolate,
|
||||
printCommunication: printCommunication,
|
||||
logCommunicationToFile: logCommunicationToFile
|
||||
client, connection.peer, isolate,
|
||||
printCommunication: printCommunication,
|
||||
logCommunicationToFile: logCommunicationToFile,
|
||||
);
|
||||
|
||||
// Attempts to resume the isolate, but does not crash if it fails because
|
||||
@@ -327,13 +328,13 @@ class FlutterDriver {
|
||||
throw new DriverError(
|
||||
'Failed to fulfill ${command.runtimeType}: Flutter application not responding',
|
||||
error,
|
||||
stackTrace
|
||||
stackTrace,
|
||||
);
|
||||
} catch (error, stackTrace) {
|
||||
throw new DriverError(
|
||||
'Failed to fulfill ${command.runtimeType} due to remote error',
|
||||
error,
|
||||
stackTrace
|
||||
stackTrace,
|
||||
);
|
||||
}
|
||||
if (response['isError'])
|
||||
@@ -503,7 +504,10 @@ class FlutterDriver {
|
||||
}
|
||||
|
||||
/// Starts recording performance traces.
|
||||
Future<Null> startTracing({ List<TimelineStream> streams: _defaultStreams, Duration timeout: _kShortTimeout }) async {
|
||||
Future<Null> startTracing({
|
||||
List<TimelineStream> streams: _defaultStreams,
|
||||
Duration timeout: _kShortTimeout,
|
||||
}) async {
|
||||
assert(streams != null && streams.isNotEmpty);
|
||||
try {
|
||||
await _peer.sendRequest(_kSetVMTimelineFlagsMethod, <String, String>{
|
||||
@@ -514,7 +518,7 @@ class FlutterDriver {
|
||||
throw new DriverError(
|
||||
'Failed to start tracing due to remote error',
|
||||
error,
|
||||
stackTrace
|
||||
stackTrace,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -530,7 +534,7 @@ class FlutterDriver {
|
||||
throw new DriverError(
|
||||
'Failed to stop tracing due to remote error',
|
||||
error,
|
||||
stackTrace
|
||||
stackTrace,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -545,12 +549,38 @@ class FlutterDriver {
|
||||
///
|
||||
/// [streams] limits the recorded timeline event streams to only the ones
|
||||
/// listed. By default, all streams are recorded.
|
||||
Future<Timeline> traceAction(Future<dynamic> action(), { List<TimelineStream> streams: _defaultStreams }) async {
|
||||
///
|
||||
/// If [retainPriorEvents] is true, retains events recorded prior to calling
|
||||
/// [action]. Otherwise, prior events are cleared before calling [action]. By
|
||||
/// default, prior events are cleared.
|
||||
Future<Timeline> traceAction(
|
||||
Future<dynamic> action(), {
|
||||
List<TimelineStream> streams: _defaultStreams,
|
||||
bool retainPriorEvents: false,
|
||||
}) async {
|
||||
if (!retainPriorEvents) {
|
||||
await clearTimeline();
|
||||
}
|
||||
await startTracing(streams: streams);
|
||||
await action();
|
||||
return stopTracingAndDownloadTimeline();
|
||||
}
|
||||
|
||||
/// Clears all timeline events recorded up until now.
|
||||
Future<Null> clearTimeline({ Duration timeout: _kShortTimeout }) async {
|
||||
try {
|
||||
await _peer
|
||||
.sendRequest(_kClearVMTimelineMethod, <String, String>{})
|
||||
.timeout(timeout);
|
||||
} catch(error, stackTrace) {
|
||||
throw new DriverError(
|
||||
'Failed to clear event timeline due to remote error',
|
||||
error,
|
||||
stackTrace,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// [action] will be executed with the frame sync mechanism disabled.
|
||||
///
|
||||
/// By default, Flutter Driver waits until there is no pending frame scheduled
|
||||
|
||||
@@ -230,25 +230,45 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('clearTimeline', () {
|
||||
test('clears timeline', () async {
|
||||
bool clearWasCalled = false;
|
||||
when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals(<String, dynamic>{}))))
|
||||
.thenAnswer((_) async {
|
||||
clearWasCalled = true;
|
||||
return null;
|
||||
});
|
||||
await driver.clearTimeline();
|
||||
expect(clearWasCalled, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('traceAction', () {
|
||||
test('traces action', () async {
|
||||
bool actionCalled = false;
|
||||
bool startTracingCalled = false;
|
||||
bool stopTracingCalled = false;
|
||||
List<String> log;
|
||||
|
||||
setUp(() async {
|
||||
log = <String>[];
|
||||
|
||||
when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals(<String, dynamic>{}))))
|
||||
.thenAnswer((_) async {
|
||||
log.add('clear');
|
||||
return null;
|
||||
});
|
||||
|
||||
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[all]'}))))
|
||||
.thenAnswer((_) async {
|
||||
startTracingCalled = true;
|
||||
return null;
|
||||
});
|
||||
.thenAnswer((_) async {
|
||||
log.add('startTracing');
|
||||
return null;
|
||||
});
|
||||
|
||||
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[]'}))))
|
||||
.thenAnswer((_) async {
|
||||
stopTracingCalled = true;
|
||||
return null;
|
||||
});
|
||||
.thenAnswer((_) async {
|
||||
log.add('stopTracing');
|
||||
return null;
|
||||
});
|
||||
|
||||
when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((_) async {
|
||||
log.add('download');
|
||||
return <String, dynamic> {
|
||||
'traceEvents': <dynamic>[
|
||||
<String, String>{
|
||||
@@ -257,14 +277,34 @@ void main() {
|
||||
],
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
test('without clearing timeline', () async {
|
||||
final Timeline timeline = await driver.traceAction(() {
|
||||
actionCalled = true;
|
||||
log.add('action');
|
||||
}, retainPriorEvents: true);
|
||||
|
||||
expect(log, const <String>[
|
||||
'startTracing',
|
||||
'action',
|
||||
'stopTracing',
|
||||
'download',
|
||||
]);
|
||||
expect(timeline.events.single.name, 'test event');
|
||||
});
|
||||
|
||||
test('with clearing timeline', () async {
|
||||
final Timeline timeline = await driver.traceAction(() {
|
||||
log.add('action');
|
||||
});
|
||||
|
||||
expect(actionCalled, isTrue);
|
||||
expect(startTracingCalled, isTrue);
|
||||
expect(stopTracingCalled, isTrue);
|
||||
expect(log, const <String>[
|
||||
'clear',
|
||||
'startTracing',
|
||||
'action',
|
||||
'stopTracing',
|
||||
'download',
|
||||
]);
|
||||
expect(timeline.events.single.name, 'test event');
|
||||
});
|
||||
});
|
||||
@@ -304,7 +344,8 @@ void main() {
|
||||
TimelineStream.dart,
|
||||
TimelineStream.gc,
|
||||
TimelineStream.compiler
|
||||
]);
|
||||
],
|
||||
retainPriorEvents: true);
|
||||
|
||||
expect(actionCalled, isTrue);
|
||||
expect(startTracingCalled, isTrue);
|
||||
|
||||
Reference in New Issue
Block a user