This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 0a8ecddf8c10742477b1947864044e0a2884ae85 Author: Juan Pablo Santos RodrÃguez <[email protected]> AuthorDate: Sun Apr 24 16:31:06 2022 +0200 Add memory profiling test, and the needed infraestructure to run it --- jspwiki-main/pom.xml | 6 ++ .../test/java/org/apache/wiki/MemoryProfiling.java | 80 ++++++++++++++++++++++ mvn_cheat-sheet.md | 1 + pom.xml | 45 +++++++++++- 4 files changed, 131 insertions(+), 1 deletion(-) diff --git a/jspwiki-main/pom.xml b/jspwiki-main/pom.xml index 00ac75fed..0ee3ac591 100644 --- a/jspwiki-main/pom.xml +++ b/jspwiki-main/pom.xml @@ -187,6 +187,12 @@ <scope>provided</scope> </dependency> + <dependency> + <groupId>com.github.jbellis</groupId> + <artifactId>jamm</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>net.sourceforge.stripes</groupId> <artifactId>stripes</artifactId> diff --git a/jspwiki-main/src/test/java/org/apache/wiki/MemoryProfiling.java b/jspwiki-main/src/test/java/org/apache/wiki/MemoryProfiling.java new file mode 100644 index 000000000..756ea355e --- /dev/null +++ b/jspwiki-main/src/test/java/org/apache/wiki/MemoryProfiling.java @@ -0,0 +1,80 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki; + +import org.apache.wiki.api.core.Acl; +import org.apache.wiki.api.core.AclEntry; +import org.apache.wiki.api.core.Attachment; +import org.apache.wiki.api.core.Engine; +import org.apache.wiki.api.core.Page; +import org.apache.wiki.api.core.Session; +import org.apache.wiki.api.spi.Wiki; +import org.github.jamm.MemoryMeter; +import org.junit.jupiter.api.Test; + +import java.util.Properties; + +/** + * Some memory profiling checks. Needs jamm java agent set as jvm arg to run. This can be enabled manually (adding + * {@code -javaagent=path-to-jamm.jar} as jvm arg when launching this test) or through the mem-profiling maven profile + * ({@code mvn test -Dtest=MemoryProfiling}). + * + * note this deactivates other javaagents like f.ex., jacoco. + */ +class MemoryProfiling { + + @Test + void memorySize() { + final Properties props = TestEngine.getTestProperties(); + props.put( "jspwiki.fileSystemProvider.pageDir", "../jspwiki-wikipages/en/src/main/resources" ); + final Engine engine = Wiki.engine().find( TestEngine.createServletContext( "/test" ), TestEngine.getTestProperties() ); + final Engine engineWithDefaultPages = Wiki.engine().find( TestEngine.createServletContext( "/test" ), props ); + final Page main = Wiki.contents().page( engine, "Main" ); + final Attachment att = Wiki.contents().attachment( engine, "Main", "file" ); + final Session session = Wiki.session().guest( engine ); + final Acl acl = Wiki.acls().acl(); + final AclEntry aclEntry = Wiki.acls().entry(); + + final MemoryMeter meter = new MemoryMeter(); + final long engineBytes = meter.measureDeep( engine ); + final long engineWithDefaultPagesBytes = meter.measureDeep( engineWithDefaultPages ); + final long mainBytes = meter.measureDeep( main ); + final long attBytes = meter.measureDeep( att ); + final long sessionBytes = meter.measureDeep( session ); + final long aclBytes = meter.measureDeep( acl ); + final long aclEntryBytes = meter.measureDeep( aclEntry ); + + System.out.println( "" ); + System.out.println( "===========================================================================================" ); + System.out.println( "Plain Engine, without pages/attachments, search indexes, references, etc.: " + format( engineBytes ) ); + System.out.println( "Engine, with default set of wiki pages: .................................. " + format( engineWithDefaultPagesBytes ) ); + System.out.println( "Page: .................................................................... " + format( mainBytes - engineBytes) ); + System.out.println( "Attachment: .............................................................. " + format( attBytes - engineBytes ) ); + System.out.println( "Guest session on plain engine: ........................................... " + format( sessionBytes - engineBytes ) ); + System.out.println( "Acl: ..................................................................... " + format( aclBytes ) ); + System.out.println( "Acl entry: ............................................................... " + format( aclEntryBytes ) ); + System.out.println( "-------------------------------------------------------------------------------------------" ); + System.out.println( "" ); + } + + String format( final long bytes ) { + return String.format( "%,10d bytes", bytes ); + } + +} diff --git a/mvn_cheat-sheet.md b/mvn_cheat-sheet.md index 19592e192..a5a4c7dc5 100644 --- a/mvn_cheat-sheet.md +++ b/mvn_cheat-sheet.md @@ -42,6 +42,7 @@ under the License. | mvn wro4j:run -Dminimize=false | only merge the js & css files (no compression) | | mvn clean install -Dmaven.test.skip -Dminimize=false | performs a build, skipping the tests and skip compression | | mvn clean install -Dgenerate-native-launchers=true | (from portable module) performs a build, regenerating the native executables on the portable build | +| mvn test -Dtest=MemoryProfiling | (from jspwiki-main module) runs a memory profiling test | (1) `-T 1C` can be added to any of these commands in order to run a parallel build, thus decreasing build time, i.e., `mvn clean install -T 1C`. diff --git a/pom.xml b/pom.xml index 2f84d7288..c2d0e7de2 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ <freshcookies-security.version>0.60</freshcookies-security.version> <gson.version>2.9.0</gson.version> <hsqldb.version>2.6.1</hsqldb.version> + <jamm.version>0.3.3</jamm.version> <jaxen.version>1.2.0</jaxen.version> <javax-jstl.version>1.2</javax-jstl.version> <javax-mail.version>1.4.7</javax-mail.version> @@ -396,6 +397,12 @@ <version>${stripes.version}</version> </dependency> + <dependency> + <groupId>com.github.jbellis</groupId> + <artifactId>jamm</artifactId> + <version>${jamm.version}</version> + </dependency> + <dependency> <groupId>org.awaitility</groupId> <artifactId>awaitility</artifactId> @@ -921,7 +928,6 @@ <id>attach-additional-artifacts</id> <activation> - <activeByDefault>false</activeByDefault> <property> <name>additional_artifacts</name> <value>true</value> @@ -958,6 +964,43 @@ </plugins> </build> </profile> + + <profile> <!-- enable memory profiling --> + <id>mem-profiling</id> + + <activation> + <property> + <name>test</name> + <value>MemoryProfiling</value> + </property> + </activation> + + <build> + <plugins> + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>dependencies-as-properties</id> + <goals><goal>properties</goal></goals> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>-javaagent:${com.github.jbellis:jamm:jar}</argLine> + <consoleOutputReporter> + <disable>false</disable> + </consoleOutputReporter> + <reportFormat>plain</reportFormat> + <statelessTestsetInfoReporter combine.self="override"/> + </configuration> + </plugin> + </plugins> + </build> + </profile> </profiles> <organization>
