Skip to content

Commit

Permalink
Merge pull request #5 from xdev-software/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
AB-xdev authored Apr 17, 2024
2 parents 6db92fd + 9495380 commit 53aea81
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 90 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# 1.1.0
* Consolidated ``AutoCloseable`` into ``HierarchicalStopWatch``

# 1.0.0
<i>Initial release</i>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# hierarchical-stopwatch

A hierarchical stopwatch that supports nesting and can be used to track performance across methods and classes. It also supports async.
A hierarchical Java stopwatch that supports nesting and can be used to track performance across methods and classes. It also supports async.

Example output:
```
Expand Down
2 changes: 1 addition & 1 deletion hierarchical-stopwatch-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>hierarchical-stopwatch-demo</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,38 @@
import java.util.stream.IntStream;

import software.xdev.time.HierarchicalLoggingStopWatch;
import software.xdev.time.HierarchicalStopWatch;


public final class Application
{
public static void main(final String[] args)
{
try(final var profiler = HierarchicalLoggingStopWatch.createStarted(
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 var ignored = profiler.nestedAC("Launch tasks"))
try(final HierarchicalStopWatch ignored = dummySw.nested("Launch tasks"))
{
completableFutures = IntStream.of(1, 2, 3)
.mapToObj(i -> CompletableFuture.runAsync(() -> {
try(final var process = profiler.nestedAC("Process " + i, true))
try(final var processSw = dummySw.nested("Process " + i, true))
{
try(final var ignore = process.nestedAC("Fetch"))
try(final var ignore = processSw.nested("Fetch"))
{
sleep(5);
}

try(final var ignore = process.nestedAC("Process"))
try(final var ignore = processSw.nested("Process"))
{
sleep(i * 5);
}

if(i % 2 == 0)
{
try(final var ignore = process.nestedAC("Finalize"))
try(final var ignore = processSw.nested("Finalize"))
{
sleep(5);
}
Expand All @@ -45,7 +46,7 @@ public static void main(final String[] args)
.toList();
}

try(final var ignored = profiler.nestedAC("Wait for tasks"))
try(final HierarchicalStopWatch ignore = dummySw.nested("Wait for tasks"))
{
completableFutures.forEach(CompletableFuture::join);
}
Expand Down
2 changes: 1 addition & 1 deletion hierarchical-stopwatch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>hierarchical-stopwatch</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>hierarchical-stopwatch</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@


/**
* Same as {@link HierarchicalStopWatchAutoClosable} but with a Consumer that handles
* Same as {@link HierarchicalStopWatch} but with a Consumer that handles
* {@link HierarchicalStopWatch#getPrettyPrinted()}
*
* @see HierarchicalStopWatchAutoClosable
* @see HierarchicalStopWatch
*/
public class HierarchicalLoggingStopWatch extends HierarchicalStopWatchAutoClosable
public class HierarchicalLoggingStopWatch extends HierarchicalStopWatch
{
protected final Consumer<String> logConsumer;

Expand Down Expand Up @@ -62,10 +62,10 @@ public static HierarchicalLoggingStopWatch createStarted(
}

public static HierarchicalLoggingStopWatch createStarted(
final String taskname,
final String taskName,
final Consumer<String> logConsumer,
final boolean enabled)
{
return createStarted(taskname, logConsumer, false, enabled);
return createStarted(taskName, logConsumer, false, enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* </pre>
* </p>
*/
public class HierarchicalStopWatch
public class HierarchicalStopWatch implements AutoCloseable
{
protected static final double NANOS_TO_MILLIS_FACTOR = 1000000.0;

Expand Down Expand Up @@ -123,6 +123,12 @@ public void stop()
}
}

@Override
public void close()
{
this.stop();
}

/**
* Tries to stop all nested profilers
*/
Expand Down Expand Up @@ -156,9 +162,7 @@ protected void addNested(final HierarchicalStopWatch nested, final boolean start
public HierarchicalStopWatch nested(final String taskName, final boolean async)
{
final HierarchicalStopWatch nested = new HierarchicalStopWatch(taskName, async, this.isEnabled());

this.addNested(nested, true);

return nested;
}

Expand All @@ -170,25 +174,6 @@ public HierarchicalStopWatch nested(final String taskName)
return this.nested(taskName, false);
}

/**
* Creates a new nested {@link AutoCloseable} profiler
*/
public HierarchicalStopWatchAutoClosable nestedAC(final String taskName, final boolean async)
{
final HierarchicalStopWatchAutoClosable nested =
new HierarchicalStopWatchAutoClosable(taskName, async, this.isEnabled());
this.addNested(nested, true);
return nested;
}

/**
* Creates a new nested {@link AutoCloseable} profiler
*/
public HierarchicalStopWatchAutoClosable nestedAC(final String taskName)
{
return this.nestedAC(taskName, false);
}

public String getPrettyPrinted()
{
if(!this.isEnabled())
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>hierarchical-stopwatch-root</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<organization>
Expand Down

0 comments on commit 53aea81

Please sign in to comment.