]> source.dussan.org Git - sonarqube.git/commitdiff
Improve Profiling output for *Index Classes
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 4 Aug 2014 10:14:33 +0000 (12:14 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 4 Aug 2014 12:05:09 +0000 (14:05 +0200)
server/sonar-server/src/main/java/org/sonar/server/search/ESNode.java
sonar-core/src/main/java/org/sonar/core/profiling/Profiling.java

index a6e28704afad13040c0a499f998c0765009a97c5..3e8d0dfdcdb71a00bfae243038751e977934866f 100644 (file)
@@ -34,6 +34,9 @@ import org.elasticsearch.common.logging.slf4j.Slf4jESLoggerFactory;
 import org.elasticsearch.common.network.NetworkUtils;
 import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.transport.InetSocketTransportAddress;
+import org.elasticsearch.common.xcontent.ToXContent;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.node.Node;
 import org.elasticsearch.node.NodeBuilder;
 import org.picocontainer.Startable;
@@ -287,17 +290,31 @@ public class ESNode implements Startable {
   }
 
   public <K extends ActionResponse> K execute(ActionRequestBuilder action) {
-    StopWatch requestProfile = profiling.start("search", Profiling.Level.BASIC);
+    StopWatch basicProfile = profiling.start("search", Profiling.Level.BASIC);
+    StopWatch fullProfile = profiling.start("search", Profiling.Level.FULL);
     ListenableActionFuture acc = action.execute();
     try {
+
+      if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+        basicProfile.stop("ES Request: %s", action.toString().replaceAll("\n", ""));
+      }
       K response = (K) acc.get();
+
+      if (profiling.isProfilingEnabled(Profiling.Level.FULL)) {
+        if (ToXContent.class.isAssignableFrom(response.getClass())) {
+          XContentBuilder debugResponse = XContentFactory.jsonBuilder();
+          debugResponse.startObject();
+          ((ToXContent) response).toXContent(debugResponse, ToXContent.EMPTY_PARAMS);
+          debugResponse.endObject();
+          fullProfile.stop("ES Response: %s", debugResponse.string());
+        } else {
+          fullProfile.stop("ES Response: %s", response.toString());
+        }
+      }
+
       return response;
     } catch (Exception e) {
       throw new IllegalStateException("ES error: ", e);
-    } finally {
-      if (requestProfile != null) {
-        requestProfile.stop("Requested: ", action);
-      }
     }
   }
 }
index 20ec65982c5608993a2d0ceedb2a3a384a32c6c1..68cf9e84f578de1816d307421697a1e48d7d3932 100644 (file)
@@ -71,7 +71,7 @@ public class Profiling {
     return watch;
   }
 
-  private boolean isProfilingEnabled(Level level) {
+  public boolean isProfilingEnabled(Level level) {
     String settingsValue = settings.getString(CONFIG_PROFILING_LEVEL);
     Level settingsLevel = Level.fromConfigString(settingsValue);
     return settingsLevel != Level.NONE && level.ordinal() <= settingsLevel.ordinal();