add integration with perf4j

This commit is contained in:
Dmitry Abramov 2009-02-04 10:35:37 +00:00
parent fd14bfce55
commit e87717b5d7
8 changed files with 533 additions and 4 deletions

View File

@ -14,6 +14,7 @@
<ant dir="modules/gui" target="${target}" inheritAll="false"/>
<ant dir="modules/web" target="${target}" inheritAll="false"/>
<ant dir="modules/web-war" target="${target}" inheritAll="false"/>
<ant dir="modules/admin-console-war" target="${target}" inheritAll="false"/>
</target>
<target name="clean">
@ -31,6 +32,7 @@
<ext:install-lib name="commons-io" version="${commons-io.version}" toDir="${lib.common.dir}"/>
<ext:install-jboss-lib name="log4j" version="${jboss.version}" toDir="${lib.common.dir}"/>
<ext:install-lib name="freemarker" version="${freemarker.version}" toDir="${lib.common.dir}"/>
<ext:install-lib name="perf4j" version="${perf4j.version}" toDir="${lib.common.dir}"/>
<!-- server libs -->
<ext:install-lib name="openjpa" version="${openjpa.version}" toDir="${lib.server.dir}"/>
<ext:install-lib name="serp" version="${serp.version}" toDir="${lib.server.dir}"/>

View File

@ -50,6 +50,14 @@
<maximumStackSize value="32" />
<properties />
</buildFile>
<buildFile url="file://$PROJECT_DIR$/modules/admin-console-war/build.xml">
<additionalClassPath />
<antReference projectDefault="true" />
<customJdkName value="" />
<maximumHeapSize value="128" />
<maximumStackSize value="32" />
<properties />
</buildFile>
</component>
<component name="BuildJarProjectSettings">
<option name="BUILD_JARS_ON_MAKE" value="false" />
@ -925,6 +933,7 @@
<component name="ProjectFileVersion" converted="true" />
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/modules/cuba-monitor-war/admin-console-war.iml" filepath="$PROJECT_DIR$/modules/cuba-monitor-war/admin-console-war.iml" />
<module fileurl="file://$PROJECT_DIR$/modules/client/client.iml" filepath="$PROJECT_DIR$/modules/client/client.iml" />
<module fileurl="file://$PROJECT_DIR$/modules/core/core.iml" filepath="$PROJECT_DIR$/modules/core/core.iml" />
<module fileurl="file://$PROJECT_DIR$/modules/gui/gui.iml" filepath="$PROJECT_DIR$/modules/gui/gui.iml" />
@ -1032,6 +1041,7 @@
<root url="jar://$PROJECT_DIR$/../lib/common/reflections-0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/../lib/common/commons-io-1.4.jar!/" />
<root url="jar://$PROJECT_DIR$/../lib/common/freemarker-2.3.15.jar!/" />
<root url="jar://$PROJECT_DIR$/../lib/common/perf4j-0.9.10.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
@ -1039,6 +1049,7 @@
<root url="jar://$PROJECT_DIR$/../lib/common/src/commons-codec-1.3-src.zip!/" />
<root url="jar://$PROJECT_DIR$/../lib/common/src/reflections-0.9-src.zip!/" />
<root url="jar://$PROJECT_DIR$/../lib/common/src/commons-io-1.4-src.zip!/" />
<root url="jar://$PROJECT_DIR$/../lib/common/src/perf4j-0.9.10-src.zip!/" />
</SOURCES>
</library>
<library name="test">

View File

@ -3,6 +3,7 @@ jboss-embedded.version=beta3-sp3-1
commons-codec.version=1.3
commons-io.version=1.4
freemarker.version=2.3.15
perf4j.version=0.9.10
openjpa.version=1.2.0
itmill-toolkit.version=5.2.12
jcifs.version=1.3.2

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" optional="false" version="2.5" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/web" relative="/" />
</webroots>
<building>
<setting name="EXPLODED_URL" value="file://$MODULE_DIR$/../../out/exploded/cuba-monitor-warWeb" />
<setting name="EXPLODED_ENABLED" value="true" />
<setting name="JAR_URL" value="file://" />
<setting name="JAR_ENABLED" value="false" />
<setting name="EXCLUDE_EXPLODED_DIRECTORY" value="true" />
</building>
<packaging>
<containerElement type="module" name="cuba-monitor-war">
<attribute name="method" value="1" />
<attribute name="URI" value="/WEB-INF/classes" />
</containerElement>
</packaging>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/javaee.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="common" level="project" />
</component>
</module>

