Chromium Code Reviews| 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 /// An entrypoint used to run portions of front_end and measure its performance. | 5 /// An entrypoint used to run portions of front_end and measure its performance. |
| 6 library front_end.tool.perf; | 6 library front_end.tool.perf; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io' show exit, stderr; | 9 import 'dart:io' show exit, stderr; |
| 10 | 10 |
| 11 import 'package:analyzer/dart/ast/ast.dart'; | 11 import 'package:analyzer/dart/ast/ast.dart'; |
| 12 import 'package:analyzer/error/listener.dart'; | 12 import 'package:analyzer/error/listener.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; | 13 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; |
| 14 import 'package:analyzer/file_system/physical_file_system.dart' | 14 import 'package:analyzer/file_system/physical_file_system.dart' |
| 15 show PhysicalResourceProvider; | 15 show PhysicalResourceProvider; |
| 16 import 'package:analyzer/source/package_map_resolver.dart'; | 16 import 'package:analyzer/source/package_map_resolver.dart'; |
| 17 import 'package:analyzer/src/context/builder.dart'; | 17 import 'package:analyzer/src/context/builder.dart'; |
| 18 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; | 18 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; |
| 19 import 'package:analyzer/src/generated/parser.dart'; | 19 import 'package:analyzer/src/generated/parser.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 21 import 'package:analyzer/src/generated/source_io.dart'; | 21 import 'package:analyzer/src/generated/source_io.dart'; |
| 22 import 'package:analyzer/src/summary/format.dart'; | 22 import 'package:analyzer/src/summary/format.dart'; |
| 23 import 'package:analyzer/src/summary/idl.dart'; | 23 import 'package:analyzer/src/summary/idl.dart'; |
| 24 import 'package:analyzer/src/summary/link.dart'; | |
| 24 import 'package:analyzer/src/summary/prelink.dart'; | 25 import 'package:analyzer/src/summary/prelink.dart'; |
| 25 import 'package:analyzer/src/summary/summarize_ast.dart'; | 26 import 'package:analyzer/src/summary/summarize_ast.dart'; |
| 26 import 'package:kernel/analyzer/loader.dart'; | 27 import 'package:kernel/analyzer/loader.dart'; |
| 27 import 'package:kernel/kernel.dart'; | 28 import 'package:kernel/kernel.dart'; |
| 28 import 'package:package_config/discovery.dart'; | 29 import 'package:package_config/discovery.dart'; |
| 29 | 30 |
| 30 import 'package:front_end/src/scanner/reader.dart'; | 31 import 'package:front_end/src/scanner/reader.dart'; |
| 31 import 'package:front_end/src/scanner/scanner.dart'; | 32 import 'package:front_end/src/scanner/scanner.dart'; |
| 32 import 'package:front_end/src/scanner/token.dart'; | 33 import 'package:front_end/src/scanner/token.dart'; |
| 33 | 34 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 }, | 82 }, |
| 82 'unlinked_summarize': () async { | 83 'unlinked_summarize': () async { |
| 83 Set<Source> files = scanReachableFiles(entryUri); | 84 Set<Source> files = scanReachableFiles(entryUri); |
| 84 // TODO(sigmund): replace the warmup with instrumented snapshots. | 85 // TODO(sigmund): replace the warmup with instrumented snapshots. |
| 85 for (int i = 0; i < 10; i++) unlinkedSummarizeFiles(files); | 86 for (int i = 0; i < 10; i++) unlinkedSummarizeFiles(files); |
| 86 }, | 87 }, |
| 87 'prelinked_summarize': () async { | 88 'prelinked_summarize': () async { |
| 88 Set<Source> files = scanReachableFiles(entryUri); | 89 Set<Source> files = scanReachableFiles(entryUri); |
| 89 // TODO(sigmund): replace the warmup with instrumented snapshots. | 90 // TODO(sigmund): replace the warmup with instrumented snapshots. |
| 90 for (int i = 0; i < 10; i++) prelinkedSummarizeFiles(files); | 91 for (int i = 0; i < 10; i++) prelinkedSummarizeFiles(files); |
| 92 }, | |
| 93 'linked_summarize': () async { | |
| 94 Set<Source> files = scanReachableFiles(entryUri); | |
| 95 // TODO(sigmund): replace the warmup with instrumented snapshots. | |
| 96 for (int i = 0; i < 10; i++) linkedSummarizeFiles(files); | |
| 91 } | 97 } |
| 92 }; | 98 }; |
| 93 | 99 |
| 94 var handler = handlers[bench]; | 100 var handler = handlers[bench]; |
| 95 if (handler == null) { | 101 if (handler == null) { |
| 96 // TODO(sigmund): implement the remaining benchmarks. | 102 // TODO(sigmund): implement the remaining benchmarks. |
| 97 print('unsupported bench-id: $bench. Please specify one of the following: ' | 103 print('unsupported bench-id: $bench. Please specify one of the following: ' |
| 98 '${handlers.keys.join(", ")}'); | 104 '${handlers.keys.join(", ")}'); |
| 99 exit(1); | 105 exit(1); |
| 100 } | 106 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 report("scan", scanTimer.elapsedMicroseconds); | 261 report("scan", scanTimer.elapsedMicroseconds); |
| 256 report("parse", parseTimer.elapsedMicroseconds); | 262 report("parse", parseTimer.elapsedMicroseconds); |
| 257 report('unlinked summarize', unlinkedSummarizeTimer.elapsedMicroseconds); | 263 report('unlinked summarize', unlinkedSummarizeTimer.elapsedMicroseconds); |
| 258 report( | 264 report( |
| 259 'unlinked summarize + parse', | 265 'unlinked summarize + parse', |
| 260 unlinkedSummarizeTimer.elapsedMicroseconds + | 266 unlinkedSummarizeTimer.elapsedMicroseconds + |
| 261 parseTimer.elapsedMicroseconds); | 267 parseTimer.elapsedMicroseconds); |
| 262 report('prelink', prelinkTimer.elapsedMicroseconds); | 268 report('prelink', prelinkTimer.elapsedMicroseconds); |
| 263 } | 269 } |
| 264 | 270 |
| 271 /// Produces linked summaries for every file in [files] and reports the time | |
| 272 /// spent doing so. | |
| 273 void linkedSummarizeFiles(Set<Source> files) { | |
| 274 // The code below will record again how many chars are scanned and how long it | |
| 275 // takes to scan them, even though we already did so in [scanReachableFiles]. | |
| 276 // Recording and reporting this twice is unnecessary, but we do so for now to | |
| 277 // validate that the results are consistent. | |
| 278 scanTimer = new Stopwatch(); | |
| 279 var old = scanTotalChars; | |
| 280 scanTotalChars = 0; | |
| 281 parseTimer = new Stopwatch(); | |
| 282 unlinkedSummarizeTimer = new Stopwatch(); | |
| 283 var unlinkedSummaries = <String, UnlinkedUnit>{}; | |
| 284 for (var source in files) { | |
| 285 unlinkedSummaries[source.uri.toString()] = unlinkedSummarize(source); | |
| 286 } | |
| 287 var prelinkTimer = new Stopwatch()..start(); | |
| 288 Set<String> libraryUris = | |
| 289 files.map((source) => source.uri.toString()).toSet(); | |
| 290 UnlinkedUnit getUnit(String uri) { | |
| 291 var result = unlinkedSummaries[uri]; | |
| 292 if (result == null) { | |
| 293 print('Warning: no summary found for: $uri'); | |
| 294 } | |
| 295 return result; | |
| 296 } | |
| 297 | |
| 298 String getDeclaredVariable(String s) => null; | |
| 299 var prelinkedLibraries = | |
| 300 setupForLink(libraryUris, getUnit, getDeclaredVariable); | |
|
Siggi Cherem (dart-lang)
2016/12/07 23:21:29
is there a difference between prelink and setupFor
Paul Berry
2016/12/07 23:54:40
Good point. PTAL.
| |
| 301 prelinkTimer.stop(); | |
| 302 var linkTimer = new Stopwatch()..start(); | |
| 303 LinkedLibrary getDependency(String uri) { | |
| 304 // getDependency should never be called because all dependencies are present | |
| 305 // in [prelinkedLibraries]. | |
| 306 print('Warning: getDependency called for: $uri'); | |
| 307 return null; | |
| 308 } | |
| 309 | |
| 310 bool strong = true; | |
| 311 relink(prelinkedLibraries, getDependency, getUnit, strong); | |
| 312 linkTimer.stop(); | |
| 313 | |
| 314 if (old != scanTotalChars) print('input size changed? ${old} chars'); | |
| 315 report("scan", scanTimer.elapsedMicroseconds); | |
| 316 report("parse", parseTimer.elapsedMicroseconds); | |
| 317 report('unlinked summarize', unlinkedSummarizeTimer.elapsedMicroseconds); | |
| 318 report( | |
| 319 'unlinked summarize + parse', | |
| 320 unlinkedSummarizeTimer.elapsedMicroseconds + | |
| 321 parseTimer.elapsedMicroseconds); | |
| 322 report('prelink', prelinkTimer.elapsedMicroseconds); | |
| 323 report('link', linkTimer.elapsedMicroseconds); | |
| 324 } | |
| 325 | |
| 265 /// Add to [files] all sources reachable from [start]. | 326 /// Add to [files] all sources reachable from [start]. |
| 266 void collectSources(Source start, Set<Source> files) { | 327 void collectSources(Source start, Set<Source> files) { |
| 267 if (!files.add(start)) return; | 328 if (!files.add(start)) return; |
| 268 var unit = parseDirectives(start); | 329 var unit = parseDirectives(start); |
| 269 for (var directive in unit.directives) { | 330 for (var directive in unit.directives) { |
| 270 if (directive is UriBasedDirective) { | 331 if (directive is UriBasedDirective) { |
| 271 var next = sources.resolveUri(start, directive.uri.stringValue); | 332 var next = sources.resolveUri(start, directive.uri.stringValue); |
| 272 collectSources(next, files); | 333 collectSources(next, files); |
| 273 } | 334 } |
| 274 } | 335 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 const int errorLimit = 100; | 408 const int errorLimit = 100; |
| 348 stderr.writeln(errors.take(errorLimit).join('\n')); | 409 stderr.writeln(errors.take(errorLimit).join('\n')); |
| 349 if (errors.length > errorLimit) { | 410 if (errors.length > errorLimit) { |
| 350 stderr.writeln('[error] ${errors.length - errorLimit} errors not shown'); | 411 stderr.writeln('[error] ${errors.length - errorLimit} errors not shown'); |
| 351 } | 412 } |
| 352 } | 413 } |
| 353 dartkTimer.stop(); | 414 dartkTimer.stop(); |
| 354 report("kernel_gen_e2e", dartkTimer.elapsedMicroseconds); | 415 report("kernel_gen_e2e", dartkTimer.elapsedMicroseconds); |
| 355 return program; | 416 return program; |
| 356 } | 417 } |
| OLD | NEW |