jcgay/maven-profiler

Provide / describe a way to extend the output

laeubi opened this issue · 7 comments

Sometimes mojos are performing some sub-task that would be good to appear at the reports.

Is this already possible? If yes it would be nice to document this.
If not, would it be possible to have some kind of custom events to listen to?

jcgay commented

This extension provides a org.apache.maven.eventspy.EventSpy custom implementation.
You can listen to events triggered by Maven execution.

If you're trying to observe specific things done by a mojo, it seems unlikely that the mojo will triggered an event.

You can try do track all the execution of fr.jcgay.maven.profiler.ProfilerEventSpy#onEvent within your build to see if an interesting event comes up but it seems to be a long shot 😇

It should be possible to implements custom events but it implies that a mojo uses org.apache.maven.eventspy.internal.EventSpyDispatcher which lives in an internal package 😅.

If you're trying to observe specific things done by a mojo, it seems unlikely that the mojo will triggered an event.

Just say I have full control over the mojo code could the mojo emit events that are understood by maven-profiler?

org.apache.maven.eventspy.internal.EventSpyDispatcher which lives in an internal package

Thanks for the hint, even though its internal I won't mind using that, do you think maven-profiler could define some kind of custom event that could be used for such purpose?

Another way I could think of would be that maven-profiler provides a (public) component where one could send events directly?

For example ProfilerEventSpy could have a method recordStart(String name) and recordStop(String name) methods or similar where name is used as an identifier?

jcgay commented

I think you're right you may also be able to inject ProfilerEventSpy directly in your mojo (I have not tested it) and call onEvent with a custom event to be implemented in maven-profiler.
How will you report them ? I think they should be linked to the mojo goal running them ?

I think it must not be linked directly to a mojo more something like:

Action A: 30 sec
Action B: 2 sec

and so on...

I think you're right you may also be able to inject ProfilerEventSpy directly in your mojo (I have not tested it) and call onEvent with a custom event to be implemented in maven-profiler.

I played around a bit with this option and think one might even reuse some events here (e.g. repository download events), sadly this does not work out-of-the-box and I have opened apache/maven#740 to address this.