jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1186195 - in /jackrabbit/trunk: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/ jackrabbit-core/src/mai...
Date Wed, 19 Oct 2011 13:23:14 GMT
Author: alexparvulescu
Date: Wed Oct 19 13:23:13 2011
New Revision: 1186195

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

Added:
    jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/PersistenceManagerStat.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatCore.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatImpl.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheAccessListener.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PMContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/StatManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDto.java

Added: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/PersistenceManagerStat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/PersistenceManagerStat.java?rev=1186195&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/PersistenceManagerStat.java
(added)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/PersistenceManagerStat.java
Wed Oct 19 13:23:13 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.api.stats;
+
+/**
+ * Statistics for the PersistenceManager
+ */
+public interface PersistenceManagerStat {
+
+    long getCacheAccessCount();
+
+    long getCacheMissCount();
+
+    double getCacheMissAvgDuration();
+
+    double getBundleWritesPerSecond();
+
+    /** -- GENERAL OPS -- **/
+
+    /**
+     * If this service is currently registering stats
+     * 
+     * @return <code>true</code> if the service is enabled
+     */
+    boolean isEnabled();
+
+    /**
+     * Enables/Disables the service
+     * 
+     * @param enabled
+     */
+    void setEnabled(boolean enabled);
+
+    /**
+     * clears all data
+     */
+    void reset();
+
+}

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java?rev=1186195&r1=1186194&r2=1186195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
Wed Oct 19 13:23:13 2011
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.core.securi
 import org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry;
 import org.apache.jackrabbit.core.state.ItemStateCacheFactory;
 import org.apache.jackrabbit.core.stats.RepositoryStatisticsImpl;