View File

@ -0,0 +1,46 @@
<?xml version="1.0"?>
<project xmlns:ext="http://haulmont.com/schema/ant"
name="admin-console-war" default="build-module" basedir=".">
<property name="project.dir" location="../.."/>
<property name="root.dir" location="${project.dir}/.."/>
<property name="module.name" value="admin-console-war"/>
<property name="module.jar" value="29admin-console.war"/>
<import file="${root.dir}/build-inc-mod.xml"/>
<property file="${root.dir}/build.properties"/>
<property file="${project.dir}/lib.properties"/>
<property name="web.src.dir" location="${module.dir}/web"/>
<path id="compile-cp">
<fileset refid="common-lib-fs"/>
<fileset refid="server-lib-fs"/>
<pathelement location="${prod.out.dir}/core"/>
</path>
<path id="test-compile-cp">
<fileset refid="common-lib-fs"/>
<fileset refid="server-lib-fs"/>
</path>
<target name="clean-module" depends="base-mod.clean-module">
<delete dir="${build.dir}/${module.name}"/>
</target>
<target name="build-module">
<echo>==> building ${project.dir} ${module.name}</echo>
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.dir}/${module.name}"/>
<copy todir="${build.dir}/${module.name}">
<fileset dir="${web.src.dir}" includes="**/*"/>
</copy>
<jar basedir="${build.dir}/${module.name}" destfile="${build.dir}/${module.jar}"/>
</target>
<target name="deploy-module" depends="undeploy-module, base-mod.deploy-module"/>
</project>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>perf4j</servlet-name>
<servlet-class>org.perf4j.log4j.servlet.GraphingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>perf4j</servlet-name>
<url-pattern>/performance-statistic</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,389 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id$ -->
<!--
| For more configuration information and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<!--
Set the threshold via a system property. Note this is parsed by log4j,
so the full JBoss system property format is not supported; e.g.
setting a default via ${jboss.server.log.threshold:WARN} will not work.
-->
<param name="Threshold" value="${jboss.server.log.threshold}"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<!-- Rollover at the top of each hour
<param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
-->
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] (Thread) Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
<!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A size based file rolling appender
<appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
-->
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<!-- ====================== -->
<!-- More Appender examples -->
<!-- ====================== -->
<!-- Buffer events and log them asynchronously
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="SMTP"/>
</appender>
-->
<!-- EMail events to an administrator
<appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Threshold" value="ERROR"/>
<param name="To" value="admin@myhost.domain.com"/>
<param name="From" value="nobody@myhost.domain.com"/>
<param name="Subject" value="JBoss Sever Errors"/>
<param name="SMTPHost" value="localhost"/>
<param name="BufferSize" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
</layout>
</appender>
-->
<!-- Syslog events
<appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Facility" value="LOCAL7"/>
<param name="FacilityPrinting" value="true"/>
<param name="SyslogHost" value="localhost"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
</layout>
</appender>
-->
<!-- Log events to JMS (requires a topic to be created)
<appender name="JMS" class="org.apache.log4j.net.JMSAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Threshold" value="ERROR"/>
<param name="TopicConnectionFactoryBindingName" value="java:/ConnectionFactory"/>
<param name="TopicBindingName" value="topic/MyErrorsTopic"/>
</appender>
-->
<!-- Log events through SNMP
<appender name="TRAP_LOG" class="org.apache.log4j.ext.SNMPTrapAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="ImplementationClassName" value="org.apache.log4j.ext.JoeSNMPTrapSender"/>
<param name="ManagementHost" value="127.0.0.1"/>
<param name="ManagementHostTrapListenPort" value="162"/>
<param name="EnterpriseOID" value="1.3.6.1.4.1.24.0"/>
<param name="LocalIPAddress" value="127.0.0.1"/>
<param name="LocalTrapSendPort" value="161"/>
<param name="GenericTrapType" value="6"/>
<param name="SpecificTrapType" value="12345678"/>
<param name="CommunityString" value="public"/>
<param name="ForwardStackTraceWithTrap" value="true"/>
<param name="Threshold" value="DEBUG"/>
<param name="ApplicationTrapOID" value="1.3.6.1.4.1.24.12.10.22.64"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d,%p,[%t],[%c],%m%n"/>
</layout>
</appender>
-->
<!-- Emit events as JMX notifications
<appender name="JMX" class="org.jboss.monitor.services.JMXNotificationAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Threshold" value="WARN"/>
<param name="ObjectName" value="jboss.system:service=Logging,type=JMXNotificationAppender"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m"/>
</layout>
</appender>
-->
<!-- Security AUDIT Appender
<appender name="AUDIT" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/audit.log"/>
<param name="Append" value="true"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t:%x) %m%n"/>
</layout>
</appender>
-->
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<!-- Begin Cuba categories -->
<category name="com.haulmont.cuba.web.App">
<priority value="TRACE"/>
</category>
<!-- End Cuba categories -->
<!-- Limit the org.apache category to INFO as its DEBUG is verbose -->
<category name="org.apache">
<priority value="INFO"/>
</category>
<!-- Limit JSF logging to DEBUG. FINER and FINEST will not be logged -->
<category name="javax.enterprise.resource.webcontainer.jsf">
<priority value="INFO" />
</category>
<!-- Limit the jacorb category to WARN as its INFO is verbose -->
<category name="jacorb">
<priority value="WARN"/>
</category>
<!-- Set the logging level of the JSF implementation -->
<category name="javax.enterprise.resource.webcontainer.jsf">
<priority value="INFO" />
</category>
<!-- Limit the org.jgroups category to WARN as its INFO is verbose -->
<category name="org.jgroups">
<priority value="WARN"/>
</category>
<!-- Limit the org.quartz category to INFO as its DEBUG is verbose -->
<category name="org.quartz">
<priority value="INFO"/>
</category>
<!-- Limit JBoss categories -->
<category name="org.jboss">
<priority value="INFO"/>
</category>
<category name="com.arjuna">
<priority value="INFO"/>
</category>
<!-- Limit the JSR77 categories -->
<category name="org.jboss.management">
<priority value="INFO"/>
</category>
<!-- Show the evolution of the DataSource pool in the logs [inUse/Available/Max]
<category name="org.jboss.resource.connectionmanager.JBossManagedConnectionPool">
<priority value="TRACE"/>
</category>
-->
<!-- Category specifically for Security Audit Provider
<category name="org.jboss.security.audit.providers.LogAuditProvider" additivity="false">
<priority value="TRACE"/>
<appender-ref ref="AUDIT"/>
</category>
-->
<!-- Limit the org.jboss.serial (jboss-serialization) to INFO as its DEBUG is verbose -->
<category name="org.jboss.serial">
<priority value="INFO"/>
</category>
<!-- Decrease the priority threshold for the org.jboss.varia category
<category name="org.jboss.varia">
<priority value="DEBUG"/>
</category>
-->
<!-- Enable JBossWS message tracing
<category name="org.jboss.ws.core.MessageTrace">
<priority value="TRACE"/>
</category>
-->
<!--
| An example of enabling the custom TRACE level priority that is used
| by the JBoss internals to diagnose low level details. This example
| turns on TRACE level msgs for the org.jboss.ejb.plugins package and its
| subpackages. This will produce A LOT of logging output.
|
| Note: since jboss AS 4.2.x, the trace level is supported natively by
| log4j, so although the custom org.jboss.logging.XLevel priority will
| still work, there is no need to use it. The two examples that follow
| will both enable trace logging.
<category name="org.jboss.system">
<priority value="TRACE" class="org.jboss.logging.XLevel"/>
</category>
<category name="org.jboss.ejb.plugins">
<priority value="TRACE"/>
</category>
-->
<!--
| Logs these events to SNMP:
- server starts/stops
- cluster evolution (node death/startup)
- When an EJB archive is deployed (and associated verified messages)
- When an EAR archive is deployed
<category name="org.jboss.system.server.Server">
<priority value="INFO" />
<appender-ref ref="TRAP_LOG"/>
</category>
<category name="org.jboss.ha.framework.interfaces.HAPartition.lifecycle">
<priority value="INFO" />
<appender-ref ref="TRAP_LOG"/>
</category>
<category name="org.jboss.deployment.MainDeployer">
<priority value="ERROR" />
<appender-ref ref="TRAP_LOG"/>
</category>
<category name="org.jboss.ejb.EJBDeployer">
<priority value="INFO" />
<appender-ref ref="TRAP_LOG"/>
</category>
<category name="org.jboss.deployment.EARDeployer">
<priority value="INFO" />
<appender-ref ref="TRAP_LOG"/>
</category>
-->
<!-- Clustering logging -->
<!-- Uncomment the following to redirect the org.jgroups and
org.jboss.ha categories to a cluster.log file.
<appender name="CLUSTER" class="org.jboss.logging.appender.RollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/cluster.log"/>
<param name="Append" value="false"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<category name="org.jgroups">
<priority value="DEBUG" />
<appender-ref ref="CLUSTER"/>
</category>
<category name="org.jboss.ha">
<priority value="DEBUG" />
<appender-ref ref="CLUSTER"/>
</category>
-->
<!-- Perf4J appenders -->
<!--
This AsyncCoalescingStatisticsAppender groups StopWatch log messages
into GroupedTimingStatistics messages which it sends on the
file appender defined below
-->
<appender name="CoalescingStatistics" class="org.perf4j.log4j.AsyncCoalescingStatisticsAppender">
<param name="TimeSlice" value="10000"/>
<appender-ref ref="fileAppender"/>
<appender-ref ref="giuCreateWindowTiming"/>
</appender>
<appender name="fileAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="${jboss.server.log.dir}/perfStats.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<appender name="giuCreateWindowTiming" class="org.perf4j.log4j.GraphingStatisticsAppender">
<!-- Possible GraphTypes are Mean, Min, Max, StdDev, Count and TPS -->
<param name="GraphType" value="Mean"/>
<!-- The tags of the timed execution blocks to graph are specified here -->
<param name="TagNamesToGraph" value="WindowManager.createWindow"/>
<appender-ref ref="graphsFileAppender"/>
</appender>
<appender name="graphsFileAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="${jboss.server.log.dir}/perfGraphs.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<!-- Loggers -->
<logger name="org.perf4j.TimingLogger" additivity="false">
<level value="INFO"/>
<appender-ref ref="CoalescingStatistics"/>
</logger>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>

