From a67fb25d46f7481b65a724d810949f7aaa08c353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A1udio=20Gomes?= Date: Thu, 7 Mar 2024 21:36:26 -0300 Subject: [PATCH] impl. timer --- .../clagomess/pirilampo/core/compilers/Compiler.java | 12 ++++++++++++ .../core/compilers/FeatureToHTMLCompiler.java | 3 ++- .../core/compilers/FeatureToPDFCompiler.java | 4 +++- .../core/compilers/FolderToHTMLCompiler.java | 5 +++-- .../core/compilers/FolderToPDFCompiler.java | 5 +++-- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/Compiler.java b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/Compiler.java index 5f9c8cd..9c9f290 100644 --- a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/Compiler.java +++ b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/Compiler.java @@ -2,11 +2,13 @@ import com.github.clagomess.pirilampo.core.dto.FeatureMetadataDto; import com.github.clagomess.pirilampo.core.dto.ParametersDto; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.input.BOMInputStream; import java.io.*; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Set; @@ -18,6 +20,7 @@ import static com.github.clagomess.pirilampo.core.enums.CompilationTypeEnum.FOLDER; import static com.github.clagomess.pirilampo.core.enums.CompilationTypeEnum.FOLDER_DIFF; +@Slf4j public abstract class Compiler { public String getFeatureExtension(File f){ Matcher matcher = Pattern.compile("\\.feature$", Pattern.CASE_INSENSITIVE) @@ -146,4 +149,13 @@ public File getAbsolutePathFeatureAsset(ParametersDto parameters, File feature, return null; } + + private long initTimer; + protected void startTimer(){ + initTimer = Instant.now().toEpochMilli(); + } + + protected void stopTimer(){ + log.info("Compilation time: {}ms", Instant.now().toEpochMilli() - initTimer); + } } diff --git a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FeatureToHTMLCompiler.java b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FeatureToHTMLCompiler.java index 3ce6e1f..61d20fd 100644 --- a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FeatureToHTMLCompiler.java +++ b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FeatureToHTMLCompiler.java @@ -26,6 +26,7 @@ public FeatureToHTMLCompiler(ParametersDto parameters) { } public void build() throws Exception { + startTimer(); GherkinDocumentParser gherkinDocumentParser = new GherkinDocumentParser(parameters, feature); try ( @@ -55,6 +56,6 @@ public void build() throws Exception { out.print(""); } - // @TODO: add done and took + stopTimer(); } } diff --git a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FeatureToPDFCompiler.java b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FeatureToPDFCompiler.java index de3c369..8949736 100644 --- a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FeatureToPDFCompiler.java +++ b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FeatureToPDFCompiler.java @@ -33,6 +33,8 @@ public FeatureToPDFCompiler(ParametersDto parameters) { } public void build() throws Exception { + startTimer(); + File bufferHtml = File.createTempFile("pirilampo-buffer-", ".html"); log.info("Created buffer file: {}", bufferHtml); File outArtifact = getOutArtifact(parameters); @@ -83,6 +85,6 @@ public void build() throws Exception { throw e; } - // @TODO: add done and took + stopTimer(); } } diff --git a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FolderToHTMLCompiler.java b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FolderToHTMLCompiler.java index 125656d..674ac50 100644 --- a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FolderToHTMLCompiler.java +++ b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FolderToHTMLCompiler.java @@ -130,8 +130,9 @@ protected void buildIndex(PrintWriter out) throws JsonProcessingException { } public void build() throws Exception { - MenuParser menuParser = new MenuParser(parameters); + startTimer(); + MenuParser menuParser = new MenuParser(parameters); Set arquivos = listFolder(parameters.getProjectSource()); if(arquivos.isEmpty()) return; @@ -220,6 +221,6 @@ public void build() throws Exception { out.print(""); } - // @TODO: add done and took + stopTimer(); } } diff --git a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FolderToPDFCompiler.java b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FolderToPDFCompiler.java index f13e126..d9a566f 100644 --- a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FolderToPDFCompiler.java +++ b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/FolderToPDFCompiler.java @@ -27,6 +27,8 @@ public FolderToPDFCompiler(ParametersDto parameters) { } public void build() throws Exception { + startTimer(); + Set arquivos = listFolder(parameters.getProjectSource()); if(arquivos.isEmpty()) return; @@ -96,7 +98,6 @@ public void build() throws Exception { throw e; } - // @TODO: add done and took - // @TODO: attach HTML at END + stopTimer(); } }