Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include project name in lifecycle phase summary #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ steps:
mount:
- .repo

- name: mavenjdk8
- name: mavenjdk11
pull: always
image: docker.io/maven:3.8.4-openjdk-11-slim
volumes:
Expand Down
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
21 changes: 5 additions & 16 deletions src/main/java/com/soebes/maven/extensions/MojoTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.soebes.maven.extensions.MojoKey.fromMojo;

/**
* @author Karl Heinz Marbaise <a href="mailto:[email protected]">[email protected]</a>
*/
Expand All @@ -44,17 +46,6 @@ public MojoTimer()
this.timerEvents = new ConcurrentHashMap<>();
}

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

private MojoKey createMojoKey( MojoExecution mojo )
{
return new MojoKey( mojo.getGroupId(), mojo.getArtifactId(), mojo.getVersion(), mojo.getGoal(),
mojo.getExecutionId(), mojo.getLifecyclePhase() );
}

public boolean hasEvents()
{
return !this.timerEvents.isEmpty();
Expand All @@ -63,15 +54,13 @@ public boolean hasEvents()
public void mojoStart( ExecutionEvent event )
{

ProjectMojo pm =
new ProjectMojo( createProjectKey( event.getProject() ), createMojoKey( event.getMojoExecution() ) );
ProjectMojo pm = new ProjectMojo( event.getProject(), fromMojo( event.getMojoExecution() ) );
timerEvents.put( pm, new SystemTime().start() );
}

public void mojoStop( ExecutionEvent event )
{
ProjectMojo pm =
new ProjectMojo( createProjectKey( event.getProject() ), createMojoKey( event.getMojoExecution() ) );
ProjectMojo pm = new ProjectMojo( event.getProject(), fromMojo( event.getMojoExecution() ) );
if ( !timerEvents.containsKey( pm ) )
{
throw new IllegalArgumentException( "Unknown mojoId (" + pm + ")" );
Expand Down Expand Up @@ -139,7 +128,7 @@ public void report()
{
for ( Entry<ProjectMojo, SystemTime> item : this.timerEvents.entrySet() )
{
LOGGER.info( "{} : {}", item.getKey().getId(), item.getValue().getElapsedTime() );
LOGGER.info( "{} : {}", item.getKey().getFullId(), item.getValue().getElapsedTime() );
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/soebes/maven/extensions/ProjectKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* under the License.
*/

import org.apache.maven.project.MavenProject;

/**
* @author Karl Heinz Marbaise <a href="mailto:[email protected]">[email protected]</a>
*/
Expand All @@ -30,6 +32,10 @@ class ProjectKey

private final String version;

public static ProjectKey fromMavenProject(MavenProject project) {
return new ProjectKey(project.getGroupId(), project.getArtifactId(), project.getVersion());
}

public ProjectKey( final String groupId, final String artifactId, final String version )
{
super();
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/com/soebes/maven/extensions/ProjectMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@
* under the License.
*/

import org.apache.maven.project.MavenProject;

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

/**
* @author Karl Heinz Marbaise <a href="mailto:[email protected]">[email protected]</a>
*/
class ProjectMojo
{
private ProjectKey project;

private String projectName;

private MojoKey mojo;

public ProjectMojo( ProjectKey project, MojoKey mojo )
public ProjectMojo( MavenProject project, MojoKey mojo )
{
super();
this.project = project;
this.project = fromMavenProject( project );
this.projectName = project.getName();
this.mojo = mojo;
}

Expand Down Expand Up @@ -65,12 +72,14 @@ public int hashCode()
return result;
}

public String getId()
public String getLifecycleId()
{
return projectName + "@" + mojo.getFullId();
}

public String getFullId()
{
String s1 = getMojo().getGroupId() + ":" + getMojo().getArtifactId() + ":" + getMojo().getVersion() + ":"
+ getMojo().getGoal() + " (" + getMojo().getExecutionId() + ":" + getMojo().getPhase() + ")";
String s2 = getProject().getGroupId() + ":" + getProject().getArtifactId() + ":" + getProject().getVersion();
return s1 + " @ " + s2;
return mojo.getFullIdWithPhase() + " @ " + project.getId();
}

@Override
Expand Down