This is an automated email from the ASF dual-hosted git repository.

dpavlov pushed a commit to branch performance
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git


The following commit(s) were added to refs/heads/performance by this push:
     new baf2cde  Profiling data exposed as service
baf2cde is described below

commit baf2cdea4598849580e26520de300523d4d78643
Author: Dmitriy Pavlov <dpav...@apache.org>
AuthorDate: Fri Sep 14 20:41:42 2018 +0300

    Profiling data exposed as service
---
 .../org/apache/ignite/ci/di/IgniteTcBotModule.java |  6 ++-
 .../apache/ignite/ci/di/ProfilingInterceptor.java  |  5 ++
 .../java/org/apache/ignite/ci/util/TimeUtil.java   |  9 ++++
 .../java/org/apache/ignite/ci/web/CtxListener.java |  4 ++
 .../ignite/ci/web/rest/monitoring/HotSpot.java     | 42 +++++++++++++++
 .../ci/web/rest/monitoring/MonitoringService.java  | 60 ++++++++++++++++++++++
 6 files changed, 125 insertions(+), 1 deletion(-)

diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/IgniteTcBotModule.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/IgniteTcBotModule.java
index 88dcd36..07ae721 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/IgniteTcBotModule.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/IgniteTcBotModule.java
@@ -32,9 +32,13 @@ public class IgniteTcBotModule extends AbstractModule {
     private Ignite ignite;
 
     protected void configure() {
+        ProfilingInterceptor profilingInterceptor = new ProfilingInterceptor();
+
         bindInterceptor(Matchers.any(),
                 Matchers.annotatedWith(AutoProfiling.class),
-                new ProfilingInterceptor());
+                profilingInterceptor);
+
+        bind(ProfilingInterceptor.class).toInstance(profilingInterceptor);
 
         bind(Ignite.class).toProvider(new Provider<Ignite>() {
             @Override
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/ProfilingInterceptor.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/ProfilingInterceptor.java
index da5d5ad..508670d 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/ProfilingInterceptor.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/ProfilingInterceptor.java
@@ -21,6 +21,7 @@ import org.aopalliance.intercept.MethodInterceptor;
 import org.aopalliance.intercept.MethodInvocation;
 
 import java.time.Duration;
+import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
@@ -49,4 +50,8 @@ public class ProfilingInterceptor implements 
MethodInterceptor {
             System.out.println(fullKey + ": " + duration + " ");
         }
     }
+
+    public Map<String, AtomicLong> getMap() {
+        return Collections.unmodifiableMap(totalTime);
+    }
 }
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/TimeUtil.java 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/TimeUtil.java
index 0aa0b63..6c605de 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/TimeUtil.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/TimeUtil.java
@@ -49,4 +49,13 @@ public class TimeUtil {
             .replaceAll("(\\d[HMS])(?!$)", "$1 ")
             .toLowerCase();
     }
+
+    public static String getDurationPrintableNanos(long ns) {
+        String durationStr = Duration.ofNanos(ns).toString();
+
+        if (durationStr.length() > 2)
+            return humanReadableFormat(durationStr);
+
+        return durationStr;
+    }
 }
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
index f7f92e4..5073f37 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
@@ -51,6 +51,10 @@ public class CtxListener implements ServletContextListener {
         return (ITcHelper)ctx.getAttribute(TC_HELPER);
     }
 
+    public static Injector getInjector(ServletContext ctx) {
+        return (Injector)ctx.getAttribute(INJECTOR);
+    }
+
     public static BackgroundUpdater getBackgroundUpdater(ServletContext ctx) {
         return (BackgroundUpdater)ctx.getAttribute(UPDATER);
     }
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/HotSpot.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/HotSpot.java
new file mode 100644
index 0000000..78f14a6
--- /dev/null
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/HotSpot.java
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.apache.ignite.ci.web.rest.monitoring;
+
+import org.apache.ignite.ci.util.TimeUtil;
+
+public class HotSpot {
+    public String method;
+    public String duration;
+
+    private long ns;
+
+    public long getNanos() {
+        return ns;
+    }
+
+    @Override
+    public String toString() {
+        return "HotSpot{" +
+                "method='" + method + '\'' +
+                ", duration='" +  TimeUtil.getDurationPrintableNanos(ns) + "'" 
+
+                '}';
+    }
+
+    public void setNanos(long l) {
+        ns = l;
+    }
+}
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/MonitoringService.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/MonitoringService.java
new file mode 100644
index 0000000..2f94f5d
--- /dev/null
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/MonitoringService.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+package org.apache.ignite.ci.web.rest.monitoring;
+
+import org.apache.ignite.ci.di.ProfilingInterceptor;
+import org.apache.ignite.ci.web.CtxListener;
+
+import javax.annotation.security.PermitAll;
+import javax.servlet.ServletContext;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+@Path("monitoring")
+@Produces(MediaType.APPLICATION_JSON)
+public class MonitoringService {
+    @Context
+    private ServletContext ctx;
+
+    @GET
+    @PermitAll
+    @Path("profiling")
+    public List<String> getHotMethods() {
+        ProfilingInterceptor instance = 
CtxListener.getInjector(ctx).getInstance(ProfilingInterceptor.class);
+        Map<String, AtomicLong> map = instance.getMap();
+
+        Stream<HotSpot> hotSpotStream = map.entrySet().stream().map(entry -> {
+            HotSpot hotSpot = new HotSpot();
+            hotSpot.setNanos(entry.getValue().get());
+            hotSpot.method = entry.getKey();
+            return hotSpot;
+        });
+
+        return 
hotSpotStream.sorted(Comparator.comparing(HotSpot::getNanos).reversed())
+                .limit(100)
+                .map(HotSpot::toString).collect(Collectors.toList());
+    }
+}

Reply via email to