Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
26c41773
Commit
26c41773
authored
Mar 07, 2016
by
yjbanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[driver] API for getting performance traces
parent
7012d522
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
18 deletions
+83
-18
scroll_perf.dart
examples/stocks/test_driver/scroll_perf.dart
+0
-2
scroll_perf_test.dart
examples/stocks/test_driver/scroll_perf_test.dart
+23
-16
driver.dart
packages/flutter_driver/lib/src/driver.dart
+60
-0
No files found.
examples/stocks/test_driver/scroll_perf.dart
View file @
26c41773
...
...
@@ -3,11 +3,9 @@
// found in the LICENSE file.
import
'package:flutter_driver/driver_extension.dart'
;
import
'package:flutter_driver/src/error.dart'
;
import
'package:stocks/main.dart'
as
app
;
void
main
(
)
{
flutterDriverLog
.
listen
(
print
);
enableFlutterDriverExtension
();
app
.
main
();
}
examples/stocks/test_driver/scroll_perf_test.dart
View file @
26c41773
...
...
@@ -19,22 +19,29 @@ void main() {
driver
.
close
();
});
test
(
'tap on the floating action button; verify counter'
,
()
async
{
// Find the scrollable stock list
ObjectRef
stockList
=
await
driver
.
findByValueKey
(
'stock-list'
);
expect
(
stockList
,
isNotNull
);
// Scroll down 5 times
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
await
driver
.
scroll
(
stockList
,
0.0
,
-
300.0
,
new
Duration
(
milliseconds:
300
));
await
new
Future
<
Null
>.
delayed
(
new
Duration
(
milliseconds:
500
));
}
// Scroll up 5 times
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
await
driver
.
scroll
(
stockList
,
0.0
,
300.0
,
new
Duration
(
milliseconds:
300
));
await
new
Future
<
Null
>.
delayed
(
new
Duration
(
milliseconds:
500
));
}
test
(
'measure'
,
()
async
{
Map
<
String
,
dynamic
>
profileJson
=
await
driver
.
traceAction
(()
async
{
// Find the scrollable stock list
ObjectRef
stockList
=
await
driver
.
findByValueKey
(
'stock-list'
);
expect
(
stockList
,
isNotNull
);
// Scroll down
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
await
driver
.
scroll
(
stockList
,
0.0
,
-
300.0
,
new
Duration
(
milliseconds:
300
));
await
new
Future
<
Null
>.
delayed
(
new
Duration
(
milliseconds:
500
));
}
// Scroll up
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
await
driver
.
scroll
(
stockList
,
0.0
,
300.0
,
new
Duration
(
milliseconds:
300
));
await
new
Future
<
Null
>.
delayed
(
new
Duration
(
milliseconds:
500
));
}
});
// Usually the profile is saved to a file and then analyzed using
// chrom://tracing or a script. Both are out of scope for this little
// test, so all we do is check that we received something.
expect
(
profileJson
,
isNotNull
);
});
});
}
packages/flutter_driver/lib/src/driver.dart
View file @
26c41773
...
...
@@ -29,6 +29,9 @@ class FlutterDriver {
FlutterDriver
.
connectedTo
(
this
.
_serviceClient
,
this
.
_appIsolate
);
static
const
String
_kFlutterExtensionMethod
=
'ext.flutter_driver'
;
static
const
String
_kStartTracingMethod
=
'ext.flutter_startTracing'
;
static
const
String
_kStopTracingMethod
=
'ext.flutter_stopTracing'
;
static
const
String
_kDownloadTraceDataMethod
=
'ext.flutter_downloadTraceData'
;
static
const
Duration
_kDefaultTimeout
=
const
Duration
(
seconds:
5
);
static
const
Duration
_kDefaultPauseBetweenRetries
=
const
Duration
(
milliseconds:
160
);
...
...
@@ -205,6 +208,63 @@ class FlutterDriver {
return
result
.
text
;
}
/// Starts recording performance traces.
Future
<
Null
>
startTracing
()
async
{
try
{
await
_appIsolate
.
invokeExtension
(
_kStartTracingMethod
);
return
null
;
}
catch
(
error
,
stackTrace
)
{
throw
new
DriverError
(
'Failed to start tracing due to remote error'
,
error
,
stackTrace
);
}
}
/// Stops recording performance traces and downloads the trace profile.
// TODO(yjbanov): return structured data rather than raw JSON once we have a
// stable protocol to talk to.
Future
<
Map
<
String
,
dynamic
>>
stopTracingAndDownloadProfile
()
async
{
Map
<
String
,
dynamic
>
stopResult
=
await
_appIsolate
.
invokeExtension
(
_kStopTracingMethod
);
String
traceFilePath
=
stopResult
[
'trace_file_path'
];
// Tracing data isn't available immediately as some of it is queued up in
// the event loop.
Stopwatch
sw
=
new
Stopwatch
()..
start
();
while
(
sw
.
elapsed
<
const
Duration
(
seconds:
30
))
{
Map
<
String
,
dynamic
>
downloadResult
=
await
_appIsolate
.
invokeExtension
(
_kDownloadTraceDataMethod
,
<
String
,
String
>{
'trace_file_path'
:
traceFilePath
,
});
if
(
downloadResult
[
'success'
]
==
false
)
throw
new
DriverError
(
'Failed to download trace file:
$traceFilePath
'
);
else
if
(
downloadResult
[
'status'
]
!=
'not ready'
)
return
downloadResult
;
// Give the event loop a chance to flush the trace log
await
new
Future
<
Null
>.
delayed
(
const
Duration
(
milliseconds:
200
));
}
throw
new
DriverError
(
'Timed out waiting for tracing profile to become ready for download.'
);
}
/// Runs [action] and outputs a performance trace for it.
///
/// Waits for the `Future` returned by [action] to complete prior to stopping
/// the trace.
///
/// This is merely a convenience wrapper on top of [startTracing] and
/// [stopTracingAndDownloadProfile].
Future
<
Map
<
String
,
dynamic
>>
traceAction
(
Future
<
dynamic
>
action
())
async
{
await
startTracing
();
await
action
();
return
stopTracingAndDownloadProfile
();
}
/// Calls the [evaluator] repeatedly until the result of the evaluation
/// satisfies the [matcher].
///
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment