-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: add an option to generate a simple build report
- resolves #29174
- Loading branch information
Showing
5 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
devtools/cli/src/main/java/io/quarkus/cli/BuildReport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package io.quarkus.cli; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.quarkus.cli.build.BuildSystemRunner; | ||
import io.quarkus.qute.CheckedTemplate; | ||
import io.quarkus.qute.TemplateInstance; | ||
|
||
@CheckedTemplate(basePath = "") | ||
public class BuildReport { | ||
|
||
static native TemplateInstance buildReport(String buildTarget, long duration, Set<String> threads, | ||
List<BuildStepRecord> records); | ||
|
||
private final BuildSystemRunner runner; | ||
|
||
public BuildReport(BuildSystemRunner runner) { | ||
this.runner = runner; | ||
} | ||
|
||
File generate() throws IOException { | ||
File metricsJsonFile = runner.getProjectRoot().resolve(runner.getBuildTool().getBuildDirectory()) | ||
.resolve("build-metrics.json").toFile(); | ||
if (!metricsJsonFile.canRead()) { | ||
throw new IllegalStateException("Build metrics file cannot be read: " + metricsJsonFile); | ||
} | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
JsonNode root = objectMapper.readTree(metricsJsonFile); | ||
|
||
String buildTarget = root.get("buildTarget").asText(); | ||
long duration = root.get("duration").asLong(); | ||
Set<String> threads = new HashSet<>(); | ||
List<BuildStepRecord> records = new ArrayList<>(); | ||
|
||
for (JsonNode record : root.get("records")) { | ||
String thread = record.get("thread").asText(); | ||
threads.add(thread); | ||
records.add(new BuildStepRecord(record.get("stepId").asText(), record.get("started").asText(), | ||
record.get("duration").asLong(), thread)); | ||
} | ||
|
||
File output = runner.getProjectRoot().resolve(runner.getBuildTool().getBuildDirectory()) | ||
.resolve("build-report.html").toFile(); | ||
if (output.exists() && !output.canWrite()) { | ||
throw new IllegalStateException("Build report file cannot be written to: " + output); | ||
} | ||
try { | ||
Files.writeString(output.toPath(), | ||
BuildReport.buildReport(buildTarget, duration, threads, records).render()); | ||
return output; | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
} | ||
|
||
public static class BuildStepRecord { | ||
|
||
public final String stepId; | ||
public final String started; | ||
public final long duration; | ||
public final String thread; | ||
|
||
public BuildStepRecord(String stepId, String started, long duration, String thread) { | ||
this.stepId = stepId; | ||
this.started = started; | ||
this.duration = duration; | ||
this.thread = thread; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
devtools/cli/src/main/resources/templates/buildReport.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Quarkus Build Report - {buildTarget}</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css"> | ||
<style> | ||
body { | ||
font-family: sans; | ||
width: max-content; | ||
padding: 2rem; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="container-fluid"> | ||
|
||
<h1>Quarkus Build Report - {buildTarget}</h1> | ||
|
||
<p class="lead mt-4 mb-4"> | ||
Executed <strong>{records.size}</strong> build steps on <strong>{threads.size}</strong> threads in | ||
<strong>{duration} ms</strong>. | ||
</p> | ||
|
||
<h2>Build Steps</h2> | ||
|
||
<table class="table table-striped mb-4"> | ||
<thead class="thead-dark"> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">Build Step</th> | ||
<th scope="col">Started</th> | ||
<th scope="col">Duration</th> | ||
<th scope="col">Thread</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#for record in records} | ||
<tr> | ||
<td>{record_count}</td> | ||
<td> | ||
{record.stepId} | ||
</td> | ||
<td> | ||
{record.started} | ||
</td> | ||
<td> | ||
{#if record.duration < 1} < 1ms {#else} {record.duration} ms {/if} </td> | ||
<td> | ||
{record.thread} | ||
</td> | ||
{/for} | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | ||
|
||
</body> | ||
|
||
</html> |