Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dump_info; | 5 library dump_info; |
| 6 | 6 |
| 7 import 'dart:convert' show | 7 import 'dart:convert' show |
| 8 HtmlEscape, | 8 HtmlEscape, |
| 9 JsonEncoder, | 9 JsonEncoder, |
| 10 StringConversionSink, | 10 StringConversionSink, |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 // A set of javascript AST nodes that we care about the size of. | 403 // A set of javascript AST nodes that we care about the size of. |
| 404 // This set is automatically populated when registerElementAst() | 404 // This set is automatically populated when registerElementAst() |
| 405 // is called. | 405 // is called. |
| 406 final Set<jsAst.Node> _tracking = new Set<jsAst.Node>(); | 406 final Set<jsAst.Node> _tracking = new Set<jsAst.Node>(); |
| 407 // A mapping from Dart Elements to Javascript AST Nodes. | 407 // A mapping from Dart Elements to Javascript AST Nodes. |
| 408 final Map<Element, List<jsAst.Node>> _elementToNodes = | 408 final Map<Element, List<jsAst.Node>> _elementToNodes = |
| 409 <Element, List<jsAst.Node>>{}; | 409 <Element, List<jsAst.Node>>{}; |
| 410 // A mapping from Javascript AST Nodes to the size of their | 410 // A mapping from Javascript AST Nodes to the size of their |
| 411 // pretty-printed contents. | 411 // pretty-printed contents. |
| 412 final Map<jsAst.Node, int> _nodeToSize = <jsAst.Node, int>{}; | 412 final Map<jsAst.Node, int> _nodeToSize = <jsAst.Node, int>{}; |
| 413 final Map<jsAst.Node, int> _nodeBeforeSize = <jsAst.Node, int>{}; | |
| 414 final Map<Element, int> _fieldNameToSize = <Element, int>{}; | 413 final Map<Element, int> _fieldNameToSize = <Element, int>{}; |
| 415 | 414 |
| 416 final Map<Element, Set<Selector>> selectorsFromElement = {}; | 415 final Map<Element, Set<Selector>> selectorsFromElement = {}; |
| 417 final Map<Element, int> inlineCount = <Element, int>{}; | 416 final Map<Element, int> inlineCount = <Element, int>{}; |
| 418 // A mapping from an element to a list of elements that are | 417 // A mapping from an element to a list of elements that are |
| 419 // inlined inside of it. | 418 // inlined inside of it. |
| 420 final Map<Element, List<Element>> inlineMap = <Element, List<Element>>{}; | 419 final Map<Element, List<Element>> inlineMap = <Element, List<Element>>{}; |
| 421 | 420 |
| 422 /// Register the size of the generated output. | 421 /// Register the size of the generated output. |
| 423 void reportSize(int programSize) { | 422 void reportSize(int programSize) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 454 } else { | 453 } else { |
| 455 return selectorsFromElement[element].expand( | 454 return selectorsFromElement[element].expand( |
| 456 (selector) { | 455 (selector) { |
| 457 return compiler.world.allFunctions.filter(selector).map((element) { | 456 return compiler.world.allFunctions.filter(selector).map((element) { |
| 458 return new Selection(element, selector); | 457 return new Selection(element, selector); |
| 459 }); | 458 }); |
| 460 }); | 459 }); |
| 461 } | 460 } |
| 462 } | 461 } |
| 463 | 462 |
| 464 /** | |
| 465 * A callback that can be called before a jsAst [node] is | |
| 466 * pretty-printed. The size of the code buffer ([aftersize]) | |
| 467 * is also passed. | |
| 468 */ | |
| 469 void enteringAst(jsAst.Node node, int beforeSize) { | |
| 470 if (isTracking(node)) { | |
| 471 _nodeBeforeSize[node] = beforeSize; | |
| 472 } | |
| 473 } | |
| 474 | |
| 475 /** | |
| 476 * A callback that can be called after a jsAst [node] is | |
| 477 * pretty-printed. The size of the code buffer ([aftersize]) | |
| 478 * is also passed. | |
| 479 */ | |
| 480 void exitingAst(jsAst.Node node, int afterSize) { | |
| 481 if (isTracking(node)) { | |
| 482 int diff = afterSize - _nodeBeforeSize[node]; | |
| 483 recordAstSize(node, diff); | |
| 484 } | |
| 485 } | |
| 486 | |
| 487 // Returns true if we care about tracking the size of | 463 // Returns true if we care about tracking the size of |
| 488 // this node. | 464 // this node. |
| 489 bool isTracking(jsAst.Node code) { | 465 bool isTracking(jsAst.Node code) { |
| 490 if (compiler.dumpInfo) { | 466 if (compiler.dumpInfo) { |
| 491 return _tracking.contains(code); | 467 return _tracking.contains(code); |
| 492 } else { | 468 } else { |
| 493 return false; | 469 return false; |
| 494 } | 470 } |
| 495 } | 471 } |
| 496 | 472 |
| 497 // Registers that a javascript AST node `code` was produced by the | 473 // Registers that a javascript AST node `code` was produced by the |
| 498 // dart Element `element`. | 474 // dart Element `element`. |
| 499 void registerElementAst(Element element, jsAst.Node code) { | 475 void registerElementAst(Element element, jsAst.Node code) { |
| 500 if (compiler.dumpInfo) { | 476 if (compiler.dumpInfo) { |
| 501 _elementToNodes | 477 _elementToNodes |
| 502 .putIfAbsent(element, () => new List<jsAst.Node>()) | 478 .putIfAbsent(element, () => new List<jsAst.Node>()) |
| 503 .add(code); | 479 .add(code); |
| 504 _tracking.add(code); | 480 _tracking.add(code); |
| 505 } | 481 } |
| 506 } | 482 } |
| 507 | 483 |
| 508 // Records the size of a dart AST node after it has been | 484 // Records the size of a dart AST node after it has been |
| 509 // pretty-printed into the output buffer. | 485 // pretty-printed into the output buffer. |
| 510 void recordAstSize(jsAst.Node code, int size) { | 486 void recordAstSize(jsAst.Node code, int size) { |
|
floitsch
2015/04/14 15:09:31
I would rename the variable to "node" since it rea
Johnni Winther
2015/04/15 11:15:28
Done.
| |
| 511 if (compiler.dumpInfo) { | 487 if (isTracking(code)) { |
| 512 //TODO: should I be incrementing here instead? | 488 //TODO: should I be incrementing here instead? |
| 513 _nodeToSize[code] = size; | 489 _nodeToSize[code] = size; |
| 514 } | 490 } |
| 515 } | 491 } |
| 516 | 492 |
| 517 // Field names are treated differently by the dart compiler | 493 // Field names are treated differently by the dart compiler |
| 518 // so they must be recorded seperately. | 494 // so they must be recorded seperately. |
| 519 void recordFieldNameSize(Element element, int size) { | 495 void recordFieldNameSize(Element element, int size) { |
| 520 _fieldNameToSize[element] = size; | 496 _fieldNameToSize[element] = size; |
| 521 } | 497 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 ChunkedConversionSink<Object> sink = | 638 ChunkedConversionSink<Object> sink = |
| 663 encoder.startChunkedConversion( | 639 encoder.startChunkedConversion( |
| 664 new StringConversionSink.fromStringSink(buffer)); | 640 new StringConversionSink.fromStringSink(buffer)); |
| 665 sink.add(outJson); | 641 sink.add(outJson); |
| 666 compiler.reportInfo(NO_LOCATION_SPANNABLE, | 642 compiler.reportInfo(NO_LOCATION_SPANNABLE, |
| 667 const MessageKind( | 643 const MessageKind( |
| 668 "View the dumped .info.json file at " | 644 "View the dumped .info.json file at " |
| 669 "https://dart-lang.github.io/dump-info-visualizer")); | 645 "https://dart-lang.github.io/dump-info-visualizer")); |
| 670 } | 646 } |
| 671 } | 647 } |
| OLD | NEW |