View File

@ -22,22 +22,24 @@ import com.haulmont.cuba.gui.xml.data.DsContextLoader;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.perf4j.StopWatch;
import org.perf4j.log4j.Log4JStopWatch;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class WindowManager {
public enum OpenType {
@ -47,17 +49,32 @@ public abstract class WindowManager {
}
protected Window createWindow(String template, Map params, LayoutLoaderConfig layoutConfig) {
StopWatch stopWatch = new Log4JStopWatch("WindowManager.createWindow");
StopWatch parseDescriptorStopWatch = new Log4JStopWatch("WindowManager.createWindow (parseDescriptor)");
Document document = parseDescriptor(template, params, true);
parseDescriptorStopWatch.stop();
final Element element = document.getRootElement();
StopWatch deployViewsStopWatch = new Log4JStopWatch("WindowManager.createWindow (deployViews)");
deployViews(document);
deployViewsStopWatch.stop();
StopWatch loadDsContextStopWatch = new Log4JStopWatch("WindowManager.createWindow (loadDsContext)");
final DsContext dsContext = loadDsContext(element);
loadDsContextStopWatch.stop();
StopWatch loadLayoutStopWatch = new Log4JStopWatch("WindowManager.createWindow (loadLayout)");
final Window window = loadLayout(element, dsContext, layoutConfig);
loadLayoutStopWatch.stop();
initialize(window, dsContext, params);
return wrapByCustomClass(window, element);
final Window wrapedWindow = wrapByCustomClass(window, element);
stopWatch.stop();
return wrapedWindow;
}
protected void deployViews(Document document) {