Skip to content

Commit

Permalink
Include project name in lifecycle phase summary
Browse files Browse the repository at this point in the history
For multi-module projects there is currently no indication of which project caused a particular mojo execution. This is an alternate solution to #4.

Current output:
```
[INFO] generate-sources:
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]     3247 ms: com.twitter:scrooge-maven-plugin:20.1.0:compile:thrift-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]     1703 ms: com.twitter:scrooge-maven-plugin:20.1.0:compile:thrift-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]      132 ms: com.twitter:scrooge-maven-plugin:20.1.0:compile:thrift-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        2 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]      303 ms: com.twitter:scrooge-maven-plugin:20.1.0:compile:thrift-sources
[INFO]      531 ms: org.antlr:antlr4-maven-plugin:4.9.3:antlr4:antlr
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]     1423 ms: org.antlr:antlr4-maven-plugin:4.9.3:antlr4:antlr
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]      117 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]     1987 ms: org.antlr:antlr4-maven-plugin:4.9.3:antlr4:antlr
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        1 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
[INFO]        0 ms: org.codehaus.mojo:build-helper-maven-plugin:3.3.0:add-source:add-antlr-sources
```

New output:
```
[INFO] Plugins in lifecycle Phases:
[INFO]
[INFO] clean:
[INFO]      126 ms : Maven :: Build Time [email protected]:maven-clean-plugin:3.1.0:clean (default-clean)
[INFO] validate:
[INFO]      145 ms : Maven :: Build Time [email protected]:maven-enforcer-plugin:3.0.0:enforce (enforce-maven)
[INFO] initialize:
[INFO]       85 ms : Maven :: Build Time [email protected]:jacoco-maven-plugin:0.8.8:prepare-agent (default)
[INFO] generate-sources:
[INFO]      137 ms : Maven :: Build Time [email protected]:templating-maven-plugin:1.0.0:filter-sources (default)
[INFO] process-resources:
[INFO]       74 ms : Maven :: Build Time [email protected]:maven-resources-plugin:3.2.0:resources (default-resources)
[INFO] compile:
[INFO]      837 ms : Maven :: Build Time [email protected]:maven-compiler-plugin:3.10.0:compile (default-compile)
[INFO] process-classes:
[INFO]       54 ms : Maven :: Build Time [email protected]:sisu-maven-plugin:1.1:main-index (generate-index)
[INFO] process-test-resources:
[INFO]        2 ms : Maven :: Build Time [email protected]:maven-resources-plugin:3.2.0:testResources (default-testResources)
[INFO] test-compile:
[INFO]      278 ms : Maven :: Build Time [email protected]:maven-compiler-plugin:3.10.0:testCompile (default-testCompile)
[INFO] test:
[INFO]     3117 ms : Maven :: Build Time [email protected]:maven-surefire-plugin:3.0.0-M6:test (default-test)
[INFO] package:
[INFO]      504 ms : Maven :: Build Time [email protected]:maven-site-plugin:3.11.0:attach-descriptor (attach-descriptor)
[INFO]       89 ms : Maven :: Build Time [email protected]:maven-shade-plugin:3.3.0:shade (default)
[INFO]      267 ms : Maven :: Build Time [email protected]:maven-jar-plugin:3.2.2:jar (default-jar)
[INFO] verify:
[INFO]      228 ms : Maven :: Build Time [email protected]:jacoco-maven-plugin:0.8.8:report (default)
[INFO] install:
[INFO]       67 ms : Maven :: Build Time [email protected]:maven-install-plugin:3.0.0-M1:install (default-install)
```
  • Loading branch information
clayreimann committed May 19, 2022
1 parent 02be61c commit 3e6d4c7
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 79 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/jdkbuilds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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.
#
name: JDKBuilds

on:
push:
branches:
- master
- '*'
pull_request:
branches:
- '*'

jobs:
openjdk:
strategy:
matrix:
jdk: [jdk-8-slim, jdk-11-slim, openjdk-17]
name: "OpenJDK ${{ matrix.jdk }}"
runs-on: ubuntu-latest
container: "maven:3.8.4-${{ matrix.jdk }}"
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ matrix.jdk }}-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-${{ matrix.jdk }}
- name: 'Build'
run: mvn -V --no-transfer-progress clean verify --fail-at-end
74 changes: 74 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 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.
#
name: Main
on:
push:
branches:
- master
- '*'
pull_request:
branches:
- '*'

