<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>src/org/jruby/management/ParserStats.java</filename>
    </added>
    <added>
      <filename>src/org/jruby/management/ParserStatsMBean.java</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -96,6 +96,7 @@ import org.jruby.javasupport.JavaSupport;
 import org.jruby.management.BeanManager;
 import org.jruby.management.ClassCache;
 import org.jruby.management.Config;
+import org.jruby.management.ParserStats;
 import org.jruby.parser.Parser;
 import org.jruby.parser.ParserConfiguration;
 import org.jruby.runtime.Binding;
@@ -205,8 +206,10 @@ public final class Ruby {
         this.kcode              = config.getKCode();
         this.beanManager        = new BeanManager(this, config.isManagementEnabled());
         this.jitCompiler        = new JITCompiler(this);
+        this.parserStats        = new ParserStats(this);
         
         this.beanManager.register(new Config(this));
+        this.beanManager.register(parserStats);
         this.beanManager.register(new ClassCache(this));
         
         this.cacheMap = new CacheMap(this);
@@ -566,6 +569,10 @@ public final class Ruby {
             return (IRubyObject) rj.getValue();
         }
     }
+
+    public Parser getParser() {
+        return parser;
+    }
     
     public BeanManager getBeanManager() {
         return beanManager;
@@ -1899,10 +1906,12 @@ public final class Ruby {
     }
     
     public Node parseFile(InputStream in, String file, DynamicScope scope) {
+        if (parserStats != null) parserStats.addLoadParse();
         return parser.parse(file, in, scope, new ParserConfiguration(0, false, false, true));
     }
 
     public Node parseInline(InputStream in, String file, DynamicScope scope) {
+        if (parserStats != null) parserStats.addEvalParse();
         return parser.parse(file, in, scope, new ParserConfiguration(0, false, true));
     }
 
@@ -1915,10 +1924,12 @@ public final class Ruby {
             bytes = content.getBytes();
         }
         
+        if (parserStats != null) parserStats.addEvalParse();
         return parser.parse(file, new ByteArrayInputStream(bytes), scope, 
                 new ParserConfiguration(lineNumber, false));
     }
 
