incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/2] git commit: Adding trace value to more easily associate calling and executing threads.
Date Tue, 26 Nov 2013 02:32:34 GMT
Adding trace value to more easily associate calling and executing threads.


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

Branch: refs/heads/apache-blur-0.2
Commit: c49c21a86a3498651e4501f461842cef967cadf1
Parents: 528d1fb
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Nov 25 21:31:39 2013 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Nov 25 21:31:39 2013 -0500

----------------------------------------------------------------------
 .../main/java/org/apache/blur/trace/Trace.java   | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c49c21a8/blur-util/src/main/java/org/apache/blur/trace/Trace.java
----------------------------------------------------------------------
diff --git a/blur-util/src/main/java/org/apache/blur/trace/Trace.java b/blur-util/src/main/java/org/apache/blur/trace/Trace.java
index 4bd0a43..d11a5e5 100644
--- a/blur-util/src/main/java/org/apache/blur/trace/Trace.java
+++ b/blur-util/src/main/java/org/apache/blur/trace/Trace.java
@@ -19,6 +19,7 @@ package org.apache.blur.trace;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Random;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -49,6 +50,12 @@ public class Trace {
   private static ThreadLocal<TraceCollector> _tracer = new ThreadLocal<TraceCollector>();
   private static TraceReporter _reporter;
   private static String _nodeName;
+  private static ThreadLocal<Random> _random = new ThreadLocal<Random>() {
+    @Override
+    protected Random initialValue() {
+      return new Random();
+    }
+  };
 
   public static String getNodeName() {
     return _nodeName;
@@ -62,7 +69,7 @@ public class Trace {
     TraceCollector collector = new TraceCollector(_nodeName, id);
     _tracer.set(collector);
   }
-  
+
   public static Parameter param(Object name, Object value) {
     if (name == null) {
       name = "null";
@@ -112,15 +119,18 @@ public class Trace {
     if (tc == null) {
       return runnable;
     }
-    Tracer trace = Trace.trace("new runnable");
+    final long threadId = _random.get().nextLong();
+    Tracer trace = Trace.trace("new runnable", Trace.param("thread_trace", threadId));
     try {
       return new Runnable() {
         @Override
         public void run() {
           setupTraceOnNewThread(tc);
+          Tracer t = Trace.trace("executing runnable", Trace.param("thread_trace", threadId));
           try {
             runnable.run();
           } finally {
+            t.done();
             tearDownTraceOnNewThread();
           }
         }
@@ -135,15 +145,18 @@ public class Trace {
     if (tc == null) {
       return callable;
     }
-    Tracer trace = Trace.trace("new callable");
+    final long threadId = _random.get().nextLong();
+    Tracer trace = Trace.trace("new callable", Trace.param("thread_trace", threadId));
     try {
       return new Callable<V>() {
         @Override
         public V call() throws Exception {
           setupTraceOnNewThread(tc);
+          Tracer t = Trace.trace("executing callable", Trace.param("thread_trace", threadId));
           try {
             return callable.call();
           } finally {
+            t.done();
             tearDownTraceOnNewThread();
           }
         }


Mime
View raw message