incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [6/8] git commit: Added a simple named timer to time and log events.
Date Wed, 28 Aug 2013 18:16:52 GMT
Added a simple named timer to time and log events.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/267d8ea9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/267d8ea9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/267d8ea9

Branch: refs/heads/master
Commit: 267d8ea98e53386117618a01ebda9a04e8979836
Parents: 00a29ab
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Wed Aug 28 14:10:47 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Wed Aug 28 14:10:47 2013 -0400

----------------------------------------------------------------------
 .../blur/manager/writer/BlurNRTIndex.java       |  9 +++-
 .../java/org/apache/blur/utils/SimpleTimer.java | 51 ++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/267d8ea9/blur-core/src/main/java/org/apache/blur/manager/writer/BlurNRTIndex.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/writer/BlurNRTIndex.java b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurNRTIndex.java
index cb3ba19..d593089 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/writer/BlurNRTIndex.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurNRTIndex.java
@@ -49,6 +49,7 @@ import org.apache.blur.server.TableContext;
 import org.apache.blur.thrift.generated.Record;
 import org.apache.blur.thrift.generated.Row;
 import org.apache.blur.utils.BlurUtil;
+import org.apache.blur.utils.SimpleTimer;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -110,7 +111,6 @@ public class BlurNRTIndex extends BlurIndex {
     if (snapshotsDirectoryExists()) {
       // load existing snapshots
       sdp = new SnapshotDeletionPolicy(_tableContext.getIndexDeletionPolicy(), loadExistingSnapshots());
-      
     } else {
       sdp = new SnapshotDeletionPolicy(_tableContext.getIndexDeletionPolicy());
     }
@@ -124,7 +124,12 @@ public class BlurNRTIndex extends BlurIndex {
     DirectoryReferenceCounter referenceCounter = new DirectoryReferenceCounter(directory,
gc, closer);
     // This directory allows for warm up by adding tracing ability.
     TraceableDirectory dir = new TraceableDirectory(referenceCounter);
+    
+    SimpleTimer simpleTimer = new SimpleTimer();
+    simpleTimer.start("writerOpen");
     _writer = new BlurIndexWriter(dir, conf, true);
+    simpleTimer.stop("writerOpen");
+    simpleTimer.start("nrtSetup");
     _recorder = new TransactionRecorder(shardContext);
     _recorder.replay(_writer);
 
@@ -151,6 +156,8 @@ public class BlurNRTIndex extends BlurIndex {
     _refresher.setName("Refresh Thread [" + _tableContext.getTable() + "/" + shardContext.getShard()
+ "]");
     _refresher.setDaemon(true);
     _refresher.start();
+    simpleTimer.stop("nrtSetup");
+    simpleTimer.log(LOG);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/267d8ea9/blur-core/src/main/java/org/apache/blur/utils/SimpleTimer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/utils/SimpleTimer.java b/blur-core/src/main/java/org/apache/blur/utils/SimpleTimer.java
new file mode 100644
index 0000000..69eb8cd
--- /dev/null
+++ b/blur-core/src/main/java/org/apache/blur/utils/SimpleTimer.java
@@ -0,0 +1,51 @@
+package org.apache.blur.utils;
+
+/**
+ * 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.
+ */
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.blur.log.Log;
+
+public class SimpleTimer {
+
+  private Map<String, Long> _startTimes = new HashMap<String, Long>();
+  private Map<String, Long> _stopTimes = new HashMap<String, Long>();
+
+  public void start(String name) {
+    _startTimes.put(name, System.nanoTime());
+  }
+
+  public void stop(String name) {
+    _stopTimes.put(name, System.nanoTime());
+  }
+
+  public void log(Log log) {
+    for (Entry<String, Long> e : _startTimes.entrySet()) {
+      long startTime = e.getValue();
+      Long stopTime = _stopTimes.get(e.getKey());
+      if (stopTime != null) {
+        log.info("Timer Name [{0}] took [{1} ms]", e.getKey(), TimeUnit.NANOSECONDS.toMillis(stopTime
- startTime));
+      } else {
+        log.info("Timer Name [{0}] never finished", e.getKey());
+      }
+    }
+  }
+
+}


Mime
View raw message