From a0f98ae3e9266e83aa10a0e8bc0b8fb44eed1a2c Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Mon, 4 Aug 2014 12:14:33 +0200 Subject: [PATCH] Improve Profiling output for *Index Classes --- .../java/org/sonar/server/search/ESNode.java | 27 +++++++++++++++---- .../org/sonar/core/profiling/Profiling.java | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/ESNode.java b/server/sonar-server/src/main/java/org/sonar/server/search/ESNode.java index a6e28704afa..3e8d0dfdcdb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/ESNode.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/ESNode.java @@ -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 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); - } } } } diff --git a/sonar-core/src/main/java/org/sonar/core/profiling/Profiling.java b/sonar-core/src/main/java/org/sonar/core/profiling/Profiling.java index 20ec65982c5..68cf9e84f57 100644 --- a/sonar-core/src/main/java/org/sonar/core/profiling/Profiling.java +++ b/sonar-core/src/main/java/org/sonar/core/profiling/Profiling.java @@ -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(); -- 2.39.5