Skip to content

Commit

Permalink
Added separate row for "Merge preparation" in times report
Browse files Browse the repository at this point in the history
  • Loading branch information
salmonb committed Jun 2, 2024
1 parent dd4f969 commit 62e6135
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ExecutionTimesReport addRow(String firstColumnValue, int count, long time
timeTable.newRow();
timeTable
.addCell(firstColumnValue)
.addCell(count >= 0 ? formatNumber(count): "")
.addCell(count == -1 ? "" : formatNumber(count))
.addCell(formatNumber(timeMillis) + " ms")
.addCell((time * 100) / totalTime + " %");
cumulativeTime += time;
Expand All @@ -60,9 +60,16 @@ public String generateReport() {
}

private static String formatNumber(long number) {
// For negative numbers (i.e. merge preparation), we put the positive number in bracket (to indicate it's not
// added to the total count of files - because this operation is not generating any file)
boolean negative = number < 0;
if (negative)
number = -number;
String text = String.valueOf(number);
if (number > 1000)
text = formatNumber(number / 1000) + " " + text.substring(text.length() - 3);
if (negative)
text = "(" + text + ")";
return text;
}

Expand Down
33 changes: 19 additions & 14 deletions src/main/java/dev/webfx/cli/commands/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ public static void execute(boolean cleanSnapshots, UpdateTasks tasks, boolean ti
.addRow("Web embed resource", tasks.embedResourceCount, tasks.embedResourceStopWatch)
.addRow("Graalvm", tasks.graalvmCount, tasks.graalvmStopWatch)
.addRow("Meta", tasks.metaCount, tasks.metaStopWatch)
.addRow("Conf merge", tasks.confCount, tasks.confStopWatch)
.addRow("i18n merge", tasks.i18nCount, tasks.i18nStopWatch)
.addRow("css merge", tasks.cssCount, tasks.cssStopWatch)
.addRow("Merge preparation", -tasks.mergePrepStopWatch.getRunCount(), tasks.mergePrepStopWatch)
.addRow("Conf merge", tasks.confCount, tasks.confMergeStopWatch)
.addRow("i18n merge", tasks.i18nCount, tasks.i18nMergeStopWatch)
.addRow("css merge", tasks.cssCount, tasks.cssMergeStopWatch)
.addComplementRow("Dependencies computing, etc...")
.addTotalRow()
.generateReport());
Expand Down Expand Up @@ -191,7 +192,7 @@ static void executeUpdateTasks(DevProjectModule workingModule, UpdateTasks tasks

// Generate meta file for executable modules (dev.webfx.platform.meta.exe/exe.properties) <- always present
// and config file for executable modules (dev.webfx.platform.conf/src-root.properties) <- present only when using modules with config
if (tasks.meta || tasks.conf || tasks.i18n || tasks.css)
if (tasks.meta || tasks.conf || tasks.i18n || tasks.css) {
workingAndChildrenModulesInDepthCache
.filter(ProjectModule::isExecutable)
.forEach(module -> {
Expand All @@ -201,23 +202,26 @@ static void executeUpdateTasks(DevProjectModule workingModule, UpdateTasks tasks
tasks.metaCount++;
tasks.metaStopWatch.off();
}
// Merging tasks (conf, i18n & css)
boolean canUseCache = !tasks.pom;
if (tasks.conf) {
tasks.confStopWatch.on();
if (RootConfigFileGenerator.generateExecutableModuleConfigurationResourceFile(module, !tasks.pom))
tasks.confMergeStopWatch.on();
if (RootConfigFileGenerator.generateExecutableModuleConfigurationResourceFile(module, canUseCache, tasks.mergePrepStopWatch))
tasks.confCount++;
tasks.confStopWatch.off();
tasks.confMergeStopWatch.off();
}
if (tasks.i18n) {
tasks.i18nStopWatch.on();
tasks.i18nCount += I18nFilesGenerator.generateExecutableModuleI18nResourceFiles(module, !tasks.pom);
tasks.i18nStopWatch.off();
tasks.i18nMergeStopWatch.on();
tasks.i18nCount += I18nFilesGenerator.generateExecutableModuleI18nResourceFiles(module, canUseCache, tasks.mergePrepStopWatch);
tasks.i18nMergeStopWatch.off();
}
if (tasks.css) {
tasks.cssStopWatch.on();
tasks.cssCount += CssFilesGenerator.generateExecutableModuleCssResourceFiles(module, !tasks.pom);
tasks.cssStopWatch.off();
tasks.cssMergeStopWatch.on();
tasks.cssCount += CssFilesGenerator.generateExecutableModuleCssResourceFiles(module, canUseCache, tasks.mergePrepStopWatch);
tasks.cssMergeStopWatch.off();
}
});
}

// Generating or updating Maven module files (pom.xml)
if (tasks.pom) {
Expand All @@ -231,7 +235,7 @@ static void executeUpdateTasks(DevProjectModule workingModule, UpdateTasks tasks
}

// Generating files for Java modules (module-info.java and META-INF/services)
if (tasks.moduleInfo || tasks.metaInfServices)
if (tasks.moduleInfo || tasks.metaInfServices) {
workingAndChildrenModulesInDepthCache
.filter(DevProjectModule::hasMainJavaSourceDirectory)
// Skipping module-info.java for some special cases
Expand All @@ -254,6 +258,7 @@ static void executeUpdateTasks(DevProjectModule workingModule, UpdateTasks tasks
tasks.metaInfServicesStopWatch.off();
}
});
}

if (tasks.gwtXml || tasks.indexHtml || tasks.entryPoint || tasks.embedResource) {
// Generate files for executable GWT modules (module.gwt.xml, index.html, super sources, service loader, resource bundle)
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/dev/webfx/cli/commands/UpdateTasks.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.webfx.cli.commands;

import dev.webfx.cli.util.stopwatch.StopWatch;
import dev.webfx.cli.util.stopwatch.StopWatchGroup;

/**
* @author Bruno Salmon
Expand Down Expand Up @@ -31,9 +32,13 @@ public final class UpdateTasks {
embedResourceStopWatch = StopWatch.createSystemNanoStopWatch(),
graalvmStopWatch = StopWatch.createSystemNanoStopWatch(),
metaStopWatch = StopWatch.createSystemNanoStopWatch(),
confStopWatch = StopWatch.createSystemNanoStopWatch(),
i18nStopWatch = StopWatch.createSystemNanoStopWatch(),
cssStopWatch = StopWatch.createSystemNanoStopWatch();
mergePrepStopWatch = StopWatch.createSystemNanoStopWatch(),
confMergeStopWatch = StopWatch.createSystemNanoStopWatch(),
i18nMergeStopWatch = StopWatch.createSystemNanoStopWatch(),
cssMergeStopWatch = StopWatch.createSystemNanoStopWatch();

// Creating a group for merging stopwatches, so that mergePrepStopWatch will automatically pause others while running
private final StopWatchGroup mergeGroup = new StopWatchGroup(mergePrepStopWatch, confMergeStopWatch, i18nMergeStopWatch, cssMergeStopWatch);

public int
pomCount,
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/dev/webfx/cli/core/DevProjectModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.webfx.cli.util.hashlist.HashList;
import dev.webfx.cli.util.sort.TopologicalSort;
import dev.webfx.cli.util.splitfiles.SplitFiles;
import dev.webfx.cli.util.stopwatch.StopWatch;
import dev.webfx.cli.util.textfile.TextFileReaderWriter;
import dev.webfx.lib.reusablestream.ReusableStream;

Expand Down Expand Up @@ -237,12 +238,14 @@ public Path getGwtExecutableFilePath() {
private LinkedHashMap<String, Path> moduleWebFxPathsAsc;
private LinkedHashMap<String, Path> moduleWebFxPathsDesc;

public LinkedHashMap<String, Path> collectThisAndTransitiveWebFXPaths(boolean canUseCache, boolean asc) {
public LinkedHashMap<String, Path> collectThisAndTransitiveWebFXPaths(boolean canUseCache, boolean asc, StopWatch mergePrepStopWatch) {
if (asc && moduleWebFxPathsAsc != null)
return moduleWebFxPathsAsc;
if (!asc && moduleWebFxPathsDesc != null)
return moduleWebFxPathsDesc;

mergePrepStopWatch.on();

LinkedHashMap<String, Path> moduleWebFxPaths = new LinkedHashMap<>();

// Reading the cache file (if allowed)
Expand Down Expand Up @@ -331,6 +334,8 @@ public LinkedHashMap<String, Path> collectThisAndTransitiveWebFXPaths(boolean ca
else
moduleWebFxPathsDesc = moduleWebFxPaths;

mergePrepStopWatch.off();

return moduleWebFxPaths;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.webfx.cli.core.Platform;
import dev.webfx.cli.core.TargetTag;
import dev.webfx.cli.util.splitfiles.SplitFiles;
import dev.webfx.cli.util.stopwatch.StopWatch;
import dev.webfx.cli.util.textfile.TextFileReaderWriter;
import dev.webfx.lib.reusablestream.ReusableStream;

Expand All @@ -22,7 +23,7 @@ public final class CssFilesGenerator {
private final static PathMatcher CSS_FILE_MATCHER = FileSystems.getDefault().getPathMatcher("glob:**.css");
private final static Map<Path, String> CSS_CACHE = new HashMap<>(); // We assume the CLI exits after the update commande, so no need to clear that cache

public static int generateExecutableModuleCssResourceFiles(DevProjectModule module, boolean canUseCache) {
public static int generateExecutableModuleCssResourceFiles(DevProjectModule module, boolean canUseCache, StopWatch mergePrepStopWatch) {
boolean isWebExecutable = module.isExecutable(Platform.GWT) || module.isExecutable(Platform.J2CL);
boolean isJavaFxExecutable = !isWebExecutable && module.isExecutable() && (module.getTarget().hasTag(TargetTag.OPENJFX) || module.getTarget().hasTag(TargetTag.GLUON));
if (!isWebExecutable && !isJavaFxExecutable)
Expand All @@ -34,7 +35,7 @@ public static int generateExecutableModuleCssResourceFiles(DevProjectModule modu

Map<Path /* relative path to merged css file */, StringBuilder /* content concatenation */> cssMerges = new HashMap<>();

Map<String, Path> moduleWebFxPaths = module.collectThisAndTransitiveWebFXPaths(canUseCache, true);
Map<String, Path> moduleWebFxPaths = module.collectThisAndTransitiveWebFXPaths(canUseCache, true, mergePrepStopWatch);

moduleWebFxPaths.forEach((moduleName, webfxPath) -> {
Path webfxCssDirectory = webfxPath.resolve("css");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.webfx.cli.core.DevProjectModule;
import dev.webfx.cli.util.splitfiles.SplitFiles;
import dev.webfx.cli.util.stopwatch.StopWatch;
import dev.webfx.cli.util.textfile.TextFileReaderWriter;
import dev.webfx.lib.reusablestream.ReusableStream;
import dev.webfx.platform.ast.ReadOnlyAstArray;
Expand All @@ -21,7 +22,7 @@ public final class I18nFilesGenerator {

private final static Map<Path, Config> I18N_CACHE = new HashMap<>(); // We assume the CLI exits after the update commande, so no need to clear that cache

public static int generateExecutableModuleI18nResourceFiles(DevProjectModule module, boolean canUseCache) {
public static int generateExecutableModuleI18nResourceFiles(DevProjectModule module, boolean canUseCache, StopWatch mergePrepStopWatch) {
if (!module.isExecutable())
return 0;
// We will collect here all configurations from all transitive modules and merge them into a single
Expand All @@ -33,7 +34,7 @@ public static int generateExecutableModuleI18nResourceFiles(DevProjectModule mod
// I18n Initialisation
Map<String, ConfigMerge> i18nMerges = new HashMap<>();

Map<String, Path> moduleWebFxPaths = module.collectThisAndTransitiveWebFXPaths(canUseCache, false);
Map<String, Path> moduleWebFxPaths = module.collectThisAndTransitiveWebFXPaths(canUseCache, false, mergePrepStopWatch);

moduleWebFxPaths.forEach((moduleName, webfxPath) -> {
// I8n collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.webfx.cli.core.DevProjectModule;
import dev.webfx.cli.util.splitfiles.SplitFiles;
import dev.webfx.cli.util.stopwatch.StopWatch;
import dev.webfx.cli.util.textfile.TextFileReaderWriter;
import dev.webfx.lib.reusablestream.ReusableStream;
import dev.webfx.platform.conf.Config;
Expand All @@ -21,7 +22,7 @@ public final class RootConfigFileGenerator {

private final static Map<Path, Config> CONFIG_CACHE = new HashMap<>(); // We assume the CLI exits after the update commande, so no need to clear that cache

public static boolean generateExecutableModuleConfigurationResourceFile(DevProjectModule module, boolean canUseCache) {
public static boolean generateExecutableModuleConfigurationResourceFile(DevProjectModule module, boolean canUseCache, StopWatch mergePrepStopWatch) {
if (!module.isExecutable())
return false;
// We will collect here all configurations from all transitive modules and merge them into a single
Expand All @@ -33,7 +34,7 @@ public static boolean generateExecutableModuleConfigurationResourceFile(DevProje
// Conf Initialisation
ConfigMerge confMerge = new ConfigMerge();

Map<String, Path> moduleWebFxPaths = module.collectThisAndTransitiveWebFXPaths(canUseCache, false);
Map<String, Path> moduleWebFxPaths = module.collectThisAndTransitiveWebFXPaths(canUseCache, false, mergePrepStopWatch);

moduleWebFxPaths.forEach((moduleName, webfxPath) -> {
// Conf collection
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/dev/webfx/cli/util/stopwatch/StopWatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public final class StopWatch {
private long systemTimeAtStart;
private long stopWatchElapsedTimeAtPause;
private long stopWatchCumulativePauseDuration;
private StopWatchGroup group;

public StopWatch(Supplier<Long> systemTimeGetter) {
this.systemTimeGetter = systemTimeGetter;
Expand All @@ -27,6 +28,14 @@ public static StopWatch createSystemMillisStopWatch() {
return new StopWatch(System::currentTimeMillis);
}

public StopWatchGroup getGroup() {
return group;
}

public void setGroup(StopWatchGroup group) {
this.group = group;
}

public long getSystemTime() {
return systemTimeGetter.get();
}
Expand Down Expand Up @@ -57,7 +66,8 @@ public void decRunCount() {

public void reset() {
runCount = 0;
running = stopped = false;
setRunning(false);
stopped = false;
systemTimeAtStart = stopWatchElapsedTimeAtPause = stopWatchCumulativePauseDuration = 0;
}

Expand All @@ -74,6 +84,8 @@ private void setRunning(boolean running) {
this.running = running;
if (running)
incRunCount();
if (group != null)
group.updateStopWatchRunningState(this, running);
}
}

Expand Down
43 changes: 43 additions & 0 deletions src/main/java/dev/webfx/cli/util/stopwatch/StopWatchGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.webfx.cli.util.stopwatch;

import java.util.Arrays;

/**
* @author Bruno Salmon
*/
public class StopWatchGroup {

private StopWatch runningStopWatch;
private StopWatch pausedStopWatch;
private boolean internalSyncing;

public StopWatchGroup() {
}

public StopWatchGroup(StopWatch... stopWatches) {
Arrays.stream(stopWatches).forEach(stopWatch -> stopWatch.setGroup(this));
}

void updateStopWatchRunningState(StopWatch stopWatch, boolean running) {
if (internalSyncing)
return;
internalSyncing = true;
if (running && runningStopWatch != stopWatch) {
if (runningStopWatch != null) {
runningStopWatch.off();
pausedStopWatch = runningStopWatch;
}
runningStopWatch = stopWatch;
}
if (!running && runningStopWatch == stopWatch) {
if (pausedStopWatch != null) {
pausedStopWatch.on();
runningStopWatch = pausedStopWatch;
} else
runningStopWatch = null;
pausedStopWatch = null;
}
internalSyncing = false;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/dev/webfx/cli/version/dev/version.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=0.1.0-SNAPSHOT
build.timestamp=2024-06-02 08:05
build.timestamp=2024-06-02 13:57

0 comments on commit 62e6135

Please sign in to comment.