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
d6d35ca7
Unverified
Commit
d6d35ca7
authored
May 29, 2018
by
Todd Volkert
Committed by
GitHub
May 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address post-review comments from #17977 (#18000)
parent
c7ea3ca3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
53 deletions
+18
-53
debug.dart
packages/flutter/lib/src/foundation/debug.dart
+16
-29
debug_test.dart
packages/flutter/test/foundation/debug_test.dart
+2
-24
No files found.
packages/flutter/lib/src/foundation/debug.dart
View file @
d6d35ca7
...
...
@@ -42,38 +42,25 @@ bool debugInstrumentationEnabled = false;
/// non-debug builds, or when [debugInstrumentationEnabled] is false, this will
/// run [action] without any instrumentation.
///
/// Returns the result of running [action]
, wrapped in a `Future` if the action
///
was synchronous.
Future
<
T
>
debugInstrumentAction
<
T
>(
String
description
,
FutureOr
<
T
>
action
())
{
if
(!
debugInstrumentationEnabled
)
return
new
Future
<
T
>.
value
(
action
());
Stopwatch
stopwatch
;
assert
((
)
{
stopwatch
=
new
Stopwatch
()..
start
()
;
return
true
;
}
());
void
stopStopwatchAndPrintElapsed
()
{
assert
(()
{
/// Returns the result of running [action]
.
///
/// See also:
///
/// * [Timeline], which is used to record synchronous tracing events for
/// visualization in Chrome's tracing format. This method does not
/// implicitly add any timeline events.
Future
<
T
>
debugInstrumentAction
<
T
>(
String
description
,
Future
<
T
>
action
()
)
{
bool
instrument
=
false
;
assert
(()
{
instrument
=
debugInstrumentationEnabled
;
return
true
;
}())
;
if
(
instrument
)
{
final
Stopwatch
stopwatch
=
new
Stopwatch
()..
start
();
return
action
().
whenComplete
(()
{
stopwatch
.
stop
();
debugPrint
(
'Action "
$description
" took
${stopwatch.elapsed}
'
);
return
true
;
}());
}
Future
<
T
>
returnResult
;
FutureOr
<
T
>
actionResult
;
try
{
actionResult
=
action
();
}
finally
{
if
(
actionResult
is
Future
<
T
>)
{
returnResult
=
actionResult
.
whenComplete
(
stopStopwatchAndPrintElapsed
);
}
else
{
stopStopwatchAndPrintElapsed
();
returnResult
=
new
Future
<
T
>.
value
(
actionResult
);
}
});
}
else
{
return
action
();
}
return
returnResult
;
}
/// Arguments to whitelist [Timeline] events in order to be shown in the
...
...
packages/flutter/test/foundation/debug_test.dart
View file @
d6d35ca7
...
...
@@ -24,19 +24,7 @@ void main() {
debugPrint
=
originalDebugPrintCallback
;
});
test
(
'works with sync actions'
,
()
async
{
final
int
result
=
await
debugInstrumentAction
<
int
>(
'no-op'
,
()
{
debugPrint
(
'action()'
);
return
1
;
});
expect
(
result
,
1
);
expect
(
printBuffer
.
toString
(),
matches
(
new
RegExp
(
'^action
\\
(
\\
)
\n
Action "no-op" took .+
\$
'
,
multiLine:
true
)),
);
});
test
(
'works with async actions'
,
()
async
{
test
(
'works with non-failing actions'
,
()
async
{
final
int
result
=
await
debugInstrumentAction
<
int
>(
'no-op'
,
()
async
{
debugPrint
(
'action()'
);
return
1
;
...
...
@@ -48,17 +36,7 @@ void main() {
);
});
test
(
'throws if sync action throws'
,
()
{
try
{
debugInstrumentAction
<
void
>(
'throws'
,
()
=>
throw
'Error'
);
fail
(
'Error expected but not thrown'
);
}
on
String
catch
(
error
)
{
expect
(
error
,
'Error'
);
expect
(
printBuffer
.
toString
(),
matches
(
r'^Action "throws" took .+'
));
}
});
test
(
'returns failing future if async action throws'
,
()
async
{
test
(
'returns failing future if action throws'
,
()
async
{
try
{
await
debugInstrumentAction
<
void
>(
'throws'
,
()
async
{
await
new
Future
<
void
>.
delayed
(
Duration
.
zero
);
...
...
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