jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1186660 - in /jackrabbit/trunk: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/
Date Thu, 20 Oct 2011 08:12:41 GMT
Author: alexparvulescu
Date: Thu Oct 20 08:12:40 2011
New Revision: 1186660

URL: http://svn.apache.org/viewvc?rev=1186660&view=rev
Log:
JCR-3124 Stats for Queries

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatCore.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/StatManager.java

Modified: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java?rev=1186660&r1=1186659&r2=1186660&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java
(original)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java
Thu Oct 20 08:12:40 2011
@@ -22,8 +22,6 @@ package org.apache.jackrabbit.api.stats;
  */
 public interface QueryStat {
 
-    void logQuery(final String language, final String statement, long duration);
-
     /** Slowest Queries */
 
     QueryStatDto[] getSlowQueries();
@@ -50,7 +48,7 @@ public interface QueryStat {
 
     double getAvgQueryTime();
 
-    /** Generic Stats Stuff */
+    /** -- GENERAL OPS -- **/
 
     /**
      * If this service is currently registering stats

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java?rev=1186660&r1=1186659&r2=1186660&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
Thu Oct 20 08:12:40 2011
@@ -133,11 +133,10 @@ public class QueryImpl extends AbstractQ
                         return "query.execute(" + statement + ")";
                     }
                 });
-
-        if (log.isDebugEnabled()) {
-            time = System.currentTimeMillis() - time;
-            log.debug("executed in {} ms. ({})", time, statement);
-        }
+        time = System.currentTimeMillis() - time;
+        log.debug("executed in {} ms. ({})", time, statement);
+        sessionContext.getRepositoryContext().getStatManager().getQueryStat()
+                .logQuery(language, statement, time);
         return result;
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java?rev=1186660&r1=1186659&r2=1186660&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
Thu Oct 20 08:12:40 2011
@@ -131,10 +131,10 @@ public class QueryObjectModelImpl extend
                         return "query.execute(" + statement + ")";
                     }
                 });
-        if (log.isDebugEnabled()) {
-            time = System.currentTimeMillis() - time;
-            log.debug("executed in {} ms. ({})", time, statement);
-        }
+        time = System.currentTimeMillis() - time;
+        log.debug("executed in {} ms. ({})", time, statement);
+        sessionContext.getRepositoryContext().getStatManager().getQueryStat()
+                .logQuery(language, statement, time);
         return result;
     }
 

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatCore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatCore.java?rev=1186660&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatCore.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatCore.java
Thu Oct 20 08:12:40 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.stats;
+
+import org.apache.jackrabbit.api.stats.QueryStat;
+
+/**
+ * Extends external facing {@link QueryStat} with some internal operations
+ * 
+ */
+public interface QueryStatCore extends QueryStat {
+
+    /**
+     * Logs the call of each query ran on the repository.
+     * 
+     * @param language
+     *            the query language, see
+     *            {@link org.apache.jackrabbit.spi.commons.name.NameConstants#JCR_LANGUAGE}
+     * @param statement
+     *            the query
+     * @param duration
+     *            time in ms
+     */
+    void logQuery(final String language, final String statement, long durationMs);
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatCore.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java?rev=1186660&r1=1186659&r2=1186660&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java
Thu Oct 20 08:12:40 2011
@@ -40,9 +40,9 @@ public class QueryStatDtoImpl implements
     private final Date creationTime;
 
     /**
-     * run duration
+     * run duration in ms
      */
-    private final long duration;
+    private final long durationMs;
 
     /**
      * query language
@@ -55,18 +55,18 @@ public class QueryStatDtoImpl implements
     private final String statement;
 
     public QueryStatDtoImpl(final String language, final String statement,
-            long duration) {
-        this.duration = duration;
+            long durationMs) {
+        this.durationMs = durationMs;
         this.language = language;
         this.statement = statement;
 
         Calendar c = Calendar.getInstance();
-        c.setTimeInMillis(System.currentTimeMillis() - duration);
+        c.setTimeInMillis(System.currentTimeMillis() - durationMs);
         this.creationTime = c.getTime();
     }
 
     public long getDuration() {
-        return duration;
+        return durationMs;
     }
 
     public String getLanguage() {
@@ -92,7 +92,7 @@ public class QueryStatDtoImpl implements
     @Override
     public String toString() {
         return "QueryStat [creationTime=" + creationTime + ", duration="
-                + duration + ", language=" + language + ", statement="
+                + durationMs + ", language=" + language + ", statement="
                 + statement + "]";
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java?rev=1186660&r1=1186659&r2=1186660&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
Thu Oct 20 08:12:40 2011
@@ -19,15 +19,14 @@ package org.apache.jackrabbit.core.stats
 import java.util.Comparator;
 import java.util.PriorityQueue;
 
-import org.apache.jackrabbit.api.stats.QueryStat;
 import org.apache.jackrabbit.api.stats.QueryStatDto;
 import org.apache.jackrabbit.core.stats.util.CachingOpsPerSecondDto;
 
 /**
- * Default {@link QueryStat} implementation
+ * Default {@link QueryStatCore} implementation
  * 
  */
-public class QueryStatImpl implements QueryStat {
+public class QueryStatImpl implements QueryStatCore {
 
     private final static Comparator<QueryStatDto> comparator = new QueryStatDtoComparator();
 
@@ -47,10 +46,12 @@ public class QueryStatImpl implements Qu
         return queueSize;
     }
 
-    public synchronized void setSlowQueriesQueueSize(int size) {
-        this.queueSize = size;
-        this.queries = new PriorityQueue<QueryStatDto>(this.queueSize + 1,
-                comparator);
+    public void setSlowQueriesQueueSize(int size) {
+        synchronized (queries) {
+            this.queueSize = size;
+            this.queries = new PriorityQueue<QueryStatDto>(this.queueSize + 1,
+                    comparator);
+        }
     }
 
     public boolean isEnabled() {
@@ -58,25 +59,31 @@ public class QueryStatImpl implements Qu
     }
 
     public void setEnabled(boolean enabled) {
-        this.enabled = enabled;
-        this.queries = new PriorityQueue<QueryStatDto>(this.queueSize + 1,
-                comparator);
+        synchronized (queries) {
+            this.enabled = enabled;
+            this.queries = new PriorityQueue<QueryStatDto>(this.queueSize + 1,
+                    comparator);
+        }
     }
 
-    public synchronized void logQuery(final String language,
-            final String statement, long duration) {
+    public void logQuery(final String language, final String statement,
+            long durationMs) {
         if (!enabled) {
             return;
         }
-        queries.add(new QueryStatDtoImpl(language, statement, duration));
-        if (queries.size() > queueSize) {
-            queries.remove();
+        synchronized (queries) {
+            queries.add(new QueryStatDtoImpl(language, statement, durationMs));
+            if (queries.size() > queueSize) {
+                queries.remove();
+            }
+            qps.onOp(durationMs);
         }
-        qps.onOp(duration * 1000);
     }
 
     public void clearSlowQueriesQueue() {
-        this.queries.clear();
+        synchronized (queries) {
+            queries.clear();
+        }
     }
 
     public void reset() {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/StatManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/StatManager.java?rev=1186660&r1=1186659&r2=1186660&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/StatManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/StatManager.java
Thu Oct 20 08:12:40 2011
@@ -17,7 +17,7 @@
 package org.apache.jackrabbit.core.stats;
 
 import static java.lang.Boolean.getBoolean;
-import org.apache.jackrabbit.api.stats.QueryStat;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,7 +36,7 @@ public class StatManager {
             .getLogger(StatManager.class);
 
     /* STAT OBJECTS */
-    private final QueryStat queryStat = new QueryStatImpl();
+    private final QueryStatCore queryStat = new QueryStatImpl();
 
     private final PersistenceManagerStatCore pmStat = new PersistenceManagerStatImpl();
 
@@ -54,7 +54,7 @@ public class StatManager {
                 new Object[] { queryStat.isEnabled(), pmStat.isEnabled() });
     }
 
-    public QueryStat getQueryStat() {
+    public QueryStatCore getQueryStat() {
         return queryStat;
     }
 



Mime
View raw message