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
208d312f
Unverified
Commit
208d312f
authored
Aug 20, 2021
by
keyonghan
Committed by
GitHub
Aug 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload devicelab test metrics from test runner (#88447)
parent
9f9aa46b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
149 additions
and
1 deletion
+149
-1
upload_results.dart
dev/devicelab/lib/command/upload_results.dart
+16
-0
metrics_center.dart
dev/devicelab/lib/framework/metrics_center.dart
+94
-0
pubspec.yaml
dev/devicelab/pubspec.yaml
+7
-1
metrics_center_test.dart
dev/devicelab/test/metrics_center_test.dart
+32
-0
No files found.
dev/devicelab/lib/command/upload_results.dart
View file @
208d312f
...
...
@@ -5,6 +5,7 @@
import
'package:args/command_runner.dart'
;
import
'../framework/cocoon.dart'
;
import
'../framework/metrics_center.dart'
;
class
UploadResultsCommand
extends
Command
<
void
>
{
UploadResultsCommand
()
{
...
...
@@ -21,6 +22,7 @@ class UploadResultsCommand extends Command<void> {
);
argParser
.
addOption
(
'luci-builder'
,
help:
'[Flutter infrastructure] Name of the LUCI builder being run on.'
);
argParser
.
addOption
(
'test-status'
,
help:
'Test status: Succeeded|Failed'
);
argParser
.
addOption
(
'commit-time'
,
help:
'Commit time in UNIX timestamp'
);
}
@override
...
...
@@ -37,6 +39,20 @@ class UploadResultsCommand extends Command<void> {
final
String
?
gitBranch
=
argResults
![
'git-branch'
]
as
String
?;
final
String
?
builderName
=
argResults
![
'luci-builder'
]
as
String
?;
final
String
?
testStatus
=
argResults
![
'test-status'
]
as
String
?;
final
String
?
commitTime
=
argResults
![
'commit-time'
]
as
String
?;
// Upload metrics to metrics_center from test runner when `commitTime` is specified. This
// is mainly for testing purpose.
// The upload step will be skipped from cocoon once this is validated.
// TODO(keyong): remove try block to block test when this is validated to work https://github.com/flutter/flutter/issues/88484
try
{
if
(
commitTime
!=
null
)
{
await
uploadToMetricsCenter
(
resultsPath
,
commitTime
);
print
(
'Successfully uploaded metrics to metrics center'
);
}
}
on
Exception
catch
(
e
,
stacktrace
)
{
print
(
'Uploading metrics failure:
$e
\n\n
$stacktrace
'
);
}
final
Cocoon
cocoon
=
Cocoon
(
serviceAccountTokenPath:
serviceAccountTokenFile
);
return
cocoon
.
sendResultsPath
(
...
...
dev/devicelab/lib/framework/metrics_center.dart
0 → 100644
View file @
208d312f
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:convert'
;
import
'dart:io'
;
import
'package:metrics_center/metrics_center.dart'
;
/// Authenticate and connect to gcloud storage.
///
/// It supports both token and credential authentications.
Future
<
FlutterDestination
>
connectFlutterDestination
()
async
{
const
String
kTokenPath
=
'TOKEN_PATH'
;
const
String
kGcpProject
=
'GCP_PROJECT'
;
final
Map
<
String
,
String
>
env
=
Platform
.
environment
;
final
bool
isTesting
=
env
[
'IS_TESTING'
]
==
'true'
;
if
(
env
.
containsKey
(
kTokenPath
)
&&
env
.
containsKey
(
kGcpProject
))
{
return
FlutterDestination
.
makeFromAccessToken
(
File
(
env
[
kTokenPath
]!).
readAsStringSync
(),
env
[
kGcpProject
]!,
isTesting:
isTesting
,
);
}
return
FlutterDestination
.
makeFromCredentialsJson
(
jsonDecode
(
env
[
'BENCHMARK_GCP_CREDENTIALS'
]!)
as
Map
<
String
,
dynamic
>,
isTesting:
isTesting
,
);
}
/// Parse results into Metric Points.
///
/// An example of `resultsJson`:
/// {
/// "CommitBranch": "master",
/// "CommitSha": "abc",
/// "BuilderName": "test",
/// "ResultData": {
/// "average_frame_build_time_millis": 0.4550425531914895,
/// "90th_percentile_frame_build_time_millis": 0.473
/// },
/// "BenchmarkScoreKeys": [
/// "average_frame_build_time_millis",
/// "90th_percentile_frame_build_time_millis"
/// ]
/// }
List
<
MetricPoint
>
parse
(
Map
<
String
,
dynamic
>
resultsJson
)
{
final
List
<
String
>
scoreKeys
=
(
resultsJson
[
'BenchmarkScoreKeys'
]
as
List
<
dynamic
>).
cast
<
String
>();
final
Map
<
String
,
dynamic
>
resultData
=
resultsJson
[
'ResultData'
]
as
Map
<
String
,
dynamic
>;
final
String
gitBranch
=
(
resultsJson
[
'CommitBranch'
]
as
String
).
trim
();
final
String
gitSha
=
(
resultsJson
[
'CommitSha'
]
as
String
).
trim
();
final
String
builderName
=
resultsJson
[
'BuilderName'
]
as
String
;
final
List
<
MetricPoint
>
metricPoints
=
<
MetricPoint
>[];
for
(
final
String
scoreKey
in
scoreKeys
)
{
metricPoints
.
add
(
MetricPoint
(
(
resultData
[
scoreKey
]
as
num
).
toDouble
(),
<
String
,
String
>{
kGithubRepoKey:
kFlutterFrameworkRepo
,
kGitRevisionKey:
gitSha
,
'branch'
:
gitBranch
,
kNameKey:
builderName
,
kSubResultKey:
scoreKey
,
},
),
);
}
return
metricPoints
;
}
/// Upload test metrics to metrics center.
Future
<
void
>
uploadToMetricsCenter
(
String
?
resultsPath
,
String
?
commitTime
)
async
{
int
commitTimeSinceEpoch
;
if
(
resultsPath
==
null
)
{
return
;
}
if
(
commitTime
!=
null
)
{
commitTimeSinceEpoch
=
1000
*
int
.
parse
(
commitTime
);
}
else
{
commitTimeSinceEpoch
=
DateTime
.
now
().
millisecondsSinceEpoch
;
}
final
File
resultFile
=
File
(
resultsPath
);
Map
<
String
,
dynamic
>
resultsJson
=
<
String
,
dynamic
>{};
resultsJson
=
json
.
decode
(
await
resultFile
.
readAsString
())
as
Map
<
String
,
dynamic
>;
final
List
<
MetricPoint
>
metricPoints
=
parse
(
resultsJson
);
final
FlutterDestination
metricsDestination
=
await
connectFlutterDestination
();
await
metricsDestination
.
update
(
metricPoints
,
DateTime
.
fromMillisecondsSinceEpoch
(
commitTimeSinceEpoch
,
isUtc:
true
,
),
);
}
dev/devicelab/pubspec.yaml
View file @
208d312f
...
...
@@ -11,6 +11,7 @@ dependencies:
file
:
6.1.2
http
:
0.13.3
meta
:
1.7.0
metrics_center
:
1.0.0
path
:
1.8.0
platform
:
3.0.2
process
:
4.2.3
...
...
@@ -19,11 +20,16 @@ dependencies:
logging
:
1.0.1
_discoveryapis_commons
:
1.0.1
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
async
:
2.8.2
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
charcode
:
1.3.1
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
checked_yaml
:
2.0.1
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
collection
:
1.15.0
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
crypto
:
3.0.1
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
equatable
:
2.0.3
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
gcloud
:
0.8.2
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
googleapis
:
3.0.0
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
googleapis_auth
:
1.1.0
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
http_parser
:
4.0.0
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
json_annotation
:
4.1.0
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pedantic
:
1.11.1
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
...
...
@@ -67,4 +73,4 @@ dev_dependencies:
web_socket_channel
:
2.1.0
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
webkit_inspection_protocol
:
1.0.0
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM:
109
4
# PUBSPEC CHECKSUM:
362
4
dev/devicelab/test/metrics_center_test.dart
0 → 100644
View file @
208d312f
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_devicelab/framework/metrics_center.dart'
;
import
'package:metrics_center/metrics_center.dart'
;
import
'common.dart'
;
void
main
(
)
{
group
(
'Parse'
,
()
{
test
(
'succeeds'
,
()
{
final
Map
<
String
,
dynamic
>
results
=
<
String
,
dynamic
>{
'CommitBranch'
:
'master'
,
'CommitSha'
:
'abc'
,
'BuilderName'
:
'test'
,
'ResultData'
:
<
String
,
dynamic
>{
'average_frame_build_time_millis'
:
0.4550425531914895
,
'90th_percentile_frame_build_time_millis'
:
0.473
},
'BenchmarkScoreKeys'
:
<
String
>[
'average_frame_build_time_millis'
,
'90th_percentile_frame_build_time_millis'
]
};
final
List
<
MetricPoint
>
metricPoints
=
parse
(
results
);
expect
(
metricPoints
[
0
].
value
,
equals
(
0.4550425531914895
));
expect
(
metricPoints
[
1
].
value
,
equals
(
0.473
));
});
});
}
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