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

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

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

Powered by Google App Engine
This is Rietveld 408576698