OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 import 'package:analyzer/context/context_root.dart'; | 9 import 'package:analyzer/context/context_root.dart'; |
10 import 'package:analyzer/context/declared_variables.dart'; | 10 import 'package:analyzer/context/declared_variables.dart'; |
(...skipping 13 matching lines...) Expand all Loading... |
24 import 'package:analyzer/src/dart/analysis/status.dart'; | 24 import 'package:analyzer/src/dart/analysis/status.dart'; |
25 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; | 25 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; |
26 import 'package:analyzer/src/generated/engine.dart' | 26 import 'package:analyzer/src/generated/engine.dart' |
27 show AnalysisContext, AnalysisEngine, AnalysisOptions; | 27 show AnalysisContext, AnalysisEngine, AnalysisOptions; |
28 import 'package:analyzer/src/generated/source.dart'; | 28 import 'package:analyzer/src/generated/source.dart'; |
29 import 'package:analyzer/src/lint/registry.dart' as linter; | 29 import 'package:analyzer/src/lint/registry.dart' as linter; |
30 import 'package:analyzer/src/summary/format.dart'; | 30 import 'package:analyzer/src/summary/format.dart'; |
31 import 'package:analyzer/src/summary/idl.dart'; | 31 import 'package:analyzer/src/summary/idl.dart'; |
32 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 32 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
33 import 'package:front_end/src/base/api_signature.dart'; | 33 import 'package:front_end/src/base/api_signature.dart'; |
| 34 import 'package:front_end/src/base/performace_logger.dart'; |
34 import 'package:front_end/src/incremental/byte_store.dart'; | 35 import 'package:front_end/src/incremental/byte_store.dart'; |
35 import 'package:meta/meta.dart'; | 36 import 'package:meta/meta.dart'; |
36 | 37 |
37 /** | 38 /** |
38 * This class computes [AnalysisResult]s for Dart files. | 39 * This class computes [AnalysisResult]s for Dart files. |
39 * | 40 * |
40 * Let the set of "explicitly analyzed files" denote the set of paths that have | 41 * Let the set of "explicitly analyzed files" denote the set of paths that have |
41 * been passed to [addFile] but not subsequently passed to [removeFile]. Let | 42 * been passed to [addFile] but not subsequently passed to [removeFile]. Let |
42 * the "current analysis results" denote the map from the set of explicitly | 43 * the "current analysis results" denote the map from the set of explicitly |
43 * analyzed files to the most recent [AnalysisResult] delivered to [results] | 44 * analyzed files to the most recent [AnalysisResult] delivered to [results] |
(...skipping 1752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 /** | 1797 /** |
1797 * The scanning and parsing errors. | 1798 * The scanning and parsing errors. |
1798 */ | 1799 */ |
1799 final List<AnalysisError> errors; | 1800 final List<AnalysisError> errors; |
1800 | 1801 |
1801 ParseResult(this.path, this.uri, this.content, this.contentHash, | 1802 ParseResult(this.path, this.uri, this.content, this.contentHash, |
1802 this.lineInfo, this.unit, this.errors); | 1803 this.lineInfo, this.unit, this.errors); |
1803 } | 1804 } |
1804 | 1805 |
1805 /** | 1806 /** |
1806 * This class is used to gather and print performance information. | |
1807 */ | |
1808 class PerformanceLog { | |
1809 final StringSink sink; | |
1810 int _level = 0; | |
1811 | |
1812 PerformanceLog(this.sink); | |
1813 | |
1814 /** | |
1815 * Enter a new execution section, which starts at one point of code, runs | |
1816 * some time, and then ends at the other point of code. | |
1817 * | |
1818 * The client must call [PerformanceLogSection.exit] for every [enter]. | |
1819 */ | |
1820 PerformanceLogSection enter(String msg) { | |
1821 writeln('+++ $msg.'); | |
1822 _level++; | |
1823 return new PerformanceLogSection(this, msg); | |
1824 } | |
1825 | |
1826 /** | |
1827 * Return the result of the function [f] invocation and log the elapsed time. | |
1828 * | |
1829 * Each invocation of [run] creates a new enclosed section in the log, | |
1830 * which begins with printing [msg], then any log output produced during | |
1831 * [f] invocation, and ends with printing [msg] with the elapsed time. | |
1832 */ | |
1833 /*=T*/ run/*<T>*/(String msg, /*=T*/ f()) { | |
1834 Stopwatch timer = new Stopwatch()..start(); | |
1835 try { | |
1836 writeln('+++ $msg.'); | |
1837 _level++; | |
1838 return f(); | |
1839 } finally { | |
1840 _level--; | |
1841 int ms = timer.elapsedMilliseconds; | |
1842 writeln('--- $msg in $ms ms.'); | |
1843 } | |
1844 } | |
1845 | |
1846 /** | |
1847 * Write a new line into the log. | |
1848 */ | |
1849 void writeln(String msg) { | |
1850 if (sink != null) { | |
1851 String indent = '\t' * _level; | |
1852 sink.writeln('$indent$msg'); | |
1853 } | |
1854 } | |
1855 } | |
1856 | |
1857 /** | |
1858 * The performance measurement section for operations that start and end | |
1859 * at different place in code, so cannot be run using [PerformanceLog.run]. | |
1860 * | |
1861 * The client must call [exit] for every [PerformanceLog.enter]. | |
1862 */ | |
1863 class PerformanceLogSection { | |
1864 final PerformanceLog _logger; | |
1865 final String _msg; | |
1866 final Stopwatch _timer = new Stopwatch()..start(); | |
1867 | |
1868 PerformanceLogSection(this._logger, this._msg); | |
1869 | |
1870 /** | |
1871 * Stop the timer, log the time. | |
1872 */ | |
1873 void exit() { | |
1874 _timer.stop(); | |
1875 _logger._level--; | |
1876 int ms = _timer.elapsedMilliseconds; | |
1877 _logger.writeln('--- $_msg in $ms ms.'); | |
1878 } | |
1879 } | |
1880 | |
1881 /** | |
1882 * The result with the [CompilationUnitElement] of a single file. | 1807 * The result with the [CompilationUnitElement] of a single file. |
1883 * | 1808 * |
1884 * These results are self-consistent, i.e. all elements and types accessible | 1809 * These results are self-consistent, i.e. all elements and types accessible |
1885 * through [element], including defined in other files, correspond to each | 1810 * through [element], including defined in other files, correspond to each |
1886 * other. But none of the results is guaranteed to be consistent with the state | 1811 * other. But none of the results is guaranteed to be consistent with the state |
1887 * of the files. | 1812 * of the files. |
1888 * | 1813 * |
1889 * Every result is independent, and is not guaranteed to be consistent with | 1814 * Every result is independent, and is not guaranteed to be consistent with |
1890 * any previously returned result, even inside of the same library. | 1815 * any previously returned result, even inside of the same library. |
1891 */ | 1816 */ |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2100 libraryDeclarations.add(new TopLevelDeclarationInSource( | 2025 libraryDeclarations.add(new TopLevelDeclarationInSource( |
2101 file.source, declaration, isExported)); | 2026 file.source, declaration, isExported)); |
2102 } | 2027 } |
2103 } | 2028 } |
2104 } | 2029 } |
2105 | 2030 |
2106 // We're not done yet. | 2031 // We're not done yet. |
2107 return false; | 2032 return false; |
2108 } | 2033 } |
2109 } | 2034 } |
OLD | NEW |