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

Side by Side Diff: petitparser/lib/src/debug/profile.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « petitparser/lib/src/debug/continuation.dart ('k') | petitparser/lib/src/debug/progress.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 part of debug;
2
3 /**
4 * Returns a transformed [parser] that when being used measures
5 * the activation count and total time of each parser.
6 *
7 * For example, the snippet
8 *
9 * var parser = letter() & word().star();
10 * profile(parser).parse('f1234567890');
11 *
12 * produces the following output:
13 *
14 * 1 2006 Instance of 'SequenceParser'
15 * 1 697 Instance of 'PossessiveRepeatingParser'[0..*]
16 * 11 406 Instance of 'CharacterParser'[letter or digit expected]
17 * 1 947 Instance of 'CharacterParser'[letter expected]
18 *
19 * The first number refers to the number of activations of each parser, and
20 * the second number is the microseconds spent in this parser and all its
21 * children.
22 */
23 Parser profile(Parser root, [OutputHandler output = print]) {
24 var count = new Map();
25 var watch = new Map();
26 var parsers = new List();
27 return new ContinuationParser(transformParser(root, (parser) {
28 parsers.add(parser);
29 return new ContinuationParser(parser, (continuation, context) {
30 count[parser]++;
31 watch[parser].start();
32 var result = continuation(context);
33 watch[parser].stop();
34 return result;
35 });
36 }), (continuation, context) {
37 parsers.forEach((parser) {
38 count[parser] = 0;
39 watch[parser] = new Stopwatch();
40 });
41 var result = continuation(context);
42 parsers.forEach((parser) {
43 output('${count[parser]}\t'
44 '${watch[parser].elapsedMicroseconds}\t'
45 '${parser}');
46 });
47 return result;
48 });
49 }
OLDNEW
« no previous file with comments | « petitparser/lib/src/debug/continuation.dart ('k') | petitparser/lib/src/debug/progress.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698