Search in sources :

Example 1 with ProcessorStatDump

use of org.apache.camel.util.ProcessorStatDump in project camel by apache.

the class RouteProfileCommand method executeOnRoute.

@Override
public void executeOnRoute(CamelController camelController, String contextName, String routeId, PrintStream out, PrintStream err) throws Exception {
    JAXBContext context = JAXBContext.newInstance(RouteStatDump.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    // write new header for new camel context
    if (previousCamelContextName == null || !previousCamelContextName.equals(contextName)) {
        out.println("");
        out.println(stringEscape.unescapeJava("Profile"));
        out.println(stringEscape.unescapeJava("\tCamel Context: " + contextName));
        out.println(String.format(HEADER_FORMAT, "Id", "Count", "Last (ms)", "Delta (ms)", "Mean (ms)", "Min (ms)", "Max (ms)", "Total (ms)", "Self (ms)"));
    }
    String xml = camelController.getRouteStatsAsXml(routeId, contextName, true, true);
    if (xml != null) {
        RouteStatDump route = (RouteStatDump) unmarshaller.unmarshal(new StringReader(xml));
        long count = route.getExchangesCompleted() + route.getExchangesFailed();
        out.println(String.format(OUTPUT_FORMAT, route.getId(), count, route.getLastProcessingTime(), route.getDeltaProcessingTime(), 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
            long selfTime = ps.getTotalProcessingTime();
            count = ps.getExchangesCompleted() + ps.getExchangesFailed();
            // indent route id with 2 spaces
            out.println(String.format(OUTPUT_FORMAT, "  " + ps.getId(), count, ps.getLastProcessingTime(), ps.getDeltaProcessingTime(), ps.getMeanProcessingTime(), ps.getMinProcessingTime(), ps.getMaxProcessingTime(), ps.getAccumulatedProcessingTime(), selfTime));
        }
    }
    // we want to group routes from the same context in the same table
    previousCamelContextName = contextName;
}
Also used : ProcessorStatDump(org.apache.camel.util.ProcessorStatDump) RouteStatDump(org.apache.camel.util.RouteStatDump) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

StringReader (java.io.StringReader)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ProcessorStatDump (org.apache.camel.util.ProcessorStatDump)1 RouteStatDump (org.apache.camel.util.RouteStatDump)1