Update coverage tool.
Makes the code strong-clean and use the new hook added in https://dart-review.googlesource.com/c/sdk/+/84880
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9299f56..07f3f77 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.5.14
+* Updates `coverage_log_server.dart` and `live_code_size_analysis.dart` to make
+ them strong clean and match the latest changes in dart2js.
+
## 0.5.13
* Use a more efficient `Map` implementation for decoding existing info files.
diff --git a/README.md b/README.md
index 385ceb7..902f195 100644
--- a/README.md
+++ b/README.md
@@ -431,16 +431,14 @@
Coverage information requires a bit more setup and work to get them running. The
steps are as follows:
- * Compile an app with dart2js using `--dump-info` and defining the
- Dart environment `traceCalls=post`:
+ * Compile an app with dart2js using `--dump-info` and
+ `--experiment-call-instrumentation`
```console
-$ DART_VM_OPTIONS="-DtraceCalls=post" dart2js --dump-info main.dart
+$ dart2js --dump-info --experiment-call-instrumentation main.dart
```
- Because coverage/tracing data is currently experimental, the feature is
- not exposed as a flag in dart2js, but you can enable it using the Dart
- environment flag. The flag only works dart2js version 1.13.0-dev.0.0 or newer.
+ The flag only works dart2js version 2.2.0 or newer.
* Launch the coverage server tool to serve up the JS code of your app:
diff --git a/bin/coverage_log_server.dart b/bin/coverage_log_server.dart
index 42cc32c..bda7f14 100644
--- a/bin/coverage_log_server.dart
+++ b/bin/coverage_log_server.dart
@@ -115,7 +115,7 @@
_expectedPath(String tail) => prefix == '' ? tail : '$prefix/$tail';
- _handler(shelf.Request request) async {
+ FutureOr<shelf.Response> _handler(shelf.Request request) async {
var urlPath = request.url.path;
print('received request: $urlPath');
var baseJsName = path.basename(jsPath);
@@ -187,9 +187,25 @@
}
_adjustRequestUrl(String code, String prefix) {
- var newUrl = prefix == '' ? 'coverage' : '$prefix/coverage';
- return code.replaceFirst('"/coverage_uri_to_amend_by_server"',
- '"/$newUrl" /*url-prefix updated!*/');
+ var url = prefix == '' ? 'coverage' : '$prefix/coverage';
+ var hook = '''
+ self.dartCallInstrumentation = function(id, name) {
+ if (!this.traceBuffer) {
+ this.traceBuffer = [];
+ }
+ var buffer = this.traceBuffer;
+ if (buffer.length == 0) {
+ window.setTimeout(function() {
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", "/$url");
+ xhr.send(JSON.stringify(buffer));
+ buffer.length = 0;
+ }, 1000);
+ }
+ buffer.push([id, name]);
+ };
+ ''';
+ return '$hook$code';
}
const HTML_HEADERS = const {'content-type': 'text/html'};
diff --git a/bin/live_code_size_analysis.dart b/bin/live_code_size_analysis.dart
index 499ef75..a4c0414 100644
--- a/bin/live_code_size_analysis.dart
+++ b/bin/live_code_size_analysis.dart
@@ -72,8 +72,10 @@
// validate just once.
var name = f.name;
if (name.contains('.')) name = name.substring(name.lastIndexOf('.') + 1);
- if (data['name'] != name && data['name'] != '') {
- print('invalid coverage: $data for $f');
+ var otherName = data['name'];
+ if (otherName.contains('.')) otherName = otherName.substring(otherName.lastIndexOf('.') + 1);
+ if (otherName != name && otherName != '') {
+ print('invalid coverage: $data for $f, ($name vs $otherName)');
}
reachableCode += f.size;
} else {
diff --git a/pubspec.yaml b/pubspec.yaml
index 6783367..645ea39 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: dart2js_info
-version: 0.5.13
+version: 0.5.14
description: >
Libraries and tools to process data produced when running dart2js with