[jboss-cvs] jboss-profiler/java/src/expansion/org/jboss/profiler/exp/agent/collector ...
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/agent/collector
Tag: JBossProfiler_Expansion
ConcurrentMetricCollectorFactory.java
TimeScaleMetricCollectorFactory.java
MemoryMetricCollectorFactory.java
MetricCollector.java ThreadMetricCollector.java
TimeScaleMetricCollector.java
ExecutionMetricCollectorFactory.java
StackTraceMetricCollectorFactory.java
StackMetricCollector.java
ThreadMetricCollectorFactory.java
ScaleMetricCollector.java
MetricCollectorFactory.java
Log:
Revision Changes Path
No revision
No revision
1.1.2.1 +96 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,96 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.BLOCK_COUNT;
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.BLOCK_TIME;
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.WAIT_COUNT;
+import static org.jboss.profiler.exp.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.exp.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(String profilerServiceName) {
+ super(profilerServiceName);
+ initialize();
+ }
+
+ public ConcurrentMetricCollectorFactory(String profilerServiceName, String remoteUrl) {
+ super(profilerServiceName, remoteUrl);
+ 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 +86 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -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.exp.agent.collector;
+
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.CPU_TIME_PASSAGE;
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.USER_CPU_TIME_PASSAGE;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+
+import org.jboss.profiler.exp.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(String profilerServiceName) {
+ super(profilerServiceName);
+ initialize();
+ }
+
+ public TimeScaleMetricCollectorFactory(String profilerServiceName, String remoteUrl) {
+ super(profilerServiceName, remoteUrl);
+ 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 +76 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,76 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.exp.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.exp.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(String profilerServiceName) {
+ super(profilerServiceName);
+ initialize();
+ }
+
+ public MemoryMetricCollectorFactory(String profilerServiceName, String remoteUrl) {
+ super(profilerServiceName, remoteUrl);
+ 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 +79 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,79 @@
+/*
+ * 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.agent.collector;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.jboss.profiler.exp.agent.collector.model.MetricName;
+
+/**
+ * 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(Map metricMap);
+
+}
1.1.2.1 +215 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,215 @@
+/*
+ * 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.agent.collector;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.profiler.exp.agent.collector.model.MetricName;
+import org.jboss.profiler.exp.agent.collector.model.ThreadMetric;
+import org.jboss.profiler.exp.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 Map<String, Map<String, Map<MetricName, ThreadMetric>>> metricsMap = null;
+
+ // TODO Remove a external file.
+ private static Map<String, String> IMPLEMENTATION_MAP = new HashMap<String, String>();
+ static {
+ IMPLEMENTATION_MAP.put("org.jboss.resource.adapter.jdbc.WrapperDataSource", "java.sql.DataSource");
+ IMPLEMENTATION_MAP.put("org.jboss.resource.adapter.jdbc.WrappedConnection", "java.sql.Connection");
+ IMPLEMENTATION_MAP.put("org.jboss.resource.adapter.jdbc.WrappedStatement", "java.sql.Statement");
+ IMPLEMENTATION_MAP.put("org.jboss.resource.adapter.jdbc.WrappedPreparedStatement", "java.sql.PreparedStatement");
+ IMPLEMENTATION_MAP.put("org.jboss.resource.adapter.jdbc.WrappedCallableStatement", "java.sql.CallableStatement");
+ IMPLEMENTATION_MAP.put("org.jboss.resource.adapter.jdbc.WrappedResultSet", "java.sql.ResultSet");
+ }
+
+ 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;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setMetricsMap(Map metricMap) {
+ this.metricsMap = metricMap;
+ }
+
+ @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, ThreadMetric> mmap = null;
+ if(metricsMap.containsKey(category)) {
+ Map<String, Map<MetricName, ThreadMetric>> omap = metricsMap.get(category);
+ mmap = omap.get(String.valueOf(threadId));
+ if(mmap==null) {
+ mmap = new EnumMap<MetricName, ThreadMetric>(MetricName.class);
+ omap.put(String.valueOf(threadId), mmap);
+ }
+ }else {
+ mmap = new EnumMap<MetricName, ThreadMetric>(MetricName.class);
+ Map<String, Map<MetricName, ThreadMetric>> omap = new HierarchicalMap<String, Map<MetricName, ThreadMetric>>();
+ omap.put(String.valueOf(threadId), mmap);
+ metricsMap.put(category, omap);
+ }
+ for(Map.Entry<MetricName, Long> localStat : localStats.entrySet()) {
+ MetricName key = localStat.getKey();
+ ThreadMetric metric = 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 = IMPLEMENTATION_MAP.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 JBoss Profiler classes.
+ else if(className.contains("org.jboss.profiler.exp.agent.interceptor")) continue;
+ // Retrieve servlet class.
+ else if(methodName.equals("doGet") || methodName.equals("doPost")) {
+ for(int j=i+1; j<stackTrace.length; j++) {
+ String c = stackTrace[j].getClassName();
+ if(className.equals(c)) continue;
+ else if(c.equals("javax.servlet.http.HttpServlet") || c.equals("javax.servlet.GenericServlet")) {
+ result = "<servlet>";
+ break;
+ }
+ else {
+ result = className+"."+methodName;
+ break;
+ }
+ }
+ break;
+ }else {
+ result = className+"."+methodName;
+ break;
+ }
+ }
+ return result;
+ }
+
+}
1.1.2.1 +108 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,108 @@
+/*
+ * 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.agent.collector;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+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;
+
+/**
+ *
+ * @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 Map<String, Map<String, Map<MetricName, TimeScaleMetric>>> 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);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setMetricsMap(Map metricMap) {
+ this.metricsMap = metricMap;
+ }
+
+ public void run() {
+ Map<MetricName, TimeScaleMetric> mmap = null;
+ if(metricsMap.containsKey(category)) {
+ Map<String, Map<MetricName, TimeScaleMetric>> omap = metricsMap.get(category);
+ mmap = omap.get(operationName);
+ if(mmap==null) {
+ mmap = new EnumMap<MetricName, TimeScaleMetric>(MetricName.class);
+ omap.put(operationName, mmap);
+ }
+ }else {
+ mmap = new EnumMap<MetricName, TimeScaleMetric>(MetricName.class);
+ Map<String, Map<MetricName, TimeScaleMetric>> omap = new HierarchicalMap<String, Map<MetricName, TimeScaleMetric>>();
+ omap.put(operationName, mmap);
+ metricsMap.put(category, omap);
+ }
+ for(Map.Entry<MetricName, Long> localStat : localStats.entrySet()) {
+ MetricName key = localStat.getKey();
+ TimeScaleMetric metric = mmap.get(key);
+ if(metric==null) {
+ metric = new TimeScaleMetric();
+ mmap.put(localStat.getKey(), metric);
+ }
+ metric.update(localStat.getValue(), timestamp);
+ }
+ }
+
+}
1.1.2.1 +87 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,87 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.CPU_TIME;
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.USER_CPU_TIME;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+
+import org.jboss.profiler.exp.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(String profilerServiceName) {
+ super(profilerServiceName);
+ initialize();
+ }
+
+ public ExecutionMetricCollectorFactory(String profilerServiceName, String remoteUrl) {
+ super(profilerServiceName, remoteUrl);
+ 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());
+ }
+ return collector;
+ }
+
+ @Override
+ public void updateCollector(MetricCollector collector) {
+ if(cpuTimeSupported) {
+ setDifference((ScaleMetricCollector)collector, CPU_TIME, threadMXBean.getCurrentThreadCpuTime());
+ setDifference((ScaleMetricCollector)collector, USER_CPU_TIME, threadMXBean.getCurrentThreadUserTime());
+ }
+ }
+
+ private void setDifference(ScaleMetricCollector collector, MetricName name, long value ) {
+ collector.setLocalStat(name, value - collector.getLocalStat(name));
+ }
+
+}
1.1.2.1 +82 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,82 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.exp.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(String profilerServiceName) {
+ super(profilerServiceName);
+ initialize();
+ }
+
+ public StackTraceMetricCollectorFactory(String profilerServiceName, String remoteUrl) {
+ super(profilerServiceName, remoteUrl);
+ 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 +120 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,120 @@
+/*
+ * 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.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.exp.agent.collector.model.MetricName;
+import org.jboss.profiler.exp.agent.collector.model.StackMetric;
+import org.jboss.profiler.exp.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 Map<String, Map<String, Map<MetricName, StackMetric>>> 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);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setMetricsMap(Map metricMap) {
+ this.metricsMap = metricMap;
+ }
+
+ 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, StackMetric> mmap = null;
+ if(metricsMap.containsKey(category)) {
+ Map<String, Map<MetricName, StackMetric>> omap = metricsMap.get(category);
+ mmap = omap.get(operationName);
+ if(mmap==null) {
+ mmap = new EnumMap<MetricName, StackMetric>(MetricName.class);
+ omap.put(operationName, mmap);
+ }
+ }else {
+ mmap = new EnumMap<MetricName, StackMetric>(MetricName.class);
+ Map<String, Map<MetricName, StackMetric>> omap = new HierarchicalMap<String, Map<MetricName, StackMetric>>();
+ omap.put(operationName, mmap);
+ metricsMap.put(category, omap);
+ }
+ for(Map.Entry<MetricName, String[]> localStat : localStats.entrySet()) {
+ MetricName key = localStat.getKey();
+ StackMetric metric = mmap.get(key);
+ if(metric==null) {
+ metric = new StackMetric();
+ mmap.put(localStat.getKey(), metric);
+ }
+ metric.update(localStat.getValue());
+ }
+ }
+
+}
1.1.2.1 +93 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,93 @@
+/*
+ * 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.agent.collector;
+
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.CPU_TIME_PASSAGE_DETAIL;
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.USER_CPU_TIME_PASSAGE_DETAIL;
+import static org.jboss.profiler.exp.agent.collector.model.MetricName.REAL_TIME_PASSAGE_DETAIL;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+import org.jboss.profiler.exp.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(String profilerServiceName) {
+ super(profilerServiceName);
+ initialize();
+ }
+
+ public ThreadMetricCollectorFactory(String profilerServiceName, String remoteUrl) {
+ super(profilerServiceName, remoteUrl);
+ 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 +107 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,107 @@
+/*
+ * 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.agent.collector;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+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;
+
+/**
+ *
+ * @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 Map<String, Map<String, Map<MetricName, ScaleMetric>>> 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);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setMetricsMap(Map metricMap) {
+ this.metricsMap = metricMap;
+ }
+
+ public void run() {
+ Map<MetricName, ScaleMetric> mmap = null;
+ if(metricsMap.containsKey(category)) {
+ Map<String, Map<MetricName, ScaleMetric>> omap = metricsMap.get(category);
+ mmap = omap.get(operationName);
+ if(mmap==null) {
+ mmap = new EnumMap<MetricName, ScaleMetric>(MetricName.class);
+ omap.put(operationName, mmap);
+ }
+ }else {
+ mmap = new EnumMap<MetricName, ScaleMetric>(MetricName.class);
+ Map<String, Map<MetricName, ScaleMetric>> omap = new HierarchicalMap<String, Map<MetricName, ScaleMetric>>();
+ omap.put(operationName, mmap);
+ metricsMap.put(category, omap);
+ }
+ for(Map.Entry<MetricName, Long> localStat : localStats.entrySet()) {
+ MetricName key = localStat.getKey();
+ ScaleMetric metric = mmap.get(key);
+ if(metric==null) {
+ metric = new ScaleMetric();
+ mmap.put(localStat.getKey(), metric);
+ }
+ metric.update(localStat.getValue());
+ }
+ }
+
+}
1.1.2.1 +83 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/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 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,83 @@
+/*
+ * 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.agent.collector;
+
+import org.jboss.profiler.exp.adaptor.ServiceManager;
+import org.jboss.profiler.exp.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 {
+
+ /*
+ * JMX service proxy
+ */
+ private IProfilerService profilerServiceProxy = null;
+
+ /**
+ * Constructs instance and connects to JMX service by local access.
+ * @param profilerServiceName - JMX service name
+ */
+ public MetricCollectorFactory(String profilerServiceName) {
+ profilerServiceProxy = (IProfilerService)ServiceManager.createLocalProxy(profilerServiceName, IProfilerService.class);
+ }
+
+ /**
+ * Constructs instance and connects to JMX service by remote access.
+ * @param profilerServiceName - JMX service name
+ * @param remoteUrl - URL of remote host
+ */
+ public MetricCollectorFactory(String profilerServiceName, String remoteUrl) {
+ profilerServiceProxy = (IProfilerService)ServiceManager.createRemoteProxy(remoteUrl, profilerServiceName, 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 void submitCollector(MetricCollector collector) {
+ profilerServiceProxy.submitMetric(collector);
+ }
+
+}
More information about the jboss-cvs-commits
mailing list