You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2011/10/12 16:46:19 UTC
svn commit: r1182408 -
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
Author: jukka
Date: Wed Oct 12 14:46:19 2011
New Revision: 1182408
URL: http://svn.apache.org/viewvc?rev=1182408&view=rev
Log:
JCR-3040: JMX Stats for the Session
Measure read and write duration of SessionOperations
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java?rev=1182408&r1=1182407&r2=1182408&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java Wed Oct 12 14:46:19 2011
@@ -53,16 +53,6 @@ public class SessionState {
LoggerFactory.getLogger(SessionState.class);
/**
- * Number of nanoseconds in a microsecond.
- */
- private static final int NS_PER_US = 1000;
-
- /**
- * Number of nanoseconds in a millisecond.
- */
- private static final int NS_PER_MS = 1000000;
-
- /**
* Component context of this session.
*/
private final SessionContext context;
@@ -78,6 +68,16 @@ public class SessionState {
private final AtomicLong writeCounter;
/**
+ * Duration of read operations.
+ */
+ private final AtomicLong readDuration;
+
+ /**
+ * Duration of write operations.
+ */
+ private final AtomicLong writeDuration;
+
+ /**
* The lock used to guarantee synchronized execution of repository
* operations. An explicit lock is used instead of normal Java
* synchronization in order to be able to log attempts to concurrently
@@ -113,6 +113,8 @@ public class SessionState {
statistics.getCounter("login").incrementAndGet();
this.readCounter = statistics.getCounter("read");
this.writeCounter = statistics.getCounter("write");
+ this.readDuration = statistics.getCounter("read.duration");
+ this.writeDuration = statistics.getCounter("write.duration");
}
/**
@@ -198,31 +200,24 @@ public class SessionState {
}
try {
- // JCR-3040: Increment the operation counters
- if (isWriteOperation) {
- writeCounter.incrementAndGet();
- } else {
- readCounter.incrementAndGet();
- }
+ // Perform the actual operation
+ log.debug("Performing {}", operation);
+ long start = System.nanoTime();
+ try {
+ return operation.perform(context);
+ } finally {
+ long time = System.nanoTime() - start;
- // Perform the actual operation, optionally with debug logs
- if (log.isDebugEnabled()) {
- log.debug("Performing {}", operation);
- long start = System.nanoTime();
- try {
- return operation.perform(context);
- } finally {
- long time = System.nanoTime() - start;
- if (time > NS_PER_MS) {
- log.debug("Performed {} in {}ms",
- operation, time / NS_PER_MS);
- } else {
- log.debug("Performed {} in {}us",
- operation, time / NS_PER_US);
- }
+ // JCR-3040: Increment the operation counters
+ if (isWriteOperation) {
+ writeCounter.incrementAndGet();
+ writeDuration.addAndGet(time);
+ } else {
+ readCounter.incrementAndGet();
+ readDuration.addAndGet(time);
}
- } else {
- return operation.perform(context);
+
+ log.debug("Performed {} in {}us", operation, time);
}
} finally {
isWriteOperation = wasWriteOperation;