Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updates

  • Loading branch information...
commit 595b4059a779426094ce8653b3830272842ba2ba 1 parent eb41aec
@perlpilot authored
Showing with 46 additions and 7 deletions.
  1. +35 −3 README.markdown
  2. +11 −4 lib/Grammar/Profiler/Simple.pm
View
38 README.markdown
@@ -8,10 +8,42 @@ to your code. Any grammar in the lexical scope of the use statement
will automatically have profiling information collected when the
grammar is used.
-This module exports two subroutines
+This module exports two subroutines, each with 3 variants:
-- get-timing retrieve the timing information collected so far
-- reset-timing reset the timing information to zero
+### `reset-timing()`
+Reset all time information collected since the start of the program or since the last call to
+`reset-timing()`
+
+### `reset-timing($grammar)`
+
+Reset all time information only for the specified grammar.
+
+### `reset-timing($grammar, $rule)`
+
+Reset all time information only for the specified rule within the specified grammar.
+
+### `get-timing()`
+
+Retrieve the timing information collected so far or since the last call
+to `reset-timing`. Returned as a mult-level hash with the first level
+indexed by the name of the grammar and the second level indexed by the
+name of the rule within the grammar.
+
+### `get-timing($grammar)`
+
+Retrieve the timing information collected for a particular grammar.
+
+### `get-timing($grammar, $rule)`
+
+Retrieve the timing information collected for a particular rule within a particular grammar.
+
+## Timing information
+
+There are 2 bits of timing information collected: the number of times each rule was called
+and the cumulative time that was spent executing each rule. For example
+
+say "MyRule was called get-timing('MyGrammar','MyRule')<calls> times";
+say "The total time executing MyRule was get-timing('MyGrammar','MyRule')<time> seconds";
View
15 lib/Grammar/Profiler/Simple.pm
@@ -4,10 +4,10 @@ my class ProfiledGrammarHOW is Metamodel::GrammarHOW is Mu {
method find_method($obj, $name) {
my $meth := callsame;
- substr($name, 0, 1) eq '!' || $name eq any(<parse CREATE Bool defined MATCH WHAT gist>) ??
+ substr($name, 0, 1) eq '!' || $name eq any(<parse CREATE Bool defined MATCH WHAT perl>) ??
$meth !!
-> $c, |$args {
- my $grammar = $obj.WHAT.gist;
+ my $grammar = $obj.WHAT.perl;
%timing{$grammar} //= {}; # Vivify grammar hash
%timing{$grammar}{$meth.name} //= {}; # Vivify method hash
my %t := %timing{$grammar}{$meth.name};
@@ -24,8 +24,15 @@ my class ProfiledGrammarHOW is Metamodel::GrammarHOW is Mu {
}
}
-sub get-timing () is export { %timing }
-sub reset-timing () is export { %timing = () }
+proto sub get-timing is export { * }
+multi sub get-timing () { %timing }
+multi sub get-timing ($grammar) { %timing{$grammar} }
+multi sub get-timing ($grammar, $rule) { %timing{$grammar}{$rule} }
+
+proto sub reset-timing is export { * }
+multi sub reset-timing () { %timing = () }
+multi sub reset-timing ($grammar) { %timing{$grammar} = () }
+multi sub reset-timing ($grammar, $rule) { %timing{$grammar}{$rule} = () }
my module EXPORTHOW { }
EXPORTHOW.WHO.<grammar> = ProfiledGrammarHOW;
Please sign in to comment.
Something went wrong with that request. Please try again.