-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into update-from-template-merged
- Loading branch information
Showing
15 changed files
with
570 additions
and
32 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
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
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,9 @@ | ||
# 1.1.1 | ||
* Minor performance improvements | ||
* Update dependencies | ||
|
||
# 1.1.0 | ||
* Consolidated ``AutoCloseable`` into ``HierarchicalStopWatch`` | ||
|
||
# 1.0.0 | ||
<i>Initial release</i> |
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
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
72 changes: 72 additions & 0 deletions
72
hierarchical-stopwatch-demo/src/main/java/software/xdev/Application.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,72 @@ | ||
package software.xdev; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.IntStream; | ||
|
||
import software.xdev.time.HierarchicalLoggingStopWatch; | ||
import software.xdev.time.HierarchicalStopWatch; | ||
|
||
|
||
public final class Application | ||
{ | ||
@SuppressWarnings("java:S106") | ||
public static void main(final String[] args) | ||
{ | ||
try(final HierarchicalStopWatch dummySw = HierarchicalLoggingStopWatch.createStarted( | ||
"Run dummy", | ||
System.out::println, // Could also be LOGGER::debug | ||
true)) // Could also be LOGGER.isDebugEnabled() | ||
{ | ||
final List<CompletableFuture<Void>> completableFutures; | ||
try(final HierarchicalStopWatch ignored = dummySw.nested("Launch tasks")) | ||
{ | ||
completableFutures = IntStream.of(1, 2, 3) | ||
.mapToObj(i -> CompletableFuture.runAsync(() -> { | ||
try(final var processSw = dummySw.nested("Process " + i, true)) | ||
{ | ||
try(final var ignore = processSw.nested("Fetch")) | ||
{ | ||
sleep(5); | ||
} | ||
|
||
try(final var ignore = processSw.nested("Process")) | ||
{ | ||
sleep(i * 5); | ||
} | ||
|
||
if(i % 2 == 0) | ||
{ | ||
try(final var ignore = processSw.nested("Finalize")) | ||
{ | ||
sleep(5); | ||
} | ||
} | ||
} | ||
})) | ||
.toList(); | ||
} | ||
|
||
try(final HierarchicalStopWatch ignore = dummySw.nested("Wait for tasks")) | ||
{ | ||
completableFutures.forEach(CompletableFuture::join); | ||
} | ||
} | ||
} | ||
|
||
private static void sleep(final int ms) | ||
{ | ||
try | ||
{ | ||
Thread.sleep(ms); | ||
} | ||
catch(final InterruptedException iex) | ||
{ | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
|
||
private Application() | ||
{ | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
hierarchical-stopwatch/src/main/java/software/xdev/time/HierarchicalLoggingStopWatch.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,71 @@ | ||
/* | ||
* Copyright © 2024 XDEV Software (https://xdev.software) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package software.xdev.time; | ||
|
||
import java.util.function.Consumer; | ||
|
||
|
||
/** | ||
* Same as {@link HierarchicalStopWatch} but with a Consumer that handles | ||
* {@link HierarchicalStopWatch#getPrettyPrinted()} | ||
* | ||
* @see HierarchicalStopWatch | ||
*/ | ||
public class HierarchicalLoggingStopWatch extends HierarchicalStopWatch | ||
{ | ||
protected final Consumer<String> logConsumer; | ||
|
||
public HierarchicalLoggingStopWatch( | ||
final String taskName, | ||
final Consumer<String> logConsumer, | ||
final boolean async, | ||
final boolean enabled) | ||
{ | ||
super(taskName, async, enabled); | ||
this.logConsumer = logConsumer; | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
super.close(); | ||
this.stopAll(); | ||
if(this.isEnabled()) | ||
{ | ||
this.logConsumer.accept(this.getPrettyPrinted()); | ||
} | ||
} | ||
|
||
public static HierarchicalLoggingStopWatch createStarted( | ||
final String taskName, | ||
final Consumer<String> logConsumer, | ||
final boolean async, | ||
final boolean enabled) | ||
{ | ||
final HierarchicalLoggingStopWatch sw = new HierarchicalLoggingStopWatch(taskName, logConsumer, async, | ||
enabled); | ||
sw.start(); | ||
return sw; | ||
} | ||
|
||
public static HierarchicalLoggingStopWatch createStarted( | ||
final String taskName, | ||
final Consumer<String> logConsumer, | ||
final boolean enabled) | ||
{ | ||
return createStarted(taskName, logConsumer, false, enabled); | ||
} | ||
} |
Oops, something went wrong.