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

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: map literal syntax 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
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart2js.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7125d28adae2f6df615f0feab56e6a6603ced708 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, JsonEncoder, StringConversionSink;
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);
floitsch 2014/06/20 22:27:57 I would prefer not to pollute the InfoNode with a
}
/// An [ElementNode] holds information about an [Element]
@@ -130,6 +132,28 @@ class ElementInfoNode implements InfoNode {
this.extra: "",
this.outputUnitId});
+ Map<String, dynamic> toJson(ProgramInfo programInfo) {
+ Map<String, dynamic> json = <String, dynamic>{
+ 'kind': this.kind,
+ 'modifiers': this.modifiers,
+ 'name': this.name,
+ 'type': this.type,
+ 'size': this.size,
+ 'extra': this.extra
+ };
+
+ if (this.size != null) {
+ json['size_percent'] =
sra1 2014/06/20 22:16:34 inconstistent name - use 'sizePercent' to match on
Ty Overby 2014/06/20 22:58:04 Done.
+ (100 * this.size / programInfo.size).toStringAsFixed(3) + "%";
+ }
+
+ if (this.contents != null) {
+ json['children'] =
+ this.contents.map((c) => c.toJson(programInfo)).toList();
+ }
+ return json;
+ }
+
void emitHtml(ProgramInfo programInfo, StringSink buffer,
[String indentation = '']) {
String kindString = span(esc(kind), cls: 'kind');
@@ -197,6 +221,16 @@ class CodeInfoNode implements InfoNode {
code(esc(generatedCode)));
buffer.write('\n');
}
+
+ Map<String, dynamic> toJson(ProgramInfo programInfo) {
+ return <String, dynamic>{
+ 'kind': 'code',
+ 'description': description,
+ 'code': generatedCode,
+ 'size': generatedCode.length,
+ 'sizePercent': (100 * generatedCode.length / programInfo.size).toStringAsFixed(3) + "%"
sra1 2014/06/20 22:16:34 Long line (should be <= 80 chars) Maybe abstract
Ty Overby 2014/06/20 22:58:04 Done.
+ };
+ }
}
/// Instances represent information inferred about the program such as
@@ -216,6 +250,15 @@ class InferredInfoNode implements InfoNode {
InferredInfoNode({this.name: "", this.description, this.type});
+ Map<String, dynamic> toJson(ProgramInfo programInfo) {
+ return <String, dynamic>{
+ 'kind': "inferred",
sra1 2014/06/20 22:16:34 Use single quotes unless there are embedded single
Ty Overby 2014/06/20 22:58:04 Done.
+ 'name': name,
+ 'type': type,
+ 'desc': description
+ };
+ }
+
void emitHtml(ProgramInfo programInfo, StringBuffer buffer,
[String indentation = '']) {
buffer.write(indentation);
@@ -253,6 +296,15 @@ class ProgramInfo {
this.compilationDuration,
this.dart2jsVersion,
this.outputUnitNumbering: null});
+
+ Map<String, dynamic> toJson() {
+ return <String, dynamic>{
+ 'program_size': size,
+ 'compile_time': compilationMoment.toString(),
+ 'compile_duration': compilationDuration.toString(),
+ 'dart2js_version': dart2jsVersion
+ };
+ }
}
class InfoDumpVisitor extends ElementVisitor<InfoNode> {
@@ -532,14 +584,33 @@ 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 = {};
sra1 2014/06/20 22:16:34 Add types.
Ty Overby 2014/06/20 22:58:04 Done.
+ entire['program'] = info.toJson();
sra1 2014/06/20 22:16:34 maybe include this in the literal.
Ty Overby 2014/06/20 22:58:04 Done.
+ entire['libs'] = info.libraries.map((lib) => lib.toJson(info)).toList();
+
+ JsonEncoder encoder = const JsonEncoder();
+ ChunkedConversionSink<Object> sink =
+ encoder.startChunkedConversion(
+ new StringConversionSink.fromStringSink(buffer));
+ sink.add(entire);
+ }
+
void dumpInfoHtml(ProgramInfo info, StringSink buffer) {
int totalSize = info.size;
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart2js.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698