+import org.apache.jackrabbit.core.stats.StatManager;
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
 
 /**
@@ -118,6 +119,11 @@ public class RepositoryContext {
     private final RepositoryStatisticsImpl statistics;
 
     /**
+     * The Statistics manager, handles statistics
+     */
+    private StatManager statManager;
+
+    /**
      * Creates a component context for the given repository.
      *
      * @param repository repository instance
@@ -126,6 +132,7 @@ public class RepositoryContext {
         assert repository != null;
         this.repository = repository;
         this.statistics = new RepositoryStatisticsImpl(executor);
+        this.statManager = new StatManager();
     }
 
     /**
@@ -415,4 +422,11 @@ public class RepositoryContext {
         return statistics;
     }
 
+    /**
+     * @return the statistics manager object
+     */
+    public StatManager getStatManager() {
+        return statManager;
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=1186195&r1=1186194&r2=1186195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Wed Oct 19 13:23:13 2011
@@ -1330,13 +1330,14 @@ public class RepositoryImpl extends Abst
             File homeDir, FileSystem fs, PersistenceManagerConfig pmConfig)
             throws RepositoryException {
         try {
-            PersistenceManager pm = pmConfig.newInstance(PersistenceManager.class);
-            pm.init(new PMContext(
-                    homeDir, fs,
-                    context.getRootNodeId(),
-                    context.getNamespaceRegistry(),
-                    context.getNodeTypeRegistry(),
-                    context.getDataStore()));
+            PersistenceManager pm = pmConfig
+                    .newInstance(PersistenceManager.class);
+            PMContext pmContext = new PMContext(homeDir, fs,
+                    context.getRootNodeId(), context.getNamespaceRegistry(),
+                    context.getNodeTypeRegistry(), context.getDataStore());
+            pmContext.setPersistenceManagerStatCore(context.getStatManager()
+                    .getPersistenceManagerStatCore());
+            pm.init(pmContext);
             return pm;
         } catch (Exception e) {
             String msg = "Cannot instantiate persistence manager " + pmConfig.getClassName();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java?rev=1186195&r1=1186194&r2=1186195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java
Wed Oct 19 13:23:13 2011
@@ -119,7 +119,7 @@ public abstract class AbstractCache impl
         if (count % ACCESS_INTERVAL == 0) {
             CacheAccessListener listener = accessListener.get();
             if (listener != null) {
-                listener.cacheAccessed(count);
+                listener.cacheAccessed(ACCESS_INTERVAL);
             }
         }
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheAccessListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheAccessListener.java?rev=1186195&r1=1186194&r2=1186195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheAccessListener.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheAccessListener.java
Wed Oct 19 13:23:13 2011
@@ -28,8 +28,15 @@ public interface CacheAccessListener {
     int ACCESS_INTERVAL = 127;
 
     /**
-     * The cache calls this method after a number of accessed.<br>
-     * For statistical purposes, the cache access count is included
+     * The cache calls this method after a number of cache accesses.<br>
+     * 
+     * For statistical purposes, the cache access count since the last call is
+     * included. In normal circumstances this is equal to
+     * {@link CacheAccessListener#ACCESS_INTERVAL}
+     * 
+     * @param accessCount
+     *            number of cache accesses since the last call
+     * 
      */
     void cacheAccessed(long accessCount);
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PMContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PMContext.java?rev=1186195&r1=1186194&r2=1186195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PMContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PMContext.java
Wed Oct 19 13:23:13 2011
@@ -16,13 +16,15 @@
  */
 package org.apache.jackrabbit.core.persistence;
 
+import java.io.File;
+
+import javax.jcr.NamespaceRegistry;
+
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.id.NodeId;
-
-import javax.jcr.NamespaceRegistry;
-import java.io.File;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.stats.PersistenceManagerStatCore;
 
 /**
  * A <code>PMContext</code> is used to provide context information for a
@@ -63,6 +65,11 @@ public class PMContext {
     private final DataStore dataStore;
 
     /**
+     * PersistenceManagerStatCore stats object for the PM.
+     */
+    private PersistenceManagerStatCore persistenceManagerStatCore;
+
+    /**
      * Creates a new <code>PMContext</code>.
      *
      * @param homeDir the physical home directory
@@ -136,4 +143,18 @@ public class PMContext {
     public DataStore getDataStore() {
         return dataStore;
     }
+
+    /**
+     * Returns the PersistenceManagerStatCore stats object for the PM.
+     * 
+     * @return the PersistenceManagerStatCore stats object for the PM.
+     */
+    public PersistenceManagerStatCore getPersistenceManagerStatCore() {
+        return persistenceManagerStatCore;
+    }
+
+    public void setPersistenceManagerStatCore(
+            PersistenceManagerStatCore persistenceManagerStatCore) {
+        this.persistenceManagerStatCore = persistenceManagerStatCore;
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java?rev=1186195&r1=1186194&r2=1186195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
Wed Oct 19 13:23:13 2011
@@ -26,13 +26,11 @@ import java.util.Set;
 
 import javax.jcr.PropertyType;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.jackrabbit.core.cache.Cache;
 import org.apache.jackrabbit.core.cache.CacheAccessListener;
 import org.apache.jackrabbit.core.cache.ConcurrentCache;
-import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.id.PropertyId;
@@ -44,16 +42,19 @@ import org.apache.jackrabbit.core.persis
 import org.apache.jackrabbit.core.persistence.util.FileBasedIndex;
 import org.apache.jackrabbit.core.persistence.util.NodePropBundle;
 import org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry;
-import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.core.state.ItemStateException;
-import org.apache.jackrabbit.core.state.NodeReferences;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
-import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.NodeReferences;
 import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.stats.PersistenceManagerStatCore;
 import org.apache.jackrabbit.core.util.StringIndex;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The <code>AbstractBundlePersistenceManager</code> acts as base for all
@@ -132,6 +133,9 @@ public abstract class AbstractBundlePers
     /** default size of the bundle cache */
     private long bundleCacheSize = 8 * 1024 * 1024;
 
+    /** statistics object */
+    private PersistenceManagerStatCore pmStatCore;
+
     /**
      * Returns the size of the bundle cache in megabytes.
      * @return the size of the bundle cache in megabytes.
@@ -394,6 +398,7 @@ public abstract class AbstractBundlePers
         bundles = new ConcurrentCache<NodeId, NodePropBundle>(context.getHomeDir().getName()
+ "BundleCache");
         bundles.setMaxMemorySize(bundleCacheSize);
         bundles.setAccessListener(this);
+        pmStatCore = context.getPersistenceManagerStatCore();
     }
 
     /**
@@ -665,14 +670,42 @@ public abstract class AbstractBundlePers
         NodePropBundle bundle = bundles.get(id);
         if (bundle == MISSING) {
             return null;
-        } else if (bundle == null) {
-            bundle = loadBundle(id);
-            if (bundle != null) {
-                bundle.markOld();
-                bundles.put(id, bundle, bundle.getSize());
-            } else {
-                bundles.put(id, MISSING, 16);
+        }
+        if (bundle != null) {
+            return bundle;
+        }
+        // cache miss
+        if (pmStatCore != null && pmStatCore.isEnabled()) {
+            long t = System.currentTimeMillis();
+            try {
+                return getBundleCacheMiss(id);
+            } finally {
+                t = System.currentTimeMillis() - t;
+                pmStatCore.onReadCacheMiss(t);
             }
+        } else {
+            return getBundleCacheMiss(id);
+        }
+    }
+
+    /**
+     * Called when the bundle is not present in the cache, so we'll need to load
+     * it from the PM impl.
+     * 
+     * This also updates the cache.
+     * 
+     * @param id
+     * @return
+     * @throws ItemStateException
+     */
+    private NodePropBundle getBundleCacheMiss(NodeId id)
+            throws ItemStateException {
+        NodePropBundle bundle = loadBundle(id);
+        if (bundle != null) {
+            bundle.markOld();
+            bundles.put(id, bundle, bundle.getSize());
+        } else {
+            bundles.put(id, MISSING, 16);
         }
         return bundle;
     }
@@ -696,9 +729,15 @@ public abstract class AbstractBundlePers
      * @throws ItemStateException if an error occurs
      */
     private void putBundle(NodePropBundle bundle) throws ItemStateException {
+
+        long time = System.currentTimeMillis();
         storeBundle(bundle);
         bundle.markOld();
-        log.debug("stored bundle {}", bundle.getId());
+        log.debug("stored bundle {} in {} ms", new Object[] { bundle.getId(),
+                System.currentTimeMillis() - time });
+        if (pmStatCore != null && pmStatCore.isEnabled()) {
+            pmStatCore.onBundleWrite(System.currentTimeMillis() - time);
+        }
 
         // only put to cache if already exists. this is to ensure proper
         // overwrite and not creating big contention during bulk loads
@@ -726,6 +765,7 @@ public abstract class AbstractBundlePers
 
     public void cacheAccessed(long accessCount) {
         logCacheStats();
+        pmStatCore.cacheAccessed(accessCount);
     }
 
     private void logCacheStats() {

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatCore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatCore.java?rev=1186195&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatCore.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatCore.java
Wed Oct 19 13:23:13 2011
@@ -0,0 +1,37 @@
+/*
+ * 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.PersistenceManagerStat;
+
+public interface PersistenceManagerStatCore extends PersistenceManagerStat {
+
+    /**
+     * @param durationMs
+     *            in milliseconds
+     */
+    void onReadCacheMiss(long durationMs);
+
+    /**
+     * @param durationMs
+     *            in milliseconds
+     */
+    void onBundleWrite(long durationMs);
+
+    void cacheAccessed(long accessCount);
+
+}

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

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatImpl.java?rev=1186195&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatImpl.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/PersistenceManagerStatImpl.java
Wed Oct 19 13:23:13 2011
@@ -0,0 +1,94 @@
+/*
+ * 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 java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.jackrabbit.core.stats.util.CachingOpsPerSecondDto;
+
+/**
+ * Default PersistenceManagerStat impl
+ * 
+ */
+public class PersistenceManagerStatImpl implements PersistenceManagerStatCore {
+
+    private boolean enabled = false;
+
+    private final CachingOpsPerSecondDto bundleWriteOps = new CachingOpsPerSecondDto();
+
+    private final AtomicLong cacheAccessCount = new AtomicLong();
+
+    private final CachingOpsPerSecondDto cacheReadMissLatency = new CachingOpsPerSecondDto();
+
+    public void onReadCacheMiss(long durationMs) {
+        if (!enabled) {
+            return;
+        }
+        cacheReadMissLatency.onOp(durationMs);
+    }
+
+    public void onBundleWrite(long durationMs) {
+        if (!enabled) {
+            return;
+        }
+        bundleWriteOps.onOp(durationMs);
+    }
+
+    public void cacheAccessed(long accessCount) {
+        if (!enabled) {
+            return;
+        }
+        cacheAccessCount.addAndGet(accessCount);
+    }
+
+    /** -- PersistenceManagerStat -- **/
+
+    public long getCacheMissCount() {
+        return cacheReadMissLatency.getOperations();
+    }
+
+    public double getCacheMissAvgDuration() {
+        return cacheReadMissLatency.getOpAvgTime();
+    }
+
+    public long getCacheAccessCount() {
+        return cacheAccessCount.get();
+    }
+
+    public double getBundleWritesPerSecond() {
+        return bundleWriteOps.getOpsPerSecond();
+    }
+
+    /** -- GENERAL OPS -- **/
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+        if (this.enabled) {
+            reset();
+        }
+    }
+
+    public void reset() {
+        bundleWriteOps.reset();
+        cacheReadMissLatency.reset();
+        cacheAccessCount.set(0);
+    }
+}

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

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=1186195&r1=1186194&r2=1186195&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
Wed Oct 19 13:23:13 2011
@@ -16,35 +16,49 @@
  */
 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;
 
 /**
- * StatManager represents a single entry point to the stats objects available.<br>
+ * StatManager represents a single entry point to the statistics objects
+ * available.<br>
  * 
  */
 public class StatManager {
 
+    public static String ALL_STATS_ENABLED_PROPERTY = "org.apache.jackrabbit.api.stats.ALL";
+    public static String QUERY_STATS_ENABLED_PROPERTY = "org.apache.jackrabbit.api.stats.QueryStat";
+    public static String PM_STATS_ENABLED_PROPERTY = "org.apache.jackrabbit.api.stats.PersistenceManagerStat";
+
     private static final Logger log = LoggerFactory
             .getLogger(StatManager.class);
 
-    /* STATS */
+    /* STAT OBJECTS */
     private final QueryStat queryStat = new QueryStatImpl();
 
+    private final PersistenceManagerStatCore pmStat = new PersistenceManagerStatImpl();
+
     public StatManager() {
+        init();
     }
 
-    public void init() {
-        queryStat.setEnabled(false);
-        log.debug("Started StatManager");
-    }
-
-    public void stop() {
-
+    protected void init() {
+        boolean allEnabled = getBoolean(ALL_STATS_ENABLED_PROPERTY);
+        queryStat.setEnabled(allEnabled
+                || getBoolean(QUERY_STATS_ENABLED_PROPERTY));
+        pmStat.setEnabled(allEnabled || getBoolean(PM_STATS_ENABLED_PROPERTY));
+        log.debug(
+                "Started StatManager. QueryStat is enabled {}, PersistenceManagerStat is
enabled {}",
+                new Object[] { queryStat.isEnabled(), pmStat.isEnabled() });
     }
 
     public QueryStat getQueryStat() {
         return queryStat;
     }
+
+    public PersistenceManagerStatCore getPersistenceManagerStatCore() {
+        return pmStat;
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDto.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDto.java?rev=1186195&r1=1186194&r2=1186195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDto.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDto.java
Wed Oct 19 13:23:13 2011
@@ -45,7 +45,7 @@ public class CachingOpsPerSecondDto {
 
     private long operations = 0;
 
-    private long totalTimeNs = 0;
+    private long totalTimeMs = 0;
 
     // cached stats
 
@@ -61,15 +61,15 @@ public class CachingOpsPerSecondDto {
         this(DEFAULT_UPDATE_FREQ_MS);
     }
 
-    public void onOp(long timeNs) {
+    public void onOp(long timeMs) {
         w.lock();
         try {
-            final long localStart = System.currentTimeMillis() - timeNs / 1000;
+            final long localStart = System.currentTimeMillis() - timeMs;
             if (localStart < startMs) {
                 startMs = localStart;
             }
             operations++;
-            totalTimeNs += timeNs;
+            totalTimeMs += timeMs;
         } finally {
             w.unlock();
         }
@@ -85,6 +85,10 @@ public class CachingOpsPerSecondDto {
         return opAvgTime;
     }
 
+    public long getOperations() {
+        return operations;
+    }
+
     private void checkUpdate(boolean forceUpdate) {
         r.lock();
         final long now = System.currentTimeMillis();
@@ -110,26 +114,22 @@ public class CachingOpsPerSecondDto {
 
     private final static MathContext DEFAULT_CONTEXT = new MathContext(3);
 
-    private void update(long now) {
+    private void update(final long now) {
         if (operations == 0) {
             opsPerSecond = 0;
             opAvgTime = 0;
             return;
         }
         long durationMs = now - startMs;
-        if (durationMs == 0) {
+        if (durationMs < 1000) {
             durationMs = 1000;
         }
         opsPerSecond = BigDecimal.valueOf(operations).multiply(thousand)
                 .divide(BigDecimal.valueOf(durationMs), DEFAULT_CONTEXT)
                 .doubleValue();
-        opAvgTime = BigDecimal.valueOf(totalTimeNs)
+        opAvgTime = BigDecimal.valueOf(totalTimeMs)
                 .divide(BigDecimal.valueOf(operations), DEFAULT_CONTEXT)
                 .doubleValue();
-        // reset if needed
-        if (operations > Long.MAX_VALUE - 5000) {
-            reset();
-        }
     }
 
     public void reset() {
@@ -140,7 +140,7 @@ public class CachingOpsPerSecondDto {
             lastUpdate = System.currentTimeMillis();
             operations = 0;
             startMs = lastUpdate;
-            totalTimeNs = 0;
+            totalTimeMs = 0;
         } finally {
             w.unlock();
         }



Mime
View raw message