jobs:
linux:
name: Linux
runs-on: ubuntu-latest
container: "maven:3.8.4-jdk-8-slim"
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-ubuntu-latest-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-ubuntu-latest
- name: 'Build'
run: mvn -V --no-transfer-progress clean verify --fail-at-end
windows:
name: 'Windows'
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-windows-latest-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-windows-latest
- name: 'Set up JDK 8'
uses: actions/setup-java@v1
with:
java-version: 8
- name: 'Build'
shell: bash
run: mvn -V --no-transfer-progress clean verify --fail-at-end
mac:
name: 'Mac OS'
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-macos-latest-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-macos-latest
- name: 'Set up JDK 8'
uses: actions/setup-java@v1
with:
java-version: 8
- name: 'Build'
run: mvn -V --no-transfer-progress clean verify --fail-at-end
114 changes: 66 additions & 48 deletions src/main/java/com/soebes/maven/extensions/BuildTimeProfiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

import javax.inject.Named;
import javax.inject.Singleton;
Expand All @@ -47,6 +49,8 @@
import com.soebes.maven.extensions.metadata.MetadataDownloadTimer;
import com.soebes.maven.extensions.metadata.MetadataInstallTimer;

import static com.soebes.maven.extensions.ProjectKey.fromMavenProject;

/**
* @author Karl Heinz Marbaise <a href="mailto:[email protected]">[email protected]</a>
*/
Expand All @@ -57,6 +61,8 @@ public class BuildTimeProfiler
{
private static final Logger LOGGER = LoggerFactory.getLogger(BuildTimeProfiler.class);

private static final String DIVIDER = "------------------------------------------------------------------------";

final List<String> lifeCyclePhases;

private final DiscoveryTimer discoveryTimer;
Expand Down Expand Up @@ -397,67 +403,29 @@ private void executionResultEventHandler( MavenExecutionResult event )
LOGGER.debug( "MBTP: executionResultEventHandler: {}", event.getProject() );

LOGGER.info( "-- Maven Build Time Profiler Summary --" );
LOGGER.info( "------------------------------------------------------------------------" );
LOGGER.info(DIVIDER);

discoveryTimer.report();

if ( mojoTimer.hasEvents() )
{
LOGGER.info( "Project Build Time (reactor order):" );
LOGGER.info( "" );
for ( MavenProject mavenProject : event.getTopologicallySortedProjects() )
{
LOGGER.info( "{}:", mavenProject.getName() );

for ( String phase : lifeCyclePhases )
{
ProjectKey projectKey = mavenProjectToProjectKey( mavenProject );

if ( !mojoTimer.hasTimeForProjectAndPhase( projectKey, phase ) )
{
continue;
}
logProjects(event);
LOGGER.info(DIVIDER);

long timeForPhaseAndProjectInMillis =
mojoTimer.getTimeForProjectAndPhaseInMillis( projectKey, phase );
LOGGER.info( " {} ms : {}", String.format( "%8d", timeForPhaseAndProjectInMillis ), phase );

}

}
LOGGER.info( "------------------------------------------------------------------------" );
LOGGER.info( "Lifecycle Phase summary:" );
LOGGER.info( "" );
for ( String phase : lifeCyclePhases )
{
long timeForPhaseInMillis = mojoTimer.getTimeForPhaseInMillis( phase );
LOGGER.info( "{} ms : {}", String.format( "%8d", timeForPhaseInMillis ), phase );
}
logPhaseSummary();
LOGGER.info(DIVIDER);

// List all plugins per phase
LOGGER.info( "------------------------------------------------------------------------" );
LOGGER.info( "Plugins in lifecycle Phases:" );
LOGGER.info( "" );
for ( String phase : lifeCyclePhases )
{
LOGGER.info( "{}:", phase );
Map<ProjectMojo, SystemTime> plugisInPhase = mojoTimer.getPluginsInPhase( phase );
for ( Entry<ProjectMojo, SystemTime> pluginInPhase : plugisInPhase.entrySet() )
{
LOGGER.info( "{} ms: {}", String.format( "%8d", pluginInPhase.getValue().getElapsedTime() ),
pluginInPhase.getKey().getMojo().getFullId() );
}

}
LOGGER.info( "------------------------------------------------------------------------" );
logDetailedPhaseExecutions();
LOGGER.info(DIVIDER);
}

if ( goalTimer.hasEvents() )
{
LOGGER.info( "Plugins directly called via goals:" );
LOGGER.info( "" );
goalTimer.report();
LOGGER.info( "------------------------------------------------------------------------" );
LOGGER.info(DIVIDER);
}

installTimer.report();
Expand All @@ -471,9 +439,59 @@ private void executionResultEventHandler( MavenExecutionResult event )
forkProject.report();
}

private ProjectKey mavenProjectToProjectKey( MavenProject project )

