[jboss-cvs] jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector ...
Takuro Okada
t2-okada at nri.co.jp
Wed Apr 11 07:13:09 EDT 2007
User: tokada
Date: 07/04/11 07:13:09
Added: java/src/expansion/org/jboss/profiler/agent/collector
Tag: JBossProfiler_Expansion
TimeScaleMetricCollectorFactory.java
StackTraceMetricCollectorFactory.java
ExecutionMetricCollectorFactory.java
MetricCollector.java TimeScaleMetricCollector.java
MemoryMetricCollectorFactory.java
CollectorConfig.java
ConcurrentMetricCollectorFactory.java
MetricCollectorFactory.java
ThreadMetricCollector.java
ScaleMetricCollector.java
ThreadMetricCollectorFactory.java
StackMetricCollector.java
Log:
Moved to another directory
Revision Changes Path
No revision
No revision
1.1.2.1 +81 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/TimeScaleMetricCollectorFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TimeScaleMetricCollectorFactory.java
===================================================================
RCS file: TimeScaleMetricCollectorFactory.java
diff -N TimeScaleMetricCollectorFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TimeScaleMetricCollectorFactory.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,81 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.agent.collector.model.MetricName.CPU_TIME_PASSAGE;
+import static org.jboss.profiler.agent.collector.model.MetricName.USER_CPU_TIME_PASSAGE;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+
+import org.jboss.profiler.agent.collector.model.MetricName;
+
+/**
+ *
+ * @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 TimeScaleMetricCollectorFactory extends MetricCollectorFactory {
+
+ private transient static ThreadMXBean threadMXBean = null;
+
+ private boolean cpuTimeSupported = false;
+
+ public TimeScaleMetricCollectorFactory() {
+ super();
+ initialize();
+ }
+
+ private void initialize() {
+ threadMXBean = ManagementFactory.getThreadMXBean();
+ cpuTimeSupported = threadMXBean.isCurrentThreadCpuTimeSupported();
+ if(cpuTimeSupported && !threadMXBean.isThreadCpuTimeEnabled()) {
+ threadMXBean.setThreadCpuTimeEnabled(true);
+ }
+ }
+
+ @Override
+ public MetricCollector createCollector(String category, String operationName, Object... args) {
+ TimeScaleMetricCollector collector = new TimeScaleMetricCollector(category, operationName, System.currentTimeMillis());
+ if(cpuTimeSupported) {
+ collector.setLocalStat(CPU_TIME_PASSAGE, threadMXBean.getCurrentThreadCpuTime());
+ collector.setLocalStat(USER_CPU_TIME_PASSAGE, threadMXBean.getCurrentThreadUserTime());
+ }
+ return collector;
+ }
+
+ @Override
+ public void updateCollector(MetricCollector collector) {
+ if(cpuTimeSupported) {
+ setDifference((TimeScaleMetricCollector)collector, CPU_TIME_PASSAGE, threadMXBean.getCurrentThreadCpuTime());
+ setDifference((TimeScaleMetricCollector)collector, USER_CPU_TIME_PASSAGE, threadMXBean.getCurrentThreadUserTime());
+ }
+ }
+
+ private void setDifference(TimeScaleMetricCollector collector, MetricName name, long value) {
+ collector.setLocalStat(name, value - collector.getLocalStat(name));
+ }
+
+}
1.1.2.1 +77 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/StackTraceMetricCollectorFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: StackTraceMetricCollectorFactory.java
===================================================================
RCS file: StackTraceMetricCollectorFactory.java
diff -N StackTraceMetricCollectorFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ StackTraceMetricCollectorFactory.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,77 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.agent.collector.model.MetricName.STACK_TRACE;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+/**
+ *
+ * @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 StackTraceMetricCollectorFactory extends MetricCollectorFactory {
+
+ private transient static ThreadMXBean threadMXBean = null;
+
+ public StackTraceMetricCollectorFactory() {
+ super();
+ initialize();
+ }
+
+ private void initialize() {
+ threadMXBean = ManagementFactory.getThreadMXBean();
+ }
+
+ @Override
+ public MetricCollector createCollector(String category, String operationName, Object... args) {
+ ThreadInfo threadInfo = threadMXBean.getThreadInfo(Thread.currentThread().getId(), Integer.MAX_VALUE);
+ StackMetricCollector collector = new StackMetricCollector(category, operationName);
+ collector.setLocalStat(STACK_TRACE, retrieveMethodNames(threadInfo.getStackTrace(), operationName));
+ return collector;
+ }
+
+ @Override
+ public void updateCollector(MetricCollector collector) {
+ // Does nothing.
+ }
+
+ private String[] retrieveMethodNames(StackTraceElement[] elements, String operationName) {
+ String[] result = new String[elements.length];
+ for(int i=0; i<elements.length; i++) {
+ int ci = elements.length - 1 - i;
+ StringBuilder sb = new StringBuilder();
+ sb.append(elements[ci].getClassName());
+ sb.append('.');
+ sb.append(elements[ci].getMethodName());
+ result[i] = sb.toString();
+ }
+ return result;
+ }
+
+}
1.1.2.1 +86 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/ExecutionMetricCollectorFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ExecutionMetricCollectorFactory.java
===================================================================
RCS file: ExecutionMetricCollectorFactory.java
diff -N ExecutionMetricCollectorFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ExecutionMetricCollectorFactory.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,86 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.agent.collector.model.MetricName.CPU_TIME;
+import static org.jboss.profiler.agent.collector.model.MetricName.REAL_TIME;
+import static org.jboss.profiler.agent.collector.model.MetricName.USER_CPU_TIME;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+
+import org.jboss.profiler.agent.collector.model.MetricName;
+
+/**
+ *
+ * @see org.jboss.profiler.production.collector.OperationMetricCollectorFactory
+ * @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 ExecutionMetricCollectorFactory extends MetricCollectorFactory {
+
+ private transient static ThreadMXBean threadMXBean = null;
+
+ private boolean cpuTimeSupported = false;
+
+ public ExecutionMetricCollectorFactory() {
+ super();
+ initialize();
+ }
+
+ private void initialize() {
+ threadMXBean = ManagementFactory.getThreadMXBean();
+ cpuTimeSupported = threadMXBean.isCurrentThreadCpuTimeSupported();
+ if(cpuTimeSupported && !threadMXBean.isThreadCpuTimeEnabled()) {
+ threadMXBean.setThreadCpuTimeEnabled(true);
+ }
+ }
+
+ @Override
+ public MetricCollector createCollector(String category, String operationName, Object... args) {
+ ScaleMetricCollector collector = new ScaleMetricCollector(category, operationName);
+ if(cpuTimeSupported) {
+ collector.setLocalStat(CPU_TIME, threadMXBean.getCurrentThreadCpuTime());
+ collector.setLocalStat(USER_CPU_TIME, threadMXBean.getCurrentThreadUserTime());
+ }
+ collector.setLocalStat(REAL_TIME, System.nanoTime());
+ return collector;
+ }
+
+ @Override
+ public void updateCollector(MetricCollector collector) {
+ ScaleMetricCollector scaleMetricCollector = (ScaleMetricCollector)collector;
+ if(cpuTimeSupported) {
+ setDifference(scaleMetricCollector, CPU_TIME, threadMXBean.getCurrentThreadCpuTime());
+ setDifference(scaleMetricCollector, USER_CPU_TIME, threadMXBean.getCurrentThreadUserTime());
+ }
+ setDifference(scaleMetricCollector, REAL_TIME, System.nanoTime());
+ }
+
+ private void setDifference(ScaleMetricCollector collector, MetricName name, long value ) {
+ collector.setLocalStat(name, value - collector.getLocalStat(name));
+ }
+
+}
1.1.2.1 +85 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/MetricCollector.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MetricCollector.java
===================================================================
RCS file: MetricCollector.java
diff -N MetricCollector.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MetricCollector.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,85 @@
+/*
+ * 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.agent.collector;
+
+import java.io.Serializable;
+
+import org.jboss.profiler.agent.collector.model.MetricName;
+import org.jboss.profiler.agent.collector.model.MetricsMap;
+
+/**
+ * This interface temporarily keeps the metric value and replaces it to the persistent object.
+ * <p>It is necessary to replace in the run() method.</p>
+ *
+ * @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 interface MetricCollector<T> extends Runnable, Serializable {
+
+ /**
+ * Gives the operation name after construction.
+ * @param operationName - opetation name
+ */
+ void setOperationName(String operationName);
+
+ /**
+ * Gives some arguments after construction.
+ * @param operationName - opetation name
+ */
+ void setArguments(Object[] objects);
+
+ /**
+ * Sets temporary value.
+ * @param metricName - kind of value
+ * @param value - temporary value
+ */
+ void setLocalStat(MetricName metricName, T value);
+
+ /**
+ * Gets temporary value.
+ * @param metricName - kind of value
+ * @return - temporary value
+ */
+ T getLocalStat(MetricName metricName);
+
+ /**
+ * Removes temporary value.
+ * @param metricName - kind of value
+ */
+ void removeLocalStat(String metricName);
+
+ /**
+ * Sets the map object of entity for replacement.
+ * @param metricMap - persistent object
+ */
+ void setMetricsMap(MetricsMap metricsMap);
+
+ /**
+ * Sets the config information
+ * @param config - config object
+ */
+ void setCollectorConfig(CollectorConfig config);
+
+}
1.1.2.1 +113 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/TimeScaleMetricCollector.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TimeScaleMetricCollector.java
===================================================================
RCS file: TimeScaleMetricCollector.java
diff -N TimeScaleMetricCollector.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TimeScaleMetricCollector.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,113 @@
+/*
+ * 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.agent.collector;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.profiler.agent.collector.model.Metric;
+import org.jboss.profiler.agent.collector.model.MetricName;
+import org.jboss.profiler.agent.collector.model.MetricsMap;
+import org.jboss.profiler.agent.collector.model.TimeScaleMetric;
+import org.jboss.profiler.util.HierarchicalMap;
+
+/**
+ *
+ * @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 TimeScaleMetricCollector implements MetricCollector<Long> {
+
+ private String category = null;
+ private String operationName = null;
+ private long timestamp = 0L;
+
+ private Map<MetricName, Long> localStats = null;
+
+ private MetricsMap metricsMap = null;
+
+ public TimeScaleMetricCollector(String category, String operationName, long timestamp, Object... args) {
+ this.category = category;
+ this.operationName = operationName;
+ this.timestamp = timestamp;
+ localStats = new HashMap<MetricName, Long>();
+ }
+
+ public void setOperationName(String operationName) {
+ this.operationName = operationName;
+ }
+
+ public void setArguments(Object[] args) {
+ // Does nothing.
+ }
+
+ public void setLocalStat(MetricName metricName, Long value) {
+ localStats.put(metricName, value);
+ }
+
+ public Long getLocalStat(MetricName metricName) {
+ return localStats.get(metricName);
+ }
+
+ public void removeLocalStat(String metricName) {
+ localStats.remove(metricName);
+ }
+
+ public void setMetricsMap(MetricsMap metricsMap) {
+ this.metricsMap = metricsMap;
+ }
+
+ public void setCollectorConfig(CollectorConfig config) {
+ // Does not use a config.
+ }
+
+ public void run() {
+ Map<MetricName, Metric> mmap = null;
+ if(metricsMap.containsKey(category)) {
+ Map<String, Map<MetricName, Metric>> omap = metricsMap.get(category);
+ mmap = omap.get(operationName);
+ if(mmap==null) {
+ mmap = new EnumMap<MetricName, Metric>(MetricName.class);
+ omap.put(operationName, mmap);
+ }
+ }else {
+ mmap = new EnumMap<MetricName, Metric>(MetricName.class);
+ Map<String, Map<MetricName, Metric>> omap = new HierarchicalMap<String, Map<MetricName, Metric>>();
+ omap.put(operationName, mmap);
+ metricsMap.put(category, omap);
+ }
+ for(Map.Entry<MetricName, Long> localStat : localStats.entrySet()) {
+ MetricName key = localStat.getKey();
+ TimeScaleMetric metric = (TimeScaleMetric)mmap.get(key);
+ if(metric==null) {
+ metric = new TimeScaleMetric();
+ mmap.put(localStat.getKey(), metric);
+ }
+ metric.update(localStat.getValue(), timestamp);
+ }
+ }
+
+}
1.1.2.1 +71 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/MemoryMetricCollectorFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MemoryMetricCollectorFactory.java
===================================================================
RCS file: MemoryMetricCollectorFactory.java
diff -N MemoryMetricCollectorFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MemoryMetricCollectorFactory.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,71 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.agent.collector.model.MetricName.MEMORY_USED;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryUsage;
+
+import org.jboss.profiler.agent.collector.model.MetricName;
+
+/**
+ *
+ * @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 MemoryMetricCollectorFactory extends MetricCollectorFactory {
+
+ private transient static MemoryMXBean memoryMXBean = null;
+
+ public MemoryMetricCollectorFactory() {
+ super();
+ initialize();
+ }
+
+ private void initialize() {
+ memoryMXBean = ManagementFactory.getMemoryMXBean();
+ }
+
+ @Override
+ public MetricCollector createCollector(String category, String operationName, Object... args) {
+ MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage();
+ ScaleMetricCollector collector = new ScaleMetricCollector(category, operationName);
+ collector.setLocalStat(MEMORY_USED, memoryUsage.getUsed());
+ return collector;
+ }
+
+ @Override
+ public void updateCollector(MetricCollector collector) {
+ MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage();
+ setDifference((ScaleMetricCollector)collector, MEMORY_USED, memoryUsage.getUsed());
+ }
+
+ private void setDifference(ScaleMetricCollector collector, MetricName name, long value ) {
+ collector.setLocalStat(name, value - collector.getLocalStat(name));
+ }
+
+}
1.1.2.1 +153 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/CollectorConfig.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CollectorConfig.java
===================================================================
RCS file: CollectorConfig.java
diff -N CollectorConfig.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CollectorConfig.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,153 @@
+package org.jboss.profiler.agent.collector;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Set;
+
+import javolution.util.FastMap;
+import javolution.util.FastSet;
+import javolution.xml.stream.XMLInputFactory;
+import javolution.xml.stream.XMLStreamConstants;
+import javolution.xml.stream.XMLStreamException;
+import javolution.xml.stream.XMLStreamReader;
+
+import org.jboss.profiler.adaptor.AgentConfig;
+
+public class CollectorConfig implements Serializable {
+
+ private static String FILE_PATH_KEY = "org.jboss.profiler.collector.config";
+
+ private AgentConfig agent = new AgentConfig();
+ private Map<String, String> jdbcImplementationMap = new FastMap<String, String>();
+ private Set<String> frameworkExpressionSet = new FastSet<String>();
+
+ /**
+ * Loads the configuration file specified and fills properties.
+ * @param filePath
+ */
+ public CollectorConfig(String filePath) throws IOException {
+ load(filePath);
+ }
+
+ /**
+ * Gets setting of agent connection.
+ * @return
+ */
+ public AgentConfig getAgent() {
+ return agent;
+ }
+
+ /**
+ * Gets names of implementation classes mapped JDBC interfaces.
+ * @return map object (implementation : interface)
+ */
+ public Map<String, String> getJdbcImplementationMap() {
+ return jdbcImplementationMap;
+ }
+
+ /**
+ * Gets expressions of framework objects.
+ * @return set object
+ */
+ public Set<String> getFrameworkExpressionSet() {
+ return frameworkExpressionSet;
+ }
+
+ private void load(String filePath) throws IOException {
+ InputStream is = null;
+ XMLStreamReader reader = null;
+ try {
+ is = this.getClass().getResourceAsStream(filePath);
+ if(is==null) {
+ filePath = System.getProperty(FILE_PATH_KEY);
+ if(filePath!=null) is = new FileInputStream(filePath);
+ }
+ if(is==null) {
+ throw new IOException("Collector Config file is not found.");
+ }
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ reader = factory.createXMLStreamReader(is);
+ String state = "";
+ while(reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
+ switch(reader.next()) {
+ case XMLStreamConstants.START_ELEMENT:
+ if(reader.getLocalName().equals("agent")) state = "agent";
+ else if(reader.getLocalName().equals("jdbc")) state = "jdbc";
+ else if(reader.getLocalName().equals("framework")) state = "framework";
+
+ else if(state.equals("agent")) {
+ if(reader.getLocalName().equals("service-name")) {
+ if(reader.hasNext()) {
+ reader.next();
+ if(reader.hasText()) {
+ agent.setServiceName(reader.getText().toString());
+ }
+ }
+ }else if(reader.getLocalName().equals("jmx-connector-url")) {
+ if(reader.hasNext()) {
+ reader.next();
+ if(reader.hasText()) {
+ agent.setJmxConnectorUrl(reader.getText().toString());
+ }
+ }
+ }else if(reader.getLocalName().equals("jmx-connector-jndi-name")) {
+ if(reader.hasNext()) {
+ reader.next();
+ if(reader.hasText()) {
+ agent.setJmxConnectorJndiName(reader.getText().toString());
+ }
+ }
+ }else if(reader.getLocalName().equals("jmx-connector-jndi-context-factory")) {
+ if(reader.hasNext()) {
+ reader.next();
+ if(reader.hasText()) {
+ agent.setJmxConnectorJndiContextFactory(reader.getText().toString());
+ }
+ }
+ }else if(reader.getLocalName().equals("jaas-user-name")) {
+ if(reader.hasNext()) {
+ reader.next();
+ if(reader.hasText()) {
+ agent.setJaasUserName(reader.getText().toString());
+ }
+ }
+ }else if(reader.getLocalName().equals("jaas-password")) {
+ if(reader.hasNext()) {
+ reader.next();
+ if(reader.hasText()) {
+ agent.setJaasPassword(reader.getText().toString());
+ }
+ }
+ }
+ }
+ else if(state.equals("jdbc") && reader.getLocalName().equals("impl-mapping")) {
+ String key = reader.getAttributeValue(null, "impl").toString();
+ String value = reader.getAttributeValue(null, "interface").toString();
+ jdbcImplementationMap.put(key, value);
+ }
+ else if(state.equals("framework") && reader.getLocalName().equals("expression")) {
+ if(reader.hasNext()) {
+ reader.next();
+ if(reader.hasText()) {
+ frameworkExpressionSet.add(reader.getText().toString());
+ }
+ }
+ }
+ }
+ }
+ } catch (XMLStreamException e) {
+ throw new IOException(e.getMessage());
+ } finally {
+ if(is!=null) is.close();
+ try {
+ if(reader!=null) reader.close();
+ } catch (XMLStreamException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+ }
+
+}
1.1.2.1 +91 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/ConcurrentMetricCollectorFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConcurrentMetricCollectorFactory.java
===================================================================
RCS file: ConcurrentMetricCollectorFactory.java
diff -N ConcurrentMetricCollectorFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ConcurrentMetricCollectorFactory.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,91 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.agent.collector.model.MetricName.BLOCK_COUNT;
+import static org.jboss.profiler.agent.collector.model.MetricName.BLOCK_TIME;
+import static org.jboss.profiler.agent.collector.model.MetricName.WAIT_COUNT;
+import static org.jboss.profiler.agent.collector.model.MetricName.WAIT_TIME;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+import org.jboss.profiler.agent.collector.model.MetricName;
+
+/**
+ *
+ * @see org.jboss.profiler.production.collector.OperationMetricCollectorFactory
+ * @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 ConcurrentMetricCollectorFactory extends MetricCollectorFactory {
+
+ private transient static ThreadMXBean threadMXBean = null;
+
+ private boolean contentionSupported = false;
+
+ public ConcurrentMetricCollectorFactory() {
+ super();
+ initialize();
+ }
+
+ private void initialize() {
+ threadMXBean = ManagementFactory.getThreadMXBean();
+ contentionSupported = threadMXBean.isThreadContentionMonitoringSupported();
+ if(contentionSupported && !threadMXBean.isThreadContentionMonitoringEnabled()) {
+ threadMXBean.setThreadContentionMonitoringEnabled(true);
+ }
+ }
+
+ @Override
+ public MetricCollector createCollector(String category, String operationName, Object... args) {
+ ThreadInfo threadInfo = threadMXBean.getThreadInfo(Thread.currentThread().getId());
+ ScaleMetricCollector collector = new ScaleMetricCollector(category, operationName);
+ collector.setLocalStat(BLOCK_COUNT, threadInfo.getBlockedCount());
+ collector.setLocalStat(WAIT_COUNT, threadInfo.getWaitedCount());
+ if(contentionSupported) {
+ collector.setLocalStat(BLOCK_TIME, threadInfo.getBlockedTime());
+ collector.setLocalStat(WAIT_TIME, threadInfo.getWaitedTime());
+ }
+ return collector;
+ }
+
+ @Override
+ public void updateCollector(MetricCollector collector) {
+ ThreadInfo threadInfo = threadMXBean.getThreadInfo(Thread.currentThread().getId());
+ setDifference((ScaleMetricCollector)collector, BLOCK_COUNT, threadInfo.getBlockedCount());
+ setDifference((ScaleMetricCollector)collector, WAIT_COUNT, threadInfo.getWaitedCount());
+ if(contentionSupported) {
+ setDifference((ScaleMetricCollector)collector, BLOCK_TIME, threadInfo.getBlockedTime());
+ setDifference((ScaleMetricCollector)collector, WAIT_TIME, threadInfo.getWaitedTime());
+ }
+ }
+
+ private void setDifference(ScaleMetricCollector collector, MetricName name, long value ) {
+ collector.setLocalStat(name, value - collector.getLocalStat(name));
+ }
+
+}
1.1.2.1 +106 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/MetricCollectorFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MetricCollectorFactory.java
===================================================================
RCS file: MetricCollectorFactory.java
diff -N MetricCollectorFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MetricCollectorFactory.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,106 @@
+/*
+ * 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.agent.collector;
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.jboss.profiler.adaptor.AgentConfig;
+import org.jboss.profiler.adaptor.ServiceManager;
+import org.jboss.profiler.agent.IProfilerService;
+
+/**
+ * This class create collector instance, and submit collector to JMX servce.
+ *
+ * @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 abstract class MetricCollectorFactory {
+
+ protected static Logger logger = Logger.getLogger(MetricCollectorFactory.class);
+
+ /*
+ * JMX service proxy
+ */
+ private IProfilerService profilerServiceProxy = null;
+
+ /*
+ * collector config
+ */
+ private CollectorConfig collectorConfig = null;
+ private static final String COLLECTOR_CONFIG_FILE_PATH = "/collector-config.xml";
+
+ private static final String DEFAULT_AGENT_SERVICE_NAME = "jboss.profiler:service=ProfilerService";
+
+ /**
+ * Constructs instance and connects to JMX service by local access.
+ */
+ public MetricCollectorFactory() {
+ loadCollectorConfig();
+ if(collectorConfig!=null) {
+ AgentConfig agentConfig = collectorConfig.getAgent();
+ if(agentConfig.getJmxConnectorUrl().contains("localhost")) {
+ profilerServiceProxy = (IProfilerService)ServiceManager.createLocalProxy(agentConfig.getServiceName(), IProfilerService.class);
+ }else {
+ profilerServiceProxy = (IProfilerService)ServiceManager.createRemoteProxy(agentConfig, IProfilerService.class);
+ }
+ }else {
+ profilerServiceProxy = (IProfilerService)ServiceManager.createLocalProxy(DEFAULT_AGENT_SERVICE_NAME, IProfilerService.class);
+ }
+ }
+
+ /**
+ * Creates collector and measures current metric value.
+ * @param category - metric category
+ * @param operationName - metric operation name
+ * @param args - optional value
+ * @return created collector
+ */
+ public abstract MetricCollector createCollector(String category, String operationName, Object... args);
+
+ /**
+ * Updates collector created.
+ * @param collector - created collector
+ */
+ public abstract void updateCollector(MetricCollector collector);
+
+ /**
+ * Submits collector to JMX service.
+ * @param collector - collector to submit
+ */
+ public synchronized void submitCollector(MetricCollector collector) {
+ collector.setCollectorConfig(collectorConfig);
+ profilerServiceProxy.submitMetric(collector);
+ }
+
+ private void loadCollectorConfig() {
+ try {
+ collectorConfig = new CollectorConfig(COLLECTOR_CONFIG_FILE_PATH);
+ } catch (IOException e) {
+ logger.error("failed to load the collector config.", e);
+ }
+ }
+
+}
1.1.2.1 +219 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/ThreadMetricCollector.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ThreadMetricCollector.java
===================================================================
RCS file: ThreadMetricCollector.java
diff -N ThreadMetricCollector.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ThreadMetricCollector.java 11 Apr 2007 11:13:09 -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.agent.collector;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.profiler.agent.collector.model.Metric;
+import org.jboss.profiler.agent.collector.model.MetricName;
+import org.jboss.profiler.agent.collector.model.MetricsMap;
+import org.jboss.profiler.agent.collector.model.ThreadMetric;
+import org.jboss.profiler.util.HierarchicalMap;
+
+/**
+ *
+ * @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 ThreadMetricCollector implements MetricCollector<Long> {
+
+ private String category = null;
+ private String operationName = null;
+ private long timestamp = 0L;
+ private Object threadId = null;
+ private Object caller = null;
+ private Object addition = null;
+
+ private StackTraceElement[] stackTrace = null;
+
+ private Map<MetricName, Long> localStats = null;
+
+ private MetricsMap metricsMap = null;
+
+ private CollectorConfig config = null;
+
+ public ThreadMetricCollector(String category, String operationName, long timestamp, Object... args) {
+ this.category = category;
+ this.operationName = operationName;
+ this.timestamp = timestamp;
+ localStats = new HashMap<MetricName, Long>();
+ }
+
+ public void setOperationName(String operationName) {
+ this.operationName = operationName;
+ }
+
+ public void setArguments(Object[] args) {
+ if(args!=null) {
+ if(args.length>0) this.threadId = args[0];
+ if(args.length>1) this.caller = args[1];
+ if(args.length>2) this.addition = args[2];
+ }
+ }
+
+ public void setLocalStat(MetricName metricName, Long value) {
+ localStats.put(metricName, value);
+ }
+
+ public Long getLocalStat(MetricName metricName) {
+ return localStats.get(metricName);
+ }
+
+ public void removeLocalStat(String metricName) {
+ localStats.remove(metricName);
+ }
+
+ public void setStackTrace(StackTraceElement[] stackTrace) {
+ this.stackTrace = stackTrace;
+ }
+
+ public void setMetricsMap(MetricsMap metricsMap) {
+ this.metricsMap = metricsMap;
+ }
+
+ public void setCollectorConfig(CollectorConfig config) {
+ this.config = config;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder expression = new StringBuilder();
+ expression.append("Category=");
+ expression.append(category);
+ expression.append(", ");
+ expression.append("OperationName=");
+ expression.append(operationName);
+ expression.append(", ");
+ expression.append("Timestamp=");
+ expression.append(timestamp);
+ expression.append(", ");
+ expression.append("ThreadId=");
+ expression.append(threadId);
+ expression.append(", ");
+ expression.append("Caller=");
+ expression.append(caller);
+ expression.append(", ");
+ expression.append("Addition=");
+ expression.append(addition);
+ expression.append(", ");
+ expression.append("LocalStats=");
+ expression.append(localStats);
+ return expression.toString();
+ }
+
+ public void run() {
+ Map<MetricName, Metric> mmap = null;
+ if(metricsMap.containsKey(category)) {
+ Map<String, Map<MetricName, Metric>> omap = metricsMap.get(category);
+ mmap = omap.get(String.valueOf(threadId));
+ if(mmap==null) {
+ mmap = new EnumMap<MetricName, Metric>(MetricName.class);
+ omap.put(String.valueOf(threadId), mmap);
+ }
+ }else {
+ mmap = new EnumMap<MetricName, Metric>(MetricName.class);
+ Map<String, Map<MetricName, Metric>> omap = new HierarchicalMap<String, Map<MetricName, Metric>>(new ThreadIdComparator());
+ omap.put(String.valueOf(threadId), mmap);
+ metricsMap.put(category, omap);
+ }
+ for(Map.Entry<MetricName, Long> localStat : localStats.entrySet()) {
+ MetricName key = localStat.getKey();
+ ThreadMetric metric = (ThreadMetric)mmap.get(key);
+ if(metric==null) {
+ metric = new ThreadMetric();
+ mmap.put(localStat.getKey(), metric);
+ }
+// metric.update(localStat.getValue(), operationName, timestamp, caller, addition);
+ metric.update(localStat.getValue(), operationName, timestamp, retrieveCaller(), addition);
+ }
+ }
+
+ private String retrieveCaller() {
+ String result = null;
+ Integer index = null;
+ boolean jdbcOperation = false;
+ if(operationName.contains("java.sql")) jdbcOperation = true;
+ for(int i=0; i<stackTrace.length; i++) {
+ if(!jdbcOperation) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(stackTrace[i].getClassName());
+ sb.append('.');
+ sb.append(stackTrace[i].getMethodName());
+ if(sb.toString().equals(operationName)) {
+ index = i;
+ break;
+ }
+ }else {
+ String interfaceName = config.getJdbcImplementationMap().get(stackTrace[i].getClassName());
+ if(interfaceName==null) continue;
+ if(operationName.contains(stackTrace[i].getMethodName())) {
+ index = i;
+ break;
+ }
+ }
+ }
+ if(index==null) return result;
+ for(int i=index+1; i<stackTrace.length; i++) {
+ String className = stackTrace[i].getClassName();
+ String methodName = stackTrace[i].getMethodName();
+ // Ignores weaved classes.
+ if(className.contains("$")) continue;
+ else if(methodName.contains("$")) continue;
+ // Ignores classes AspectWerkz weaved
+ else if(className.endsWith("_AW_JoinPoint")) continue;
+ // Ignores JBoss Profiler classes.
+ else if(className.startsWith("org.jboss.profiler.agent.interceptor")) continue;
+ // Retrieve servlet class.
+ else if(className.equals("javax.servlet.http.HttpServlet") || className.equals("javax.servlet.GenericServlet")) {
+ result = "<servlet>";
+ break;
+ }
+ // Ignores Java API classes
+ else if(className.startsWith("java") || className.startsWith("sun")) continue;
+ else {
+ // Ignores framework classes.
+ boolean ignore = false;
+ for(String expression : config.getFrameworkExpressionSet()) {
+ if(className.contains(expression)) ignore = true;
+ }
+ if(ignore) continue;
+ }
+ result = className+"."+methodName;
+ break;
+ }
+ return result;
+ }
+
+ private class ThreadIdComparator implements Comparator<String>, Serializable {
+ public int compare(String o1, String o2) {
+ return Long.valueOf(o1).compareTo(Long.valueOf(o2));
+ }
+ }
+
+}
1.1.2.1 +112 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/ScaleMetricCollector.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ScaleMetricCollector.java
===================================================================
RCS file: ScaleMetricCollector.java
diff -N ScaleMetricCollector.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ScaleMetricCollector.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,112 @@
+/*
+ * 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.agent.collector;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.profiler.agent.collector.model.Metric;
+import org.jboss.profiler.agent.collector.model.MetricName;
+import org.jboss.profiler.agent.collector.model.MetricsMap;
+import org.jboss.profiler.agent.collector.model.ScaleMetric;
+import org.jboss.profiler.util.HierarchicalMap;
+
+/**
+ *
+ * @see org.jboss.profiler.production.collector.OperationMetricCollector
+ * @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 ScaleMetricCollector implements MetricCollector<Long> {
+
+ private String category = null;
+ private String operationName = null;
+
+ private Map<MetricName, Long> localStats = null;
+
+ private MetricsMap metricsMap = null;
+
+ public ScaleMetricCollector(String category, String operationName) {
+ this.category = category;
+ this.operationName = operationName;
+ localStats = new HashMap<MetricName, Long>();
+ }
+
+ public void setOperationName(String operationName) {
+ this.operationName = operationName;
+ }
+
+ public void setArguments(Object[] objects) {
+ // Does nothing.
+ }
+
+ public void setLocalStat(MetricName metricName, Long value) {
+ localStats.put(metricName, (Long)value);
+ }
+
+ public Long getLocalStat(MetricName metricName) {
+ return localStats.get(metricName);
+ }
+
+ public void removeLocalStat(String metricName) {
+ localStats.remove(metricName);
+ }
+
+ public void setMetricsMap(MetricsMap metricsMap) {
+ this.metricsMap = metricsMap;
+ }
+
+ public void setCollectorConfig(CollectorConfig config) {
+ // Does not use a config.
+ }
+
+ public void run() {
+ Map<MetricName, Metric> mmap = null;
+ if(metricsMap.containsKey(category)) {
+ Map<String, Map<MetricName, Metric>> omap = metricsMap.get(category);
+ mmap = omap.get(operationName);
+ if(mmap==null) {
+ mmap = new EnumMap<MetricName, Metric>(MetricName.class);
+ omap.put(operationName, mmap);
+ }
+ }else {
+ mmap = new EnumMap<MetricName, Metric>(MetricName.class);
+ Map<String, Map<MetricName, Metric>> omap = new HierarchicalMap<String, Map<MetricName, Metric>>();
+ omap.put(operationName, mmap);
+ metricsMap.put(category, omap);
+ }
+ for(Map.Entry<MetricName, Long> localStat : localStats.entrySet()) {
+ MetricName key = localStat.getKey();
+ ScaleMetric metric = (ScaleMetric)mmap.get(key);
+ if(metric==null) {
+ metric = new ScaleMetric();
+ mmap.put(localStat.getKey(), metric);
+ }
+ metric.update(localStat.getValue());
+ }
+ }
+
+}
1.1.2.1 +88 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/ThreadMetricCollectorFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ThreadMetricCollectorFactory.java
===================================================================
RCS file: ThreadMetricCollectorFactory.java
diff -N ThreadMetricCollectorFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ThreadMetricCollectorFactory.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,88 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.agent.collector.model.MetricName.CPU_TIME_PASSAGE_DETAIL;
+import static org.jboss.profiler.agent.collector.model.MetricName.REAL_TIME_PASSAGE_DETAIL;
+import static org.jboss.profiler.agent.collector.model.MetricName.USER_CPU_TIME_PASSAGE_DETAIL;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+import org.jboss.profiler.agent.collector.model.MetricName;
+
+/**
+ *
+ * @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 ThreadMetricCollectorFactory extends MetricCollectorFactory {
+
+ private transient static ThreadMXBean threadMXBean = null;
+
+ private boolean cpuTimeSupported = false;
+
+ public ThreadMetricCollectorFactory() {
+ super();
+ initialize();
+ }
+
+ private void initialize() {
+ threadMXBean = ManagementFactory.getThreadMXBean();
+ cpuTimeSupported = threadMXBean.isCurrentThreadCpuTimeSupported();
+ if(cpuTimeSupported && !threadMXBean.isThreadCpuTimeEnabled()) {
+ threadMXBean.setThreadCpuTimeEnabled(true);
+ }
+ }
+
+ @Override
+ public MetricCollector createCollector(String category, String operationName, Object... args) {
+ ThreadMetricCollector collector = new ThreadMetricCollector(category, operationName, System.currentTimeMillis());
+ if(cpuTimeSupported) {
+ collector.setLocalStat(CPU_TIME_PASSAGE_DETAIL, threadMXBean.getCurrentThreadCpuTime());
+ collector.setLocalStat(USER_CPU_TIME_PASSAGE_DETAIL, threadMXBean.getCurrentThreadUserTime());
+ }
+ collector.setLocalStat(REAL_TIME_PASSAGE_DETAIL, System.nanoTime());
+ return collector;
+ }
+
+ @Override
+ public void updateCollector(MetricCollector collector) {
+ ThreadMetricCollector threadMetricCollector = (ThreadMetricCollector)collector;
+ if(cpuTimeSupported) {
+ setDifference(threadMetricCollector, CPU_TIME_PASSAGE_DETAIL, threadMXBean.getCurrentThreadCpuTime());
+ setDifference(threadMetricCollector, USER_CPU_TIME_PASSAGE_DETAIL, threadMXBean.getCurrentThreadUserTime());
+ }
+ setDifference(threadMetricCollector, REAL_TIME_PASSAGE_DETAIL, System.nanoTime());
+ ThreadInfo threadInfo = threadMXBean.getThreadInfo(Thread.currentThread().getId(), Integer.MAX_VALUE);
+ threadMetricCollector.setStackTrace(threadInfo.getStackTrace());
+ }
+
+ private void setDifference(ThreadMetricCollector collector, MetricName name, long value) {
+ collector.setLocalStat(name, value - collector.getLocalStat(name));
+ }
+
+}
1.1.2.1 +125 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/agent/collector/Attic/StackMetricCollector.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: StackMetricCollector.java
===================================================================
RCS file: StackMetricCollector.java
diff -N StackMetricCollector.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ StackMetricCollector.java 11 Apr 2007 11:13:09 -0000 1.1.2.1
@@ -0,0 +1,125 @@
+/*
+ * 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.agent.collector;
+
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.profiler.agent.collector.model.Metric;
+import org.jboss.profiler.agent.collector.model.MetricName;
+import org.jboss.profiler.agent.collector.model.MetricsMap;
+import org.jboss.profiler.agent.collector.model.StackMetric;
+import org.jboss.profiler.util.HierarchicalMap;
+
+/**
+ *
+ * @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 StackMetricCollector implements MetricCollector<String[]> {
+
+ private String category = null;
+ private String operationName = null;
+
+ private Map<MetricName, String[]> localStats = null;
+
+ private MetricsMap metricsMap = null;
+
+ public StackMetricCollector(String category, String operationName) {
+ this.category = category;
+ this.operationName = operationName;
+ localStats = new HashMap<MetricName, String[]>();
+ }
+
+ public void setOperationName(String operationName) {
+ this.operationName = operationName;
+ for(Map.Entry<MetricName, String[]> entry : localStats.entrySet()) {
+ localStats.put(entry.getKey(), cutoffMethodNames(entry.getValue(), operationName));
+ }
+ }
+
+ public void setArguments(Object[] objects) {
+ // Does nothing.
+ }
+
+ public void setLocalStat(MetricName metricName, String[] value) {
+ localStats.put(metricName, value);
+ }
+
+ public String[] getLocalStat(MetricName metricName) {
+ return localStats.get(metricName);
+ }
+
+ public void removeLocalStat(String metricName) {
+ localStats.remove(metricName);
+ }
+
+ public void setMetricsMap(MetricsMap metricsMap) {
+ this.metricsMap = metricsMap;
+ }
+
+ public void setCollectorConfig(CollectorConfig config) {
+ // Does not use a config.
+ }
+
+ private String[] cutoffMethodNames(String[] source, String operationName) {
+ List<String> result = new ArrayList<String>();
+ for(int i=0; i<source.length; i++) {
+ result.add(source[i]);
+ if(source[i].equals(operationName)) break;
+ }
+ return result.toArray(new String[result.size()]);
+ }
+
+ public void run() {
+ Map<MetricName, Metric> mmap = null;
+ if(metricsMap.containsKey(category)) {
+ Map<String, Map<MetricName, Metric>> omap = metricsMap.get(category);
+ mmap = omap.get(operationName);
+ if(mmap==null) {
+ mmap = new EnumMap<MetricName, Metric>(MetricName.class);
+ omap.put(operationName, mmap);
+ }
+ }else {
+ mmap = new EnumMap<MetricName, Metric>(MetricName.class);
+ Map<String, Map<MetricName, Metric>> omap = new HierarchicalMap<String, Map<MetricName, Metric>>();
+ omap.put(operationName, mmap);
+ metricsMap.put(category, omap);
+ }
+ for(Map.Entry<MetricName, String[]> localStat : localStats.entrySet()) {
+ MetricName key = localStat.getKey();
+ StackMetric metric = (StackMetric)mmap.get(key);
+ if(metric==null) {
+ metric = new StackMetric();
+ mmap.put(localStat.getKey(), metric);
+ }
+ metric.update(localStat.getValue());
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list