jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1188678 - in /jackrabbit/trunk: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/
Date Tue, 25 Oct 2011 14:48:27 GMT
Author: jukka
Date: Tue Oct 25 14:48:26 2011
New Revision: 1188678

URL: http://svn.apache.org/viewvc?rev=1188678&view=rev
Log:
JCR-3117: Stats for the PersistenceManager

Add also average duration statistics for session and bundle read and write operations.

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesAverage.java
Modified:
    jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java

Modified: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java?rev=1188678&r1=1188677&r2=1188678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java
(original)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java
Tue Oct 25 14:48:26 2011
@@ -26,13 +26,17 @@ public interface RepositoryStatistics {
     enum Type {
         BUNDLE_READ_COUNTER(true),
         BUNDLE_READ_DURATION(true),
+        BUNDLE_READ_AVERAGE(false),
         BUNDLE_WRITE_COUNTER(true),
         BUNDLE_WRITE_DURATION(true),
+        BUNDLE_WRITE_AVERAGE(false),
         BUNDLE_CACHE_COUNTER(true),
         SESSION_READ_COUNTER(true),
         SESSION_READ_DURATION(true),
+        SESSION_READ_AVERAGE(false),
         SESSION_WRITE_COUNTER(true),
         SESSION_WRITE_DURATION(true),
+        SESSION_WRITE_AVERAGE(false),
         SESSION_LOGIN_COUNTER(true),
         SESSION_COUNT(false);
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java?rev=1188678&r1=1188677&r2=1188678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java
Tue Oct 25 14:48:26 2011
@@ -35,17 +35,28 @@ public class RepositoryStatisticsImpl im
     private final Map<Type, TimeSeriesRecorder> recorders =
             new HashMap<Type, TimeSeriesRecorder>();
 
+    private final Map<Type, TimeSeriesAverage> avg =
+            new HashMap<Type, TimeSeriesAverage>();
+
     public RepositoryStatisticsImpl() {
         getOrCreateRecorder(Type.SESSION_COUNT);
         getOrCreateRecorder(Type.SESSION_LOGIN_COUNTER);
-        getOrCreateRecorder(Type.SESSION_READ_COUNTER);
-        getOrCreateRecorder(Type.SESSION_READ_DURATION);
-        getOrCreateRecorder(Type.SESSION_WRITE_COUNTER);
-        getOrCreateRecorder(Type.SESSION_WRITE_DURATION);
-        getOrCreateRecorder(Type.BUNDLE_READ_COUNTER);
-        getOrCreateRecorder(Type.BUNDLE_READ_DURATION);
-        getOrCreateRecorder(Type.BUNDLE_WRITE_COUNTER);
-        getOrCreateRecorder(Type.BUNDLE_WRITE_DURATION);
+
+        TimeSeries src = getOrCreateRecorder(Type.SESSION_READ_COUNTER);
+        TimeSeries srd = getOrCreateRecorder(Type.SESSION_READ_DURATION);
+        avg.put(Type.SESSION_READ_AVERAGE, new TimeSeriesAverage(srd, src));
+
+        TimeSeries swc = getOrCreateRecorder(Type.SESSION_WRITE_COUNTER);
+        TimeSeries swd = getOrCreateRecorder(Type.SESSION_WRITE_DURATION);
+        avg.put(Type.SESSION_WRITE_AVERAGE, new TimeSeriesAverage(swd, swc));
+
+        TimeSeries brc = getOrCreateRecorder(Type.BUNDLE_READ_COUNTER);
+        TimeSeries brd = getOrCreateRecorder(Type.BUNDLE_READ_DURATION);
+        avg.put(Type.BUNDLE_READ_AVERAGE, new TimeSeriesAverage(brd, brc));
+
+        TimeSeries bwc = getOrCreateRecorder(Type.BUNDLE_WRITE_COUNTER);
+        TimeSeries bwd = getOrCreateRecorder(Type.BUNDLE_WRITE_DURATION);
+        avg.put(Type.BUNDLE_WRITE_AVERAGE, new TimeSeriesAverage(bwd, bwc));
     }
 
     public RepositoryStatisticsImpl(ScheduledExecutorService executor) {
@@ -60,6 +71,7 @@ public class RepositoryStatisticsImpl im
     public synchronized Iterator<Entry<Type, TimeSeries>> iterator() {
         Map<Type, TimeSeries> map = new TreeMap<Type, TimeSeries>();
         map.putAll(recorders);
+        map.putAll(avg);
         return map.entrySet().iterator();
     }
 
@@ -68,7 +80,11 @@ public class RepositoryStatisticsImpl im
     }
 
     public TimeSeries getTimeSeries(Type type) {
-        return getOrCreateRecorder(type);
+        if (avg.containsKey(type)) {
+            return avg.get(type);
+        } else {
+            return getOrCreateRecorder(type);
+        }
     }
 
     private synchronized TimeSeriesRecorder getOrCreateRecorder(Type type) {

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesAverage.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesAverage.java?rev=1188678&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesAverage.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesAverage.java
Tue Oct 25 14:48:26 2011
@@ -0,0 +1,85 @@
+/*
+ * 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.TimeSeries;
+
+/**
+ * Time series of the average calculated by dividing a measured
+ * value by the counter of events during the measurement period.
+ */
+class TimeSeriesAverage implements TimeSeries {
+
+    /** Value */
+    private final TimeSeries value;
+
+    /** Value */
+    private final TimeSeries counter;
+
+    public TimeSeriesAverage(TimeSeries value, TimeSeries counter) {
+        this.value = value;
+        this.counter = counter;
+    }
+
+    //----------------------------------------------------------< TimeSeries >
+
+    public long[] getValuePerSecond() {
+        long[] values = value.getValuePerSecond();
+        long[] counts = counter.getValuePerSecond();
+        return divide(values, counts);
+    }
+
+    public long[] getValuePerMinute() {
+        long[] values = value.getValuePerMinute();
+        long[] counts = counter.getValuePerMinute();
+        return divide(values, counts);
+    }
+
+    public synchronized long[] getValuePerHour() {
+        long[] values = value.getValuePerHour();
+        long[] counts = counter.getValuePerHour();
+        return divide(values, counts);
+    }
+
+    public synchronized long[] getValuePerWeek() {
+        long[] values = value.getValuePerWeek();
+        long[] counts = counter.getValuePerWeek();
+        return divide(values, counts);
+    }
+
+    //-------------------------------------------------------------< private >
+
+    /**
+     * Per-entry division of two arrays.
+     *
+     * @param a array
+     * @param b array
+     * @return result of division
+     */
+    private long[] divide(long[] a, long[] b) {
+        long[] c = new long[a.length];
+        for (int i = 0; i < a.length; i++) {
+            if (b[i] != 0) {
+                c[i] = a[i] / b[i];
+            } else {
+                c[i] = 0;
+            }
+        }
+        return c;
+    }
+
+}



Mime
View raw message