在 运行 时间转储执行数据

Dump execution data at run time

我正在使用 JaCoCo 生成代码覆盖率报告,我有许多场景可以生成单独的报告。问题是该程序非常庞大,需要大约 2 分钟才能启动并加载所有 class 文件。

我想在其中一个场景完成后立即获取 运行 时间的执行数据,然后开始下一个场景,而不是为每个场景重新启动服务器。

有办法吗?

以下所有内容均摘自 http://www.jacoco.org/jacoco/trunk/doc/

的 JaCoCo 官方文档

Java http://www.jacoco.org/jacoco/trunk/doc/agent.html 描述的代理有选项 output:

  • file: At VM termination execution data is written to the file specified in the destfile attribute.
  • tcpserver: The agent listens for incoming connections on the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.
  • tcpclient: At startup the agent connects to the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.

和选项 jmx:

If set to true the agent exposes functionality via JMX

通过 JMX 功能公开,如 JavaDoc 等提供了以下三种方法:

byte[] getExecutionData(boolean reset) Returns current execution data.

void dump(boolean reset) Triggers a dump of the current execution data through the configured output.

void reset() Resets all coverage information.

同样从文档中也有 Ant Task dump - http://www.jacoco.org/jacoco/trunk/doc/ant.html:

This task allows to remotely collect execution data from another JVM without stopping it. Remote dumps are usefull for long running Java processes like application servers.

dump 命令行界面中的命令 - http://www.jacoco.org/jacoco/trunk/doc/cli.html

dump 进球 jacoco-maven-plugin - http://www.jacoco.org/jacoco/trunk/doc/dump-mojo.html

API usage examples包括:

  • MBeanClient.java This example connects to a coverage agent to collect execution data over the JMX.
  • ExecutionDataClient.java This example connects to a coverage agent to collect execution data over the remote protocol.
  • ExecutionDataServer.java This example starts a socket server to collect execution data from agents over the remote protocol.