private void logProjects(MavenExecutionResult event)
{
LOGGER.info( "Project Build Time (reactor order):" );
LOGGER.info( "" );
for ( MavenProject mavenProject : event.getTopologicallySortedProjects() )
{
LOGGER.info( "{}:", mavenProject.getName() );

for ( String phase : lifeCyclePhases )
{
ProjectKey projectKey = fromMavenProject( mavenProject );

if ( !mojoTimer.hasTimeForProjectAndPhase( projectKey, phase ) )
{
continue;
}

logTime( mojoTimer.getTimeForProjectAndPhaseInMillis( projectKey, phase ), phase );
}

}
}

private void logPhaseSummary()
{
LOGGER.info( "Lifecycle Phase summary:" );
LOGGER.info( "" );
for ( String phase : lifeCyclePhases )
{
logTime( mojoTimer.getTimeForPhaseInMillis( phase ), phase );
}
}

private void logDetailedPhaseExecutions()
{
LOGGER.info( "Plugins in lifecycle Phases:" );
LOGGER.info( "" );
for ( String phase : lifeCyclePhases )
{
LOGGER.info( "{}:", phase );
Map<ProjectMojo, SystemTime> plugisInPhase = mojoTimer.getPluginsInPhase( phase );
for ( Entry<ProjectMojo, SystemTime> pluginInPhase : plugisInPhase.entrySet() )
{
logTime( pluginInPhase.getValue().getElapsedTime(), pluginInPhase.getKey().getLifecycleId() );
}

}
}

private void logTime(long millis, String label)
{
return new ProjectKey( project.getGroupId(), project.getArtifactId(), project.getVersion() );
LOGGER.info( "{} ms : {}", String.format( "%8d", millis ), label );
}

private void collectAllLifeCylcePhases( String phase )
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/soebes/maven/extensions/GoalTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.soebes.maven.extensions.ProjectKey.fromMavenProject;

/**
* @author Karl Heinz Marbaise <a href="mailto:[email protected]">[email protected]</a>
*/
Expand All @@ -29,11 +30,6 @@ public boolean hasEvents()
return !timerEvents.isEmpty();
}

private ProjectKey createProjectKey( MavenProject project )
{
return new ProjectKey( project.getGroupId(), project.getArtifactId(), project.getVersion() );
}

private GoalKey createGoalKey( MojoExecution mojo )
{
return new GoalKey( mojo.getGroupId(), mojo.getArtifactId(), mojo.getVersion(), mojo.getGoal(),
Expand All @@ -43,14 +39,14 @@ private GoalKey createGoalKey( MojoExecution mojo )
public void mojoStart( ExecutionEvent event )
{
ProjectGoal pm =
new ProjectGoal( createProjectKey( event.getProject() ), createGoalKey( event.getMojoExecution() ) );
new ProjectGoal( fromMavenProject(event.getProject()), createGoalKey(event.getMojoExecution() ) );
timerEvents.put( pm, new SystemTime().start() );
}

public void mojoStop( ExecutionEvent event )
{
ProjectGoal pm =
new ProjectGoal( createProjectKey( event.getProject() ), createGoalKey( event.getMojoExecution() ) );
new ProjectGoal( fromMavenProject(event.getProject()), createGoalKey(event.getMojoExecution() ) );
if ( !timerEvents.containsKey( pm ) )
{
throw new IllegalArgumentException( "Unknown mojoId (" + pm.getId() + ")" );
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/soebes/maven/extensions/MojoKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* under the License.
*/

import org.apache.maven.plugin.MojoExecution;

/**
* @author Karl Heinz Marbaise <a href="mailto:[email protected]">[email protected]</a>
*/
Expand All @@ -31,6 +33,11 @@ class MojoKey

private String phase;

public static MojoKey fromMojo(MojoExecution mojo) {
return new MojoKey( mojo.getGroupId(), mojo.getArtifactId(), mojo.getVersion(), mojo.getGoal(),
mojo.getExecutionId(), mojo.getLifecyclePhase() );
}

public MojoKey( String groupId, String artifactId, String version, String goal, String executionId,
String lifeCyclePhase )
{
Expand Down Expand Up @@ -75,6 +82,11 @@ public String getFullId()
return super.getId() + ":" + getGoal() + " (" + getExecutionId() + ")";
}

public String getFullIdWithPhase()
{
return super.getId() + ":" + getGoal() + " (" + getExecutionId() + ":" + getPhase() + ")";
}

@Override
public int hashCode()
{
Expand Down
Loading

0 comments on commit 3e6d4c7

Please sign in to comment.