Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1560)

Unified Diff: sdk/lib/_internal/compiler/implementation/dump_info.dart

Issue 336003003: dump-info additionally dumps a json info file (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/dump_info.dart
diff --git a/sdk/lib/_internal/compiler/implementation/dump_info.dart b/sdk/lib/_internal/compiler/implementation/dump_info.dart
index f5c8f2690f32223a0f7fd1cf6c4ef32394db71ee..1758e57e97f82ee1edf3a5db9a85ba0e878f7220 100644
--- a/sdk/lib/_internal/compiler/implementation/dump_info.dart
+++ b/sdk/lib/_internal/compiler/implementation/dump_info.dart
@@ -4,7 +4,7 @@
library dump_info;
-import 'dart:convert' show HtmlEscape;
+import 'dart:convert' show HtmlEscape, JSON;
import 'elements/elements.dart';
import 'elements/visitor.dart';
@@ -87,6 +87,8 @@ abstract class InfoNode {
void emitHtml(ProgramInfo programInfo, StringSink buffer,
[String indentation = '']);
+
+ Map<String, dynamic> toJson(ProgramInfo programInfo);
}
/// An [ElementNode] holds information about an [Element]
@@ -130,6 +132,24 @@ class ElementInfoNode implements InfoNode {
this.extra: "",
this.outputUnitId});
+ Map<String, dynamic> toJson(ProgramInfo programInfo) {
+ Map<String, dynamic> props = {};
+ props['kind'] = this.kind;
+ props['modifiers'] = this.modifiers;
+ props['name'] = this.name;
+ props['type'] = this.type;
+ props['size'] = this.size;
+ if (this.size != null) {
+ props['size_percent'] =
+ (100 * this.size / programInfo.size).toStringAsFixed(3) + "%";
+ }
+ props['extra'] = this.extra;
+ if (this.contents != null) {
+ props['children'] = this.contents.map((c) => c.toJson(programInfo)).toList();
Ty Overby 2014/06/20 19:36:47 Line over 80 chars.
Ty Overby 2014/06/20 19:47:28 Done.
+ }
+ return props;
+ }
+
void emitHtml(ProgramInfo programInfo, StringSink buffer,
[String indentation = '']) {
String kindString = span(esc(kind), cls: 'kind');
@@ -197,6 +217,18 @@ class CodeInfoNode implements InfoNode {
code(esc(generatedCode)));
buffer.write('\n');
}
+
+ Map<String, dynamic> toJson(ProgramInfo programInfo) {
+ Map<String, dynamic> props = {};
sra1 2014/06/20 19:49:27 You can use the literal syntax to add the always-i
Ty Overby 2014/06/20 19:59:13 Done.
+ props['kind'] = 'code';
+ props['description'] = description;
+ props['code'] = generatedCode;
+ props['size'] = generatedCode.length;
+ props['sizePercent'] =
+ (100 * generatedCode.length / programInfo.size).toStringAsFixed(3) + "%";
+
+ return props;
+ }
}
/// Instances represent information inferred about the program such as
@@ -216,6 +248,15 @@ class InferredInfoNode implements InfoNode {
InferredInfoNode({this.name: "", this.description, this.type});
+ Map<String, dynamic> toJson(ProgramInfo programInfo) {
+ Map<String, dynamic> props = {};
+ props['kind'] = "inferred";
+ props['name'] = name;
+ props['type'] = type;
+ props['desc'] = description;
+ return props;
+ }
+
void emitHtml(ProgramInfo programInfo, StringBuffer buffer,
[String indentation = '']) {
buffer.write(indentation);
@@ -253,6 +294,15 @@ class ProgramInfo {
this.compilationDuration,
this.dart2jsVersion,
this.outputUnitNumbering: null});
+
+ Map<String, dynamic> toJson() {
+ Map<String, dynamic> json = {};
Ty Overby 2014/06/20 19:36:47 Either have this variable be called `props` or hav
Ty Overby 2014/06/20 19:47:28 Done.
sra1 2014/06/20 19:49:27 I think `json`.
Ty Overby 2014/06/20 19:59:13 `json` is what I went with.
+ json['program_size'] = size;
+ json['compile_time'] = compilationMoment.toString();
+ json['compile_duration'] = compilationDuration.toString();
+ json['dart2js_version'] = dart2jsVersion;
+ return json;
+ }
}
class InfoDumpVisitor extends ElementVisitor<InfoNode> {
@@ -532,14 +582,28 @@ class DumpInfoTask extends CompilerTask {
void dumpInfo() {
measure(() {
ProgramInfo info = infoDumpVisitor.collectDumpInfo();
- StringBuffer buffer = new StringBuffer();
- dumpInfoHtml(info, buffer);
+
+ StringBuffer htmlBuffer = new StringBuffer();
+ dumpInfoHtml(info, htmlBuffer);
compiler.outputProvider('', 'info.html')
- ..add(buffer.toString())
+ ..add(htmlBuffer.toString())
+ ..close();
+
+ StringBuffer jsonBuffer = new StringBuffer();
+ dumpInfoJson(info, jsonBuffer);
+ compiler.outputProvider('', 'info.json')
+ ..add(jsonBuffer.toString())
..close();
});
}
+ void dumpInfoJson(ProgramInfo info, StringSink buffer) {
+ Map entire = {};
+ entire['program'] = info.toJson();
+ entire['libs'] = info.libraries.map((lib) => lib.toJson(info)).toList();
+ buffer.writeln(JSON.encode(entire));
Ty Overby 2014/06/20 19:36:47 The performance of this could probably be improved
Ty Overby 2014/06/20 19:47:28 Done.
Ty Overby 2014/06/20 19:47:28 Done.
+ }
+
void dumpInfoHtml(ProgramInfo info, StringSink buffer) {
int totalSize = info.size;

Powered by Google App Engine
This is Rietveld 408576698