+    @Deprecated
     public Node parse(String content, String file, DynamicScope scope, int lineNumber, 
             boolean extraPositionInformation) {
         byte[] bytes;
@@ -1934,11 +1945,13 @@ public final class Ruby {
     }
     
     public Node parseEval(ByteList content, String file, DynamicScope scope, int lineNumber) {
+        if (parserStats != null) parserStats.addEvalParse();
         return parser.parse(file, content, scope, new ParserConfiguration(lineNumber, false));
     }
 
     public Node parse(ByteList content, String file, DynamicScope scope, int lineNumber, 
             boolean extraPositionInformation) {
+        if (parserStats != null) parserStats.addJRubyModuleParse();
         return parser.parse(file, content, scope, 
                 new ParserConfiguration(lineNumber, extraPositionInformation, false));
     }
@@ -2340,6 +2353,7 @@ public final class Ruby {
 
         getBeanManager().unregisterCompiler();
         getBeanManager().unregisterConfig();
+        getBeanManager().unregisterParserStats();
         getBeanManager().unregisterClassCache();
         getBeanManager().unregisterMethodCache();
 
@@ -2976,6 +2990,9 @@ public final class Ruby {
     
     // Management/monitoring
     private BeanManager beanManager;
+
+    // Parser stats
+    private ParserStats parserStats;
     
     // Compilation
     private final JITCompiler jitCompiler;</diff>
      <filename>src/org/jruby/Ruby.java</filename>
    </modified>
    <modified>
      <diff>@@ -33,6 +33,10 @@ public class BeanManager {
         if (managementEnabled) register(base + &quot;service=Config&quot;, config);
     }
     
+    public void register(ParserStatsMBean parserStats) {
+        if (managementEnabled) register(base + &quot;service=ParserStats&quot;, parserStats);
+    }
+    
     public void register(MethodCacheMBean methodCache) {
         if (managementEnabled) register(base + &quot;service=MethodCache&quot;, methodCache);
     }
@@ -47,6 +51,9 @@ public class BeanManager {
     public void unregisterConfig() {
         if (managementEnabled) unregister(base + &quot;service=Config&quot;);
     }
+    public void unregisterParserStats() {
+        if (managementEnabled) unregister(base + &quot;service=ParserStats&quot;);
+    }
     public void unregisterClassCache() {
         if (managementEnabled) unregister(base + &quot;service=ClassCache&quot;);
     }</diff>
      <filename>src/org/jruby/management/BeanManager.java</filename>
    </modified>
    <modified>
      <diff>@@ -54,22 +54,34 @@ import org.jruby.util.ByteList;
  */
 public class Parser {
     private final Ruby runtime;
+    private volatile long totalTime;
+    private volatile int totalBytes;
 
     public Parser(Ruby runtime) {
         this.runtime = runtime;
     }
+
+    public long getTotalTime() {
+        return totalTime;
+    }
+
+    public int getTotalBytes() {
+        return totalBytes;
+    }
     
     public Node parseRewriter(String file, InputStream content, 
             ParserConfiguration configuration) throws SyntaxException {
-
+        long startTime = System.nanoTime();
         DefaultRubyParser parser = RubyParserPool.getInstance().borrowParser();
+        parser.setWarnings(new NullWarnings());
+        LexerSource lexerSource = LexerSource.getSource(file, content, null, configuration);
+        
         try {
-            parser.setWarnings(new NullWarnings());
-            LexerSource lexerSource = LexerSource.getSource(file, content, null, configuration);
-            
             return parser.parse(configuration, lexerSource).getAST();
         } finally {
             RubyParserPool.getInstance().returnParser(parser);
+            totalTime += System.nanoTime() - startTime;
+            totalBytes += lexerSource.getOffset();
         }
     }
     
@@ -82,6 +94,7 @@ public class Parser {
     @SuppressWarnings(&quot;unchecked&quot;)
     public Node parse(String file, InputStream content, DynamicScope blockScope,
             ParserConfiguration configuration) {
+        long startTime = System.nanoTime();
         IRubyObject scriptLines = runtime.getObject().fastGetConstantAt(&quot;SCRIPT_LINES__&quot;);
         RubyArray list = null;
         
@@ -106,10 +119,10 @@ public class Parser {
         
         DefaultRubyParser parser = null;
         RubyParserResult result = null;
+        parser = RubyParserPool.getInstance().borrowParser();
+        parser.setWarnings(runtime.getWarnings());
+        LexerSource lexerSource = LexerSource.getSource(file, content, list, configuration);
         try {
-            parser = RubyParserPool.getInstance().borrowParser();
-            parser.setWarnings(runtime.getWarnings());
-            LexerSource lexerSource = LexerSource.getSource(file, content, list, configuration);
             result = parser.parse(configuration, lexerSource);
             if (result.getEndOffset() &gt;= 0) {
                 IRubyObject verbose = runtime.getVerbose();
@@ -137,6 +150,11 @@ public class Parser {
             result.getScope().growIfNeeded();
         }
 
-        return result.getAST();
+        Node ast = result.getAST();
+        
+        totalTime += System.nanoTime() - startTime;
+        totalBytes += lexerSource.getOffset();
+
+        return ast;
     }
 }</diff>
      <filename>src/org/jruby/parser/Parser.java</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>acfa0b5f5fbfbd608c4aefe65d4a895d89730b36</id>
    </parent>
  </parents>
  <author>
    <name>headius</name>
    <email>headius@961051c9-f516-0410-bf72-c9f7e237a7b7</email>
  </author>
  <url>http://github.com/vvs/jruby/commit/8ddd9b8feae1f499156e2aa70312174060354c32</url>
  <id>8ddd9b8feae1f499156e2aa70312174060354c32</id>
  <committed-date>2008-08-31T03:14:21-07:00</committed-date>
  <authored-date>2008-08-31T03:14:21-07:00</authored-date>
  <message>Add a ParserStats MBean to gather metrics on time spent parsing.


git-svn-id: https://svn.codehaus.org/jruby/trunk/jruby@7608 961051c9-f516-0410-bf72-c9f7e237a7b7</message>
  <tree>58d79c9c477d03f50a827c63256cbc74983a4b53</tree>
  <committer>
    <name>headius</name>
    <email>headius@961051c9-f516-0410-bf72-c9f7e237a7b7</email>
  </committer>
</commit>
