[jboss-cvs] jboss-profiler/java/src/expansion/org/jboss/profiler/exp/view/servlet ...

Takuro Okada t2-okada at nri.co.jp
Thu Oct 26 04:58:56 EDT 2006


  User: tokada  
  Date: 06/10/26 04:58:56

  Added:       java/src/expansion/org/jboss/profiler/exp/view/servlet      
                        Tag: JBossProfiler_Expansion ExecutionStack.java
                        ExecutionMetrics.java ExecutionPassage.java
                        ExecutionPassageDetail.java ConcurrencyMetrics.java
                        MemoryMetrics.java
  Log:
  
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +132 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/exp/view/servlet/Attic/ExecutionStack.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExecutionStack.java
  ===================================================================
  RCS file: ExecutionStack.java
  diff -N ExecutionStack.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ExecutionStack.java	26 Oct 2006 08:58:56 -0000	1.1.2.1
  @@ -0,0 +1,132 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + * Copyright 2006, JBoss Inc., and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
  +
  +package org.jboss.profiler.exp.view.servlet;
  +
  +import java.io.IOException;
  +import java.util.EnumMap;
  +import java.util.List;
  +import java.util.Map;
  +
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServlet;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +
  +import javolution.xml.stream.XMLOutputFactory;
  +import javolution.xml.stream.XMLStreamException;
  +import javolution.xml.stream.XMLStreamWriter;
  +
  +import org.apache.log4j.Logger;
  +import org.jboss.profiler.exp.adaptor.ServiceManager;
  +import org.jboss.profiler.exp.agent.collector.model.MetricName;
  +import org.jboss.profiler.exp.agent.collector.model.StackMetric;
  +import org.jboss.profiler.exp.util.HierarchicalMap;
  +
  +/**
  + * The servlet class for writing data for execution stack.
  + * 
  + * output exsample:
  + * <executionStack>
  + *   <recordSet category="AOP Interceptor">
  + *     <record id="0-0" name="methodname" depth="0" type="p"/>
  + *     ...
  + *   </recordSet>
  + * </executionStack>
  + * 
  + * @author Takuro Okada (Nomura Research Institute, Ltd.)
  + * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
  + * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
  + * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
  + */
  +public class ExecutionStack extends HttpServlet {
  +    
  +    private final String XML_ROOT = "executionStack";
  +    private final String XML_RECORD_SET = "recordSet";
  +    private final String XML_RECORD = "record";
  +    
  +    private final String DEFAULT_SERVICE_NAME = "jboss.profiler:service=ProfilerService";
  +    
  +    private static Logger logger = Logger.getLogger(ExecutionStack.class);
  +    
  +    @SuppressWarnings("unchecked")
  +    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  +        
  +        String profilerServiceName = this.getServletContext().getInitParameter("ProfilerServiceName");
  +        if(profilerServiceName==null) profilerServiceName = DEFAULT_SERVICE_NAME;
  +        
  +        // invoke agent to get snapshot of metrics
  +        Object obj = ServiceManager.invokeLocal(profilerServiceName, "snapMetrics");
  +        if(obj==null) {
  +            logger.error("failed to snap the metrics data.");
  +        }
  +        Map metricsMap = (Map)obj;
  +        
  +        // write xml
  +        response.setContentType("text/plain; charset=UTF-8");
  +        XMLOutputFactory factory = XMLOutputFactory.newInstance();
  +        factory.setProperty(XMLOutputFactory.INDENTATION, "  ");
  +        XMLStreamWriter writer = null;
  +        try {
  +            writer = factory.createXMLStreamWriter(response.getWriter());
  +            writer.writeStartDocument();
  +            writer.writeStartElement(XML_ROOT);
  +            
  +            for(Object category : metricsMap.keySet()) {
  +                HierarchicalMap operationMap = (HierarchicalMap)metricsMap.get(category);
  +                for(Object operationName : operationMap.keySet()) {
  +                    EnumMap mmap = (EnumMap)operationMap.get(operationName);
  +                    StackMetric metric = (StackMetric)mmap.get(MetricName.STACK_TRACE);
  +                    if(metric==null) continue;
  +                    writer.writeStartElement(XML_RECORD_SET);
  +                    writer.writeAttribute("category", String.valueOf(category));
  +                    writer.writeAttribute("operationName", String.valueOf(operationName));
  +                    List<String[]> stacks = metric.getStacks();
  +                    for(int i=0; i<stacks.size(); i++) {
  +                        String[] stack = stacks.get(i);
  +                        for(int j=0; j<stack.length; j++) {
  +                            writer.writeEmptyElement(XML_RECORD);
  +                            writer.writeAttribute("id", String.valueOf(i)+"-"+String.valueOf(j));
  +                            writer.writeAttribute("name", stack[j]);
  +                            writer.writeAttribute("depth", String.valueOf(j));
  +                            writer.writeAttribute("type", "p");
  +                        }
  +                    }
  +                    writer.writeEndElement();
  +                }
  +            }
  +            writer.writeEndElement();
  +            writer.writeEndDocument();
  +        } catch (XMLStreamException e) {
  +            logger.error("failed to write xml.");
  +        } finally {
  +            if(writer!=null) {
  +                try {
  +                    writer.close();
  +                } catch (XMLStreamException e) {
  +                    logger.error("failed to write xml.");
  +                }
  +            }
  +        }
  +    }
  +    
  +}
  
  
  
  1.1.2.1   +176 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/exp/view/servlet/Attic/ExecutionMetrics.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExecutionMetrics.java
  ===================================================================
  RCS file: ExecutionMetrics.java
  diff -N ExecutionMetrics.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ExecutionMetrics.java	26 Oct 2006 08:58:56 -0000	1.1.2.1
  @@ -0,0 +1,176 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + * Copyright 2006, JBoss Inc., and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
  +
  +package org.jboss.profiler.exp.view.servlet;
  +
  +import java.io.IOException;
  +import java.util.EnumMap;
  +import java.util.Map;
  +import java.util.SortedMap;
  +import java.util.TreeMap;
  +
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServlet;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +
  +import javolution.xml.stream.XMLOutputFactory;
  +import javolution.xml.stream.XMLStreamException;
  +import javolution.xml.stream.XMLStreamWriter;
  +
  +import org.apache.log4j.Logger;
  +import org.jboss.profiler.exp.adaptor.ServiceManager;
  +import org.jboss.profiler.exp.agent.collector.model.MetricName;
  +import org.jboss.profiler.exp.agent.collector.model.ScaleMetric;
  +import org.jboss.profiler.exp.util.HierarchicalMap;
  +import org.jboss.profiler.exp.view.util.Signature;
  +
  +/**
  + * The servlet class for writing data for execution statictics.
  + * 
  + * output exsample:
  + * <executionMetrics>
  + *   <recordSet category="AOP Interceptor">
  + *     <record name="packagename"
  + *             type="p"
  + *             invocationCount="3"
  + *             maxTime="90129600"
  + *             minTime="0"
  + *             averageTime="3940851"/>
  + *     ...
  + *   </recordSet>
  + * </executionMetrics>
  + * 
  + * @author Takuro Okada (Nomura Research Institute, Ltd.)
  + * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
  + * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
  + * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
  + */
  +public class ExecutionMetrics extends HttpServlet {
  +    
  +    private final String XML_ROOT = "executionMetrics";
  +    private final String XML_RECORD_SET = "recordSet";
  +    private final String XML_RECORD = "record";
  +    
  +    private final String DEFAULT_SERVICE_NAME = "jboss.profiler:service=ProfilerService";
  +    
  +    private static Logger logger = Logger.getLogger(ExecutionMetrics.class);
  +    
  +    @SuppressWarnings("unchecked")
  +    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  +        
  +        String profilerServiceName = this.getServletContext().getInitParameter("ProfilerServiceName");
  +        if(profilerServiceName==null) profilerServiceName = DEFAULT_SERVICE_NAME;
  +        
  +        MetricName metricName = MetricName.USER_CPU_TIME;
  +        String metricNameInput = request.getParameter("org.jboss.profiler.exp.view.setting.MetricName");
  +        if(metricNameInput!=null) {
  +            if(metricNameInput.equals("cpuTime")) metricName = MetricName.CPU_TIME;
  +        }
  +        
  +        // invoke agent to get snapshot of metrics
  +        Object obj = ServiceManager.invokeLocal(profilerServiceName, "snapMetrics");
  +        if(obj==null) {
  +            logger.error("failed to snap the metrics data.");
  +        }
  +        Map metricsMap = (Map)obj;
  +        
  +        // get metrics keys
  +        Map<String, Signature> categoryMap = new TreeMap<String, Signature>();
  +        for(Object set : metricsMap.entrySet()) {
  +            Map.Entry categorySet = (Map.Entry)set;
  +            String category = (String)categorySet.getKey();
  +            Map omap = (Map)categorySet.getValue();
  +            Signature signature = new Signature();
  +            for(Object operationName : omap.keySet()) {
  +                signature.add(String.valueOf(operationName));
  +            }
  +            categoryMap.put(category, signature);
  +        }
  +        
  +        // write xml
  +        response.setContentType("text/plain; charset=UTF-8");
  +        XMLOutputFactory factory = XMLOutputFactory.newInstance();
  +        factory.setProperty(XMLOutputFactory.INDENTATION, "  ");
  +        XMLStreamWriter writer = null;
  +        try {
  +            writer = factory.createXMLStreamWriter(response.getWriter());
  +            writer.writeStartDocument();
  +            writer.writeStartElement(XML_ROOT);
  +            
  +            for(Map.Entry<String, Signature> categorySet : categoryMap.entrySet()) {
  +                writer.writeStartElement(XML_RECORD_SET);
  +                writer.writeAttribute("category", categorySet.getKey());
  +                
  +                HierarchicalMap operationMap = (HierarchicalMap)metricsMap.get(categorySet.getKey());
  +                for(Map.Entry<String, Signature.Type> signatures : categorySet.getValue()) {
  +                    String name = signatures.getKey();
  +                    SortedMap particalMap = operationMap.partialMap(name);
  +                    
  +                    long invocationCount = 0;
  +                    long maxTime = 0;
  +                    long minTime = 0;
  +                    long averageTime = 0;
  +                    int count = 0;
  +                    for(Object value : particalMap.values()) {
  +                        EnumMap mmap = (EnumMap)value;
  +                        ScaleMetric metric = (ScaleMetric)mmap.get(metricName);
  +                        if(metric==null) continue;
  +                        
  +                        if(metricName.equals(MetricName.USER_CPU_TIME)) {
  +                            invocationCount += metric.getCount();
  +                            if(metric.getHigh() > maxTime) maxTime = metric.getHigh();
  +                            if(metric.getLow() < minTime) minTime = metric.getLow();
  +                            averageTime += metric.getAverage();
  +                            count++;
  +                        }
  +                    }
  +                    if(count==0) continue;
  +                    
  +                    averageTime = averageTime / count;
  +                    writer.writeEmptyElement(XML_RECORD);
  +                    writer.writeAttribute("name", name);
  +                    writer.writeAttribute("depth", String.valueOf(Signature.countDepth(name)));
  +                    writer.writeAttribute("type", signatures.getValue().toString());
  +                    writer.writeAttribute("invocationCount", String.valueOf(invocationCount));
  +                    writer.writeAttribute("maxTime", String.valueOf(maxTime));
  +                    writer.writeAttribute("minTime", String.valueOf(minTime));
  +                    writer.writeAttribute("averageTime", String.valueOf(averageTime));
  +                }
  +                writer.writeEndElement();
  +            }
  +            writer.writeEndElement();
  +            writer.writeEndDocument();
  +        } catch (XMLStreamException e) {
  +            logger.error("failed to write xml.");
  +        } finally {
  +            if(writer!=null) {
  +                try {
  +                    writer.close();
  +                } catch (XMLStreamException e) {
  +                    logger.error("failed to write xml.");
  +                }
  +            }
  +        }
  +    }
  +    
  +}
  
  
  
  1.1.2.1   +131 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/exp/view/servlet/Attic/ExecutionPassage.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExecutionPassage.java
  ===================================================================
  RCS file: ExecutionPassage.java
  diff -N ExecutionPassage.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ExecutionPassage.java	26 Oct 2006 08:58:56 -0000	1.1.2.1
  @@ -0,0 +1,131 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + * Copyright 2006, JBoss Inc., and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
  +
  +package org.jboss.profiler.exp.view.servlet;
  +
  +import java.io.IOException;
  +import java.util.EnumMap;
  +import java.util.Map;
  +
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServlet;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +
  +import javolution.xml.stream.XMLOutputFactory;
  +import javolution.xml.stream.XMLStreamException;
  +import javolution.xml.stream.XMLStreamWriter;
  +
  +import org.apache.log4j.Logger;
  +import org.jboss.profiler.exp.adaptor.ServiceManager;
  +import org.jboss.profiler.exp.agent.collector.model.MetricName;
  +import org.jboss.profiler.exp.agent.collector.model.TimeScaleMetric;
  +import org.jboss.profiler.exp.util.HierarchicalMap;
  +
  +/**
  + * The servlet class for writing data for execution passage.
  + * 
  + * output exsample:
  + * <executionPassage>
  + *   <recordSet category="AOP Interceptor" operationName="methodname" metricName="Elapsed Time">
  + *     <record timestamp="1160488403555" value="10014400"/>
  + *     ...
  + *   </recordSet>
  + * </executionPassage>
  + * 
  + * @author Takuro Okada (Nomura Research Institute, Ltd.)
  + * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
  + * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
  + * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
  + */
  +public class ExecutionPassage extends HttpServlet {
  +    
  +    private final String XML_ROOT = "executionPassage";
  +    private final String XML_RECORD_SET = "recordSet";
  +    private final String XML_RECORD = "record";
  +    
  +    private final String DEFAULT_SERVICE_NAME = "jboss.profiler:service=ProfilerService";
  +    
  +    private static Logger logger = Logger.getLogger(ExecutionPassage.class);
  +    
  +    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  +        
  +        String profilerServiceName = this.getServletContext().getInitParameter("ProfilerServiceName");
  +        if(profilerServiceName==null) profilerServiceName = DEFAULT_SERVICE_NAME;
  +        
  +        MetricName metricName = MetricName.USER_CPU_TIME_PASSAGE;
  +        String metricNameInput = request.getParameter("org.jboss.profiler.exp.view.setting.MetricName");
  +        if(metricNameInput!=null) {
  +            if(metricNameInput.equals("cpuTime")) metricName = MetricName.CPU_TIME_PASSAGE;
  +        }
  +        
  +        // invoke agent to get snapshot of metrics
  +        Object obj = ServiceManager.invokeLocal(profilerServiceName, "snapMetrics");
  +        if(obj==null) {
  +            logger.error("failed to snap the metrics data.");
  +        }
  +        Map metricsMap = (Map)obj;
  +        
  +        // write xml
  +        response.setContentType("text/plain; charset=UTF-8");
  +        XMLOutputFactory factory = XMLOutputFactory.newInstance();
  +        factory.setProperty(XMLOutputFactory.INDENTATION, "  ");
  +        XMLStreamWriter writer = null;
  +        try {
  +            writer = factory.createXMLStreamWriter(response.getWriter());
  +            writer.writeStartDocument();
  +            writer.writeStartElement(XML_ROOT);
  +            
  +            for(Object category : metricsMap.keySet()) {
  +                HierarchicalMap operationMap = (HierarchicalMap)metricsMap.get(category);
  +                for(Object operationName : operationMap.keySet()) {
  +                    EnumMap mmap = (EnumMap)operationMap.get(operationName);
  +                    TimeScaleMetric metric = (TimeScaleMetric)mmap.get(metricName);
  +                    if(metric==null) continue;
  +                    writer.writeStartElement(XML_RECORD_SET);
  +                    writer.writeAttribute("category", String.valueOf(category));
  +                    writer.writeAttribute("operationName", String.valueOf(operationName));
  +                    writer.writeAttribute("metricName", MetricName.USER_CPU_TIME_PASSAGE.toString());
  +                    for(TimeScaleMetric.Entry entry : metric.getEntries()) {
  +                        writer.writeEmptyElement(XML_RECORD);
  +                        writer.writeAttribute("timestamp", String.valueOf(entry.getTimestamp()));
  +                        writer.writeAttribute("value", String.valueOf(entry.getValue()));
  +                    }
  +                    writer.writeEndElement();
  +                }
  +            }
  +            writer.writeEndElement();
  +            writer.writeEndDocument();
  +        } catch (XMLStreamException e) {
  +            logger.error("failed to write xml.");
  +        } finally {
  +            if(writer!=null) {
  +                try {
  +                    writer.close();
  +                } catch (XMLStreamException e) {
  +                    logger.error("failed to write xml.");
  +                }
  +            }
  +        }
  +    }
  +    
  +}
  
  
  
  1.1.2.1   +167 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/exp/view/servlet/Attic/ExecutionPassageDetail.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExecutionPassageDetail.java
  ===================================================================
  RCS file: ExecutionPassageDetail.java
  diff -N ExecutionPassageDetail.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ExecutionPassageDetail.java	26 Oct 2006 08:58:56 -0000	1.1.2.1
  @@ -0,0 +1,167 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + * Copyright 2006, JBoss Inc., and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
  +
  +package org.jboss.profiler.exp.view.servlet;
  +
  +import java.io.IOException;
  +import java.util.EnumMap;
  +import java.util.Map;
  +
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServlet;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +
  +import javolution.xml.stream.XMLOutputFactory;
  +import javolution.xml.stream.XMLStreamException;
  +import javolution.xml.stream.XMLStreamWriter;
  +
  +import org.apache.log4j.Logger;
  +import org.jboss.profiler.exp.adaptor.ServiceManager;
  +import org.jboss.profiler.exp.agent.collector.model.MetricName;
  +import org.jboss.profiler.exp.agent.collector.model.ThreadMetric;
  +
  +/**
  + * The servlet class for writing data for execution passage.
  + * 
  + * output exsample:
  + * <executionPassage>
  + *   <recordSet category="Beans">
  + *     <record id="128"
  + *             name="org.jboss.profiler.exp.test.target.logic.SampleLogic.addEmployee"
  + *             timestamp="1160729227839" elapsedTime="800000000"
  + *             caller="SampleServlet"
  + *             args=""/>
  + *     ...
  + *   </recordSet>
  + * </executionPassage>
  + * 
  + * @author Takuro Okada (Nomura Research Institute, Ltd.)
  + * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
  + * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
  + * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
  + */
  +public class ExecutionPassageDetail extends HttpServlet {
  +    
  +    private final String XML_ROOT = "executionPassage";
  +    private final String XML_RECORD_SET = "recordSet";
  +    private final String XML_RECORD = "record";
  +    
  +    private final String DEFAULT_SERVICE_NAME = "jboss.profiler:service=ProfilerService";
  +    
  +    private final String DEFAULT_HR_CATEGORY = "Http Requests";
  +    private final String DEFAULT_BE_CATEGORY = "Beans";
  +    private final String DEFAULT_DA_CATEGORY = "Data Access";
  +    
  +    private static Logger logger = Logger.getLogger(ExecutionPassageDetail.class);
  +    
  +    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  +        
  +        String profilerServiceName = this.getServletContext().getInitParameter("ProfilerServiceName");
  +        if(profilerServiceName==null) profilerServiceName = DEFAULT_SERVICE_NAME;
  +        
  +        String httpRequestCategory = this.getServletContext().getInitParameter("HttpRequestCategory");
  +        if(httpRequestCategory==null) httpRequestCategory = DEFAULT_HR_CATEGORY;
  +        String beansCategory = this.getServletContext().getInitParameter("BeansCategory");
  +        if(beansCategory==null) beansCategory = DEFAULT_BE_CATEGORY;
  +        String dataAccessCategory = this.getServletContext().getInitParameter("DataAccessCategory");
  +        if(dataAccessCategory==null) dataAccessCategory = DEFAULT_DA_CATEGORY;
  +        
  +        MetricName metricName = MetricName.REAL_TIME_PASSAGE_DETAIL;
  +        String metricNameInput = request.getParameter("org.jboss.profiler.exp.view.setting.MetricName");
  +        if(metricNameInput!=null) {
  +            if(metricNameInput.equals("cpu")) metricName = MetricName.CPU_TIME_PASSAGE_DETAIL;
  +            if(metricNameInput.equals("userCpu")) metricName = MetricName.USER_CPU_TIME_PASSAGE_DETAIL;
  +        }
  +        
  +        String specifiedCategoriesInput = request.getParameter("org.jboss.profiler.exp.view.request.Categories");
  +        String[] specifiedCategories = null;
  +        if(specifiedCategoriesInput!=null) specifiedCategories = specifiedCategoriesInput.split(",");
  +        String specifiedThreadIdTemp = request.getParameter("org.jboss.profiler.exp.view.request.ThreadId");
  +        String specifiedThreadId = null;
  +        if(specifiedThreadIdTemp!=null) specifiedThreadId = specifiedThreadIdTemp;
  +        
  +        String specifiedCaller = request.getParameter("org.jboss.profiler.exp.view.request.Caller");
  +        
  +        // invoke agent to get snapshot of metrics
  +        Object obj = ServiceManager.invokeLocal(profilerServiceName, "snapMetrics");
  +        if(obj==null) {
  +            logger.error("failed to snap the metrics data.");
  +        }
  +        Map metricsMap = (Map)obj;
  +        
  +        // write xml
  +        response.setContentType("text/plain; charset=UTF-8");
  +        XMLOutputFactory factory = XMLOutputFactory.newInstance();
  +        factory.setProperty(XMLOutputFactory.INDENTATION, "  ");
  +        XMLStreamWriter writer = null;
  +        try {
  +            writer = factory.createXMLStreamWriter(response.getWriter());
  +            writer.writeStartDocument();
  +            writer.writeStartElement(XML_ROOT);
  +            writer.writeStartElement(XML_RECORD_SET);
  +            for(String category : specifiedCategories) {
  +                Map operationMap = (Map)metricsMap.get(category.trim());
  +                if(operationMap==null) continue;
  +                if(specifiedThreadId!=null) {
  +                    writeRecord(writer, operationMap, specifiedThreadId, metricName, specifiedCaller);
  +                }else {
  +                    for(Object threadId : operationMap.keySet()) {
  +                        writeRecord(writer, operationMap, threadId, metricName, specifiedCaller);
  +                    }
  +                }
  +            }
  +            writer.writeEndElement();
  +            writer.writeEndElement();
  +            writer.writeEndDocument();
  +        } catch (XMLStreamException e) {
  +            logger.error("failed to write xml.");
  +        } finally {
  +            if(writer!=null) {
  +                try {
  +                    writer.close();
  +                } catch (XMLStreamException e) {
  +                    logger.error("failed to write xml.");
  +                }
  +            }
  +        }
  +    }
  +    
  +    private void writeRecord(XMLStreamWriter writer, Map operationMap, Object threadId, MetricName metricName, String caller) throws XMLStreamException {
  +        EnumMap mmap = (EnumMap)operationMap.get(threadId);
  +        ThreadMetric metric = (ThreadMetric)mmap.get(metricName);
  +        if(metric==null) return;
  +        for(ThreadMetric.Entry entry : metric.getEntries()) {
  +            if(caller!=null && !String.valueOf(entry.getCaller()).equals(caller)) {
  +                continue;
  +            }
  +            writer.writeEmptyElement(XML_RECORD);
  +            writer.writeAttribute("id", String.valueOf(threadId));
  +            writer.writeAttribute("name", entry.getMethodName());
  +            writer.writeAttribute("timestamp", String.valueOf(entry.getTimestamp()));
  +            writer.writeAttribute("value", String.valueOf(entry.getValue()));
  +            writer.writeAttribute("caller", String.valueOf(entry.getCaller()));
  +            writer.writeAttribute("args", String.valueOf(entry.getAddition()));
  +        }
  +    }
  +    
  +}
  
  
  
  1.1.2.1   +219 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/exp/view/servlet/Attic/ConcurrencyMetrics.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConcurrencyMetrics.java
  ===================================================================
  RCS file: ConcurrencyMetrics.java
  diff -N ConcurrencyMetrics.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ConcurrencyMetrics.java	26 Oct 2006 08:58:56 -0000	1.1.2.1
  @@ -0,0 +1,219 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + * Copyright 2006, JBoss Inc., and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
  +
  +package org.jboss.profiler.exp.view.servlet;
  +
  +import java.io.IOException;
  +import java.util.EnumMap;
  +import java.util.Map;
  +import java.util.SortedMap;
  +import java.util.TreeMap;
  +
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServlet;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +
  +import javolution.xml.stream.XMLOutputFactory;
  +import javolution.xml.stream.XMLStreamException;
  +import javolution.xml.stream.XMLStreamWriter;
  +
  +import org.apache.log4j.Logger;
  +import org.jboss.profiler.exp.adaptor.ServiceManager;
  +import org.jboss.profiler.exp.agent.collector.model.MetricName;
  +import org.jboss.profiler.exp.agent.collector.model.ScaleMetric;
  +import org.jboss.profiler.exp.util.HierarchicalMap;
  +import org.jboss.profiler.exp.view.util.Signature;
  +
  +/**
  + * The servlet class for writing data for concurrency statictics.
  + * 
  + * output exsample:
  + * <concurrencyMetrics>
  + *   <recordSet category="AOP Interceptor">
  + *     <record name="packagename"
  + *             type="p"
  + *             bcMax="3"
  + *             bcMin="0"
  + *             bcAvg="1"
  + *             btMax="3940851"
  + *             btMin="0"
  + *             btAvg="2200653"
  + *             wcMax="3"
  + *             wcMin="0"
  + *             wcAvg="1"
  + *             wtMax="3940851"
  + *             wtMin="0"
  + *             wtAvg="2200653"/>
  + *     ...
  + *   </recordSet>
  + * </concurrencyMetrics>
  + * 
  + * @author Takuro Okada (Nomura Research Institute, Ltd.)
  + * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
  + * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
  + * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
  + */
  +public class ConcurrencyMetrics extends HttpServlet {
  +    
  +    private final String XML_ROOT = "concurrencyMetrics";
  +    private final String XML_RECORD_SET = "recordSet";
  +    private final String XML_RECORD = "record";
  +    
  +    private final String DEFAULT_SERVICE_NAME = "jboss.profiler:service=ProfilerService";
  +    
  +    private final static MetricName[] targetMetricNames = new MetricName[] 
  +                              {MetricName.BLOCK_COUNT, MetricName.BLOCK_TIME, MetricName.WAIT_COUNT, MetricName.WAIT_TIME};
  +    
  +    private static Logger logger = Logger.getLogger(ConcurrencyMetrics.class);
  +    
  +    @SuppressWarnings("unchecked")
  +    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  +        
  +        String profilerServiceName = this.getServletContext().getInitParameter("ProfilerServiceName");
  +        if(profilerServiceName==null) profilerServiceName = DEFAULT_SERVICE_NAME;
  +        
  +        // invoke agent to get snapshot of metrics
  +        Object obj = ServiceManager.invokeLocal(profilerServiceName, "snapMetrics");
  +        if(obj==null) {
  +            logger.error("failed to snap the metrics data.");
  +        }
  +        Map metricsMap = (Map)obj;
  +        
  +        // get metrics keys
  +        Map<String, Signature> categoryMap = new TreeMap<String, Signature>();
  +        for(Object set : metricsMap.entrySet()) {
  +            Map.Entry categorySet = (Map.Entry)set;
  +            String category = (String)categorySet.getKey();
  +            Map omap = (Map)categorySet.getValue();
  +            Signature signature = new Signature();
  +            for(Object operationName : omap.keySet()) {
  +                signature.add(String.valueOf(operationName));
  +            }
  +            categoryMap.put(category, signature);
  +        }
  +        
  +        // write xml
  +        response.setContentType("text/plain; charset=UTF-8");
  +        XMLOutputFactory factory = XMLOutputFactory.newInstance();
  +        factory.setProperty(XMLOutputFactory.INDENTATION, "  ");
  +        XMLStreamWriter writer = null;
  +        try {
  +            writer = factory.createXMLStreamWriter(response.getWriter());
  +            writer.writeStartDocument();
  +            writer.writeStartElement(XML_ROOT);
  +            
  +            for(Map.Entry<String, Signature> categorySet : categoryMap.entrySet()) {
  +                writer.writeStartElement(XML_RECORD_SET);
  +                writer.writeAttribute("category", categorySet.getKey());
  +                
  +                HierarchicalMap operationMap = (HierarchicalMap)metricsMap.get(categorySet.getKey());
  +                for(Map.Entry<String, Signature.Type> signatures : categorySet.getValue()) {
  +                    String name = signatures.getKey();
  +                    SortedMap particalMap = operationMap.partialMap(name);
  +                    
  +                    long bcMax = 0;
  +                    long bcMin = 0;
  +                    long bcAvg = 0;
  +                    long btMax = 0;
  +                    long btMin = 0;
  +                    long btAvg = 0;
  +                    long wcMax = 0;
  +                    long wcMin = 0;
  +                    long wcAvg = 0;
  +                    long wtMax = 0;
  +                    long wtMin = 0;
  +                    long wtAvg = 0;
  +                    int bcc = 0;
  +                    int btc = 0;
  +                    int wcc = 0;
  +                    int wtc = 0;
  +                    int count = 0;
  +                    for(Object value : particalMap.values()) {
  +                        EnumMap mmap = (EnumMap)value;
  +                        for(MetricName metricName : targetMetricNames) {
  +                            ScaleMetric metric = (ScaleMetric)mmap.get(metricName);
  +                            if(metric==null) continue;
  +                            if(metricName.equals(MetricName.BLOCK_COUNT)) {
  +                                if(metric.getHigh() > bcMax) bcMax = metric.getHigh();
  +                                if(metric.getLow() < bcMin) bcMin = metric.getLow();
  +                                bcAvg += metric.getAverage();
  +                                bcc++;
  +                            }else if(metricName.equals(MetricName.BLOCK_TIME)) {
  +                                if(metric.getHigh() > btMax) btMax = metric.getHigh();
  +                                if(metric.getLow() < btMin) btMin = metric.getLow();
  +                                btAvg += metric.getAverage();
  +                                btc++;
  +                            }else if(metricName.equals(MetricName.WAIT_COUNT)) {
  +                                if(metric.getHigh() > wcMax) wcMax = metric.getHigh();
  +                                if(metric.getLow() < wcMin) wcMin = metric.getLow();
  +                                wcAvg += metric.getAverage();
  +                                wcc++;
  +                            }else if(metricName.equals(MetricName.WAIT_TIME)) {
  +                                if(metric.getHigh() > wtMax) wtMax = metric.getHigh();
  +                                if(metric.getLow() < wtMin) wtMin = metric.getLow();
  +                                wtAvg += metric.getAverage();
  +                                wtc++;
  +                            }
  +                            count++;
  +                        }
  +                    }
  +                    if(count==0) continue;
  +                    bcAvg = bcAvg / bcc;
  +                    btAvg = btAvg / btc;
  +                    wcAvg = wcAvg / wcc;
  +                    wtAvg = wtAvg / wtc;
  +                    writer.writeEmptyElement(XML_RECORD);
  +                    writer.writeAttribute("name", name);
  +                    writer.writeAttribute("depth", String.valueOf(Signature.countDepth(name)));
  +                    writer.writeAttribute("type", signatures.getValue().toString());
  +                    writer.writeAttribute("bcMax", String.valueOf(bcMax));
  +                    writer.writeAttribute("bcMin", String.valueOf(bcMin));
  +                    writer.writeAttribute("bcAvg", String.valueOf(bcAvg));
  +                    writer.writeAttribute("btMax", String.valueOf(btMax));
  +                    writer.writeAttribute("btMin", String.valueOf(btMin));
  +                    writer.writeAttribute("btAvg", String.valueOf(btAvg));
  +                    writer.writeAttribute("wcMax", String.valueOf(wcMax));
  +                    writer.writeAttribute("wcMin", String.valueOf(wcMin));
  +                    writer.writeAttribute("wcAvg", String.valueOf(wcAvg));
  +                    writer.writeAttribute("wtMax", String.valueOf(wtMax));
  +                    writer.writeAttribute("wtMin", String.valueOf(wtMin));
  +                    writer.writeAttribute("wtAvg", String.valueOf(wtAvg));
  +                }
  +                writer.writeEndElement();
  +            }
  +            writer.writeEndElement();
  +            writer.writeEndDocument();
  +        } catch (XMLStreamException e) {
  +            logger.error("failed to write xml.");
  +        } finally {
  +            if(writer!=null) {
  +                try {
  +                    writer.close();
  +                } catch (XMLStreamException e) {
  +                    logger.error("failed to write xml.");
  +                }
  +            }
  +        }
  +    }
  +    
  +}
  
  
  
  1.1.2.1   +161 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/exp/view/servlet/Attic/MemoryMetrics.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MemoryMetrics.java
  ===================================================================
  RCS file: MemoryMetrics.java
  diff -N MemoryMetrics.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ MemoryMetrics.java	26 Oct 2006 08:58:56 -0000	1.1.2.1
  @@ -0,0 +1,161 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + * Copyright 2006, JBoss Inc., and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
  +
  +package org.jboss.profiler.exp.view.servlet;
  +
  +import java.io.IOException;
  +import java.util.EnumMap;
  +import java.util.Map;
  +import java.util.SortedMap;
  +import java.util.TreeMap;
  +
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServlet;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +
  +import javolution.xml.stream.XMLOutputFactory;
  +import javolution.xml.stream.XMLStreamException;
  +import javolution.xml.stream.XMLStreamWriter;
  +
  +import org.apache.log4j.Logger;
  +import org.jboss.profiler.exp.adaptor.ServiceManager;
  +import org.jboss.profiler.exp.agent.collector.model.MetricName;
  +import org.jboss.profiler.exp.agent.collector.model.ScaleMetric;
  +import org.jboss.profiler.exp.util.HierarchicalMap;
  +import org.jboss.profiler.exp.view.util.Signature;
  +
  +/**
  + * The servlet class for writing data for memory statictics.
  + * 
  + * output exsample:
  + * <memoryMetrics>
  + *   <recordSet category="AOP Interceptor">
  + *     <record name="packagename"
  + *             type="p"
  + *             max="3"
  + *             min="0"
  + *             avg="1"/>
  + *   </recordSet>
  + * </memoryMetrics>
  + * 
  + * @author Takuro Okada (Nomura Research Institute, Ltd.)
  + * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
  + * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
  + * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
  + */
  +public class MemoryMetrics extends HttpServlet {
  +    
  +    private final String XML_ROOT = "memoryMetrics";
  +    private final String XML_RECORD_SET = "recordSet";
  +    private final String XML_RECORD = "record";
  +    
  +    private final String DEFAULT_SERVICE_NAME = "jboss.profiler:service=ProfilerService";
  +    
  +    private static Logger logger = Logger.getLogger(MemoryMetrics.class);
  +    
  +    @SuppressWarnings("unchecked")
  +    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  +        
  +        String profilerServiceName = this.getServletContext().getInitParameter("ProfilerServiceName");
  +        if(profilerServiceName==null) profilerServiceName = DEFAULT_SERVICE_NAME;
  +        
  +        // invoke agent to get snapshot of metrics
  +        Object obj = ServiceManager.invokeLocal(profilerServiceName, "snapMetrics");
  +        if(obj==null) {
  +            logger.error("failed to snap the metrics data.");
  +        }
  +        Map metricsMap = (Map)obj;
  +        
  +        // get metrics keys
  +        Map<String, Signature> categoryMap = new TreeMap<String, Signature>();
  +        for(Object set : metricsMap.entrySet()) {
  +            Map.Entry categorySet = (Map.Entry)set;
  +            String category = (String)categorySet.getKey();
  +            Map omap = (Map)categorySet.getValue();
  +            Signature signature = new Signature();
  +            for(Object operationName : omap.keySet()) {
  +                signature.add(String.valueOf(operationName));
  +            }
  +            categoryMap.put(category, signature);
  +        }
  +        
  +        // write xml
  +        response.setContentType("text/plain; charset=UTF-8");
  +        XMLOutputFactory factory = XMLOutputFactory.newInstance();
  +        factory.setProperty(XMLOutputFactory.INDENTATION, "  ");
  +        XMLStreamWriter writer = null;
  +        try {
  +            writer = factory.createXMLStreamWriter(response.getWriter());
  +            writer.writeStartDocument();
  +            writer.writeStartElement(XML_ROOT);
  +            
  +            for(Map.Entry<String, Signature> categorySet : categoryMap.entrySet()) {
  +                writer.writeStartElement(XML_RECORD_SET);
  +                writer.writeAttribute("category", categorySet.getKey());
  +                
  +                HierarchicalMap operationMap = (HierarchicalMap)metricsMap.get(categorySet.getKey());
  +                for(Map.Entry<String, Signature.Type> signatures : categorySet.getValue()) {
  +                    String name = signatures.getKey();
  +                    SortedMap particalMap = operationMap.partialMap(name);
  +                    
  +                    long max = 0;
  +                    long min = 0;
  +                    long average = 0;
  +                    int count = 0;
  +                    for(Object value : particalMap.values()) {
  +                        EnumMap mmap = (EnumMap)value;
  +                        ScaleMetric metric = (ScaleMetric)mmap.get(MetricName.MEMORY_USED);
  +                        if(metric==null) continue;
  +                        if(metric.getHigh() > max) max = metric.getHigh();
  +                        if(metric.getLow() < min) min = metric.getLow();
  +                        average += metric.getAverage();
  +                        count++;
  +                    }
  +                    if(count==0) continue;
  +                    average = average / count;
  +                    writer.writeEmptyElement(XML_RECORD);
  +                    writer.writeAttribute("name", name);
  +                    writer.writeAttribute("depth", String.valueOf(Signature.countDepth(name)));
  +                    writer.writeAttribute("type", signatures.getValue().toString());
  +                    writer.writeAttribute("max", String.valueOf(max));
  +                    writer.writeAttribute("min", String.valueOf(min));
  +                    writer.writeAttribute("avg", String.valueOf(average));
  +                }
  +                writer.writeEndElement();
  +            }
  +            writer.writeEndElement();
  +            writer.writeEndDocument();
  +        } catch (XMLStreamException e) {
  +            logger.error("failed to write xml.");
  +        } finally {
  +            if(writer!=null) {
  +                try {
  +                    writer.close();
  +                } catch (XMLStreamException e) {
  +                    logger.error("failed to write xml.");
  +                }
  +            }
  +        }
  +    }
  +    
  +}
  
  
  



More information about the jboss-cvs-commits mailing list