camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1464589 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/management/mbean/ camel-core/src/main/java/org/apache/camel/util/ platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/
Date Thu, 04 Apr 2013 15:11:26 GMT
Author: davsclaus
Date: Thu Apr  4 15:11:25 2013
New Revision: 1464589

URL: http://svn.apache.org/r1464589
Log:
CAMEL-6237: Polished karaf commands

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/RouteStatDump.java
    camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java?rev=1464589&r1=1464588&r2=1464589&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
Thu Apr  4 15:11:25 2013
@@ -19,7 +19,9 @@ package org.apache.camel.management.mbea
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import javax.management.MBeanServer;
@@ -219,12 +221,13 @@ public class ManagedRoute extends Manage
     }
 
     public String dumpRouteStatsAsXml(boolean fullStats, boolean includeProcessors) throws
Exception {
+        // in this logic we need to calculate the accumulated processing time for the processor
in the route
+        // and hence why the logic is a bit more complicated to do this, as we need to caculate
that from
+        // the bottom -> top of the route but this information is valuable for profiling
routes
         StringBuilder sb = new StringBuilder();
 
-        sb.append("<routeStat").append(String.format(" id=\"%s\"", route.getId()));
-        // use substring as we only want the attributes
-        String stat = dumpStatsAsXml(fullStats);
-        sb.append(" ").append(stat.substring(7, stat.length() - 2)).append(">\n");
+        // need to calculate this value first, as we need that value for the route stat
+        Long processorAccumulatedTime = 0L;
 
         // gather all the processors for this route, which requires JMX
         if (includeProcessors) {
@@ -237,25 +240,59 @@ public class ManagedRoute extends Manage
                 List<ManagedProcessorMBean> mps = new ArrayList<ManagedProcessorMBean>();
                 for (ObjectName on : names) {
                     ManagedProcessorMBean processor = MBeanServerInvocationHandler.newProxyInstance(server,
on, ManagedProcessorMBean.class, true);
-                    mps.add(processor);
+
+                    // the processor must belong to this route
+                    if (getRouteId().equals(processor.getRouteId())) {
+                        mps.add(processor);
+                    }
                 }
                 Collections.sort(mps, new OrderProcessorMBeans());
 
+                // walk the processors in reverse order, and calculate the accumulated total
time
+                Map<String, Long> accumulatedTimes = new HashMap<String, Long>();
+                Collections.reverse(mps);
+                for (ManagedProcessorMBean processor : mps) {
+                    processorAccumulatedTime += processor.getTotalProcessingTime();
+                    accumulatedTimes.put(processor.getProcessorId(), processorAccumulatedTime);
+                }
+                // and reverse back again
+                Collections.reverse(mps);
+
                 // and now add the sorted list of processors to the xml output
                 for (ManagedProcessorMBean processor : mps) {
-                    // the processor must belong to this route
-                    if (getRouteId().equals(processor.getRouteId())) {
-                        sb.append("    <processorStat").append(String.format(" id=\"%s\"
index=\"%s\"", processor.getProcessorId(), processor.getIndex()));
-                        // use substring as we only want the attributes
-                        sb.append(" ").append(processor.dumpStatsAsXml(fullStats).substring(7)).append("\n");
+                    sb.append("    <processorStat").append(String.format(" id=\"%s\" index=\"%s\"",
processor.getProcessorId(), processor.getIndex()));
+                    // do we have an accumulated time then append that
+                    Long accTime = accumulatedTimes.get(processor.getProcessorId());
+                    if (accTime != null) {
+                        sb.append(" accumulatedProcessingTime=\"").append(accTime).append("\"");
                     }
+                    // use substring as we only want the attributes
+                    sb.append(" ").append(processor.dumpStatsAsXml(fullStats).substring(7)).append("\n");
                 }
             }
             sb.append("  </processorStats>\n");
         }
 
-        sb.append("</routeStat>");
-        return sb.toString();
+        // route self time is route total - processor accumulated total)
+        long routeSelfTime = getTotalProcessingTime() - processorAccumulatedTime;
+        if (routeSelfTime < 0) {
+            // ensure we don't calculate that as negative
+            routeSelfTime = 0;
+        }
+
+        StringBuilder answer = new StringBuilder();
+        answer.append("<routeStat").append(String.format(" id=\"%s\"", route.getId()));
+        // use substring as we only want the attributes
+        String stat = dumpStatsAsXml(fullStats);
+        answer.append(" selfProcessingTime=\"").append(routeSelfTime).append("\"");
+        answer.append(" ").append(stat.substring(7, stat.length() - 2)).append(">\n");
+
+        if (includeProcessors) {
+            answer.append(sb);
+        }
+
+        answer.append("</routeStat>");
+        return answer.toString();
     }
 
     @Override

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java?rev=1464589&r1=1464588&r2=1464589&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java Thu
Apr  4 15:11:25 2013
@@ -65,6 +65,9 @@ public final class ProcessorStatDump {
     private Long meanProcessingTime;
 
     @XmlAttribute
+    private Long accumulatedProcessingTime;
+
+    @XmlAttribute
     private String resetTimestamp;
 
     @XmlAttribute
@@ -187,6 +190,14 @@ public final class ProcessorStatDump {
         this.meanProcessingTime = meanProcessingTime;
     }
 
+    public Long getAccumulatedProcessingTime() {
+        return accumulatedProcessingTime;
+    }
+
+    public void setAccumulatedProcessingTime(Long accumulatedProcessingTime) {
+        this.accumulatedProcessingTime = accumulatedProcessingTime;
+    }
+
     public String getResetTimestamp() {
         return resetTimestamp;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/RouteStatDump.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/RouteStatDump.java?rev=1464589&r1=1464588&r2=1464589&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/RouteStatDump.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/RouteStatDump.java Thu Apr
 4 15:11:25 2013
@@ -66,6 +66,9 @@ public final class RouteStatDump {
     private Long meanProcessingTime;
 
     @XmlAttribute
+    private Long selfProcessingTime;
+
+    @XmlAttribute
     private String resetTimestamp;
 
     @XmlAttribute
@@ -186,6 +189,14 @@ public final class RouteStatDump {
         this.meanProcessingTime = meanProcessingTime;
     }
 
+    public Long getSelfProcessingTime() {
+        return selfProcessingTime;
+    }
+
+    public void setSelfProcessingTime(Long selfProcessingTime) {
+        this.selfProcessingTime = selfProcessingTime;
+    }
+
     public String getResetTimestamp() {
         return resetTimestamp;
     }
@@ -267,5 +278,3 @@ public final class RouteStatDump {
     }
 
 }
-
-

Modified: camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java?rev=1464589&r1=1464588&r2=1464589&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
(original)
+++ camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
Thu Apr  4 15:11:25 2013
@@ -39,8 +39,8 @@ import org.apache.karaf.util.StringEscap
 @Command(scope = "camel", name = "route-profile", description = "Display profile information
about Camel route(s).")
 public class RouteProfile extends AbstractRouteCommand {
 
-    protected static final String HEADER_FORMAT = "%-30s %10s %12s %12s %12s %12s %12s %12s";
-    protected static final String OUTPUT_FORMAT = "[%-28s] [%8d] [%10d] [%10d] [%10d] [%10d]
[%10d] [%10s]";
+    protected static final String HEADER_FORMAT = "%-30s %10s %12s %12s %12s %12s %12s %12s
%12s";
+    protected static final String OUTPUT_FORMAT = "[%-28s] [%8d] [%10d] [%10d] [%10d] [%10d]
[%10d] [%10d] [%10d]";
 
     private String previousCamelContextName;
 
@@ -60,7 +60,7 @@ public class RouteProfile extends Abstra
             System.out.println("");
             System.out.println(StringEscapeUtils.unescapeJava("\u001B[1mProfile\u001B[0m"));
             System.out.println(StringEscapeUtils.unescapeJava("\tCamel Context: " + camelRoute.getRouteContext().getCamelContext().getName()));
-            System.out.println(String.format(HEADER_FORMAT, "Id", "Count", "Last (ms)", "Delta
(ms)", "Mean (ms)", "Min (ms)", "Max (ms)", "Self (ms)"));
+            System.out.println(String.format(HEADER_FORMAT, "Id", "Count", "Last (ms)", "Delta
(ms)", "Mean (ms)", "Min (ms)", "Max (ms)", "Total (ms)", "Self (ms)"));
         }
 //        System.out.println(StringEscapeUtils.unescapeJava("\u001B[1m\u001B[33mCamel Route
" + camelRoute.getId() + "\u001B[0m"));
 //        System.out.println(StringEscapeUtils.unescapeJava("\tEndpoint uri: " + URISupport.sanitizeUri(camelRoute.getEndpoint().getEndpointUri())));
@@ -74,22 +74,20 @@ public class RouteProfile extends Abstra
                 String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
                 if (camelId != null && camelId.equals(camelContext.getName())) {
 
-                    // TODO: add column with total time (delta for self time)
-
                     String xml = (String) mBeanServer.invoke(routeMBean, "dumpRouteStatsAsXml",
new Object[]{Boolean.FALSE, Boolean.TRUE}, new String[]{"boolean", "boolean"});
                     RouteStatDump route = (RouteStatDump) unmarshaller.unmarshal(new StringReader(xml));
 
                     long count = route.getExchangesCompleted() + route.getExchangesFailed();
                     System.out.println(String.format(OUTPUT_FORMAT, route.getId(), count,
route.getLastProcessingTime(), route.getDeltaProcessingTime(),
-                            route.getMeanProcessingTime(), route.getMinProcessingTime(),
route.getMaxProcessingTime(), ""));
+                            route.getMeanProcessingTime(), route.getMinProcessingTime(),
route.getMaxProcessingTime(), route.getTotalProcessingTime(), route.getSelfProcessingTime()));
 
                     for (ProcessorStatDump ps : route.getProcessorStats()) {
                         // the self time is the total time of the processor itself
-                        String selfTime = "" + ps.getTotalProcessingTime();
+                        long selfTime = ps.getTotalProcessingTime();
                         count = ps.getExchangesCompleted() + ps.getExchangesFailed();
                         // indent route id with 2 spaces
-                        System.out.println(String.format(OUTPUT_FORMAT, "  " + ps.getId(),
count, ps.getLastProcessingTime(),
-                                ps.getDeltaProcessingTime(), ps.getMeanProcessingTime(),
ps.getMinProcessingTime(), ps.getMaxProcessingTime(), selfTime));
+                        System.out.println(String.format(OUTPUT_FORMAT, "  " + ps.getId(),
count, ps.getLastProcessingTime(), ps.getDeltaProcessingTime(),
+                                ps.getMeanProcessingTime(), ps.getMinProcessingTime(), ps.getMaxProcessingTime(),
ps.getAccumulatedProcessingTime(), selfTime));
                     }
                 }
             }



Mime
View raw message