Skip to content

Commit

Permalink
Merge branch 'develop' into update-from-template-merged
Browse files Browse the repository at this point in the history
  • Loading branch information
xdev-gh-bot committed Sep 9, 2024
2 parents 75f839e + 2bdb3cc commit 91732be
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ body:
attributes:
label: "Checklist"
options:
- label: "I am able to reproduce the bug with the [latest version](https://github.com/xdev-software/template-placeholder/releases/latest)"
- label: "I am able to reproduce the bug with the [latest version](https://github.com/xdev-software/hierarchical-stopwatch/releases/latest)"
required: true
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/template-placeholder/issues) or [closed](https://github.com/xdev-software/template-placeholder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/hierarchical-stopwatch/issues) or [closed](https://github.com/xdev-software/hierarchical-stopwatch/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
required: true
- label: "I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise."
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/enhancement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body:
attributes:
label: "Checklist"
options:
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/template-placeholder/issues) or [closed](https://github.com/xdev-software/template-placeholder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/hierarchical-stopwatch/issues) or [closed](https://github.com/xdev-software/hierarchical-stopwatch/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
required: true
- label: "I have taken the time to fill in all the required details. I understand that the feature request will be dismissed otherwise."
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body:
attributes:
label: "Checklist"
options:
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/template-placeholder/issues) or [closed](https://github.com/xdev-software/template-placeholder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/hierarchical-stopwatch/issues) or [closed](https://github.com/xdev-software/hierarchical-stopwatch/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
required: true
- label: "I have taken the time to fill in all the required details. I understand that the question will be dismissed otherwise."
required: true
Expand Down
2 changes: 1 addition & 1 deletion .run/Run Demo.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Demo" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="software.xdev.Application" />
<module name="template-placeholder-demo" />
<module name="hierarchical-stopwatch-demo" />
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<extension name="coverage">
<pattern>
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
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>
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ You should have the following things installed:
* Ensure that the JDK/Java-Version is correct


## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/template-placeholder/release.yml?branch=master)](https://github.com/xdev-software/template-placeholder/actions/workflows/release.yml)
## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/hierarchical-stopwatch/release.yml?branch=master)](https://github.com/xdev-software/hierarchical-stopwatch/actions/workflows/release.yml)

Before releasing:
* Consider doing a [test-deployment](https://github.com/xdev-software/template-placeholder/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing.
* Consider doing a [test-deployment](https://github.com/xdev-software/hierarchical-stopwatch/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing.
* Check the [changelog](CHANGELOG.md)

If the ``develop`` is ready for release, create a pull request to the ``master``-Branch and merge the changes
Expand Down
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/template-placeholder?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/template-placeholder)
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/template-placeholder/check-build.yml?branch=develop)](https://github.com/xdev-software/template-placeholder/actions/workflows/check-build.yml?query=branch%3Adevelop)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_template-placeholder&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_template-placeholder)
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/hierarchical-stopwatch?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/hierarchical-stopwatch)
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/hierarchical-stopwatch/check-build.yml?branch=develop)](https://github.com/xdev-software/hierarchical-stopwatch/actions/workflows/check-build.yml?query=branch%3Adevelop)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_hierarchical-stopwatch&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_hierarchical-stopwatch)

# template-placeholder
# hierarchical-stopwatch

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

Example output:
```
-------------------------------
Root Parent Task
-------------------------------
100,00% 100,00% - Run dummy [42ms]
11,20% 11,20% - Launch tasks [5ms]
88,74% 88,74% - Wait for tasks [38ms]
ASYNC ASYNC - Process 1 [11ms]
12,45% 46,81% - Fetch [5ms]
14,01% 52,70% - Process [6ms]
0,13% 0,49% ? unspecified [0ms]
ASYNC ASYNC - Process 2 [32ms]
12,44% 16,36% - Fetch [5ms]
49,53% 65,14% - Process [21ms]
13,95% 18,35% - Finalize [6ms]
0,11% 0,14% ? unspecified [0ms]
ASYNC ASYNC - Process 3 [22ms]
12,44% 23,71% - Fetch [5ms]
39,99% 76,20% - Process [17ms]
0,05% 0,10% ? unspecified [0ms]
0,06% 0,06% ? unspecified [0ms]
```

An [usage example is available in the demo project](./hierarchical-stopwatch-demo/src/main/java/software/xdev/Application.java).

## Installation
[Installation guide for the latest release](https://github.com/xdev-software/template-placeholder/releases/latest#Installation)
[Installation guide for the latest release](https://github.com/xdev-software/hierarchical-stopwatch/releases/latest#Installation)

## Support
If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support).
Expand All @@ -15,4 +42,4 @@ If you need support as soon as possible and you can't wait for any pull request,
See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project.

## Dependencies and Licenses
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/template-placeholder/dependencies)
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/hierarchical-stopwatch/dependencies)
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Reporting a Vulnerability

Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/template-placeholder/security/advisories/new).
Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/hierarchical-stopwatch/security/advisories/new).
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

<parent>
<groupId>software.xdev</groupId>
<artifactId>template-placeholder-root</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>hierarchical-stopwatch-root</artifactId>
<version>1.1.2-SNAPSHOT</version>
</parent>

<artifactId>template-placeholder-demo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>hierarchical-stopwatch-demo</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
Expand All @@ -32,7 +32,7 @@
<dependencies>
<dependency>
<groupId>software.xdev</groupId>
<artifactId>template-placeholder</artifactId>
<artifactId>hierarchical-stopwatch</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Expand Down
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()
{
}
}
24 changes: 16 additions & 8 deletions template-placeholder/pom.xml → hierarchical-stopwatch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
<modelVersion>4.0.0</modelVersion>

<groupId>software.xdev</groupId>
<artifactId>template-placeholder</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>hierarchical-stopwatch</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>template-placeholder</name>
<description>template-placeholder</description>
<url>https://github.com/xdev-software/template-placeholder</url>
<name>hierarchical-stopwatch</name>
<description>hierarchical-stopwatch</description>
<url>https://github.com/xdev-software/hierarchical-stopwatch</url>

<scm>
<url>https://github.com/xdev-software/template-placeholder</url>
<connection>scm:git:https://github.com/xdev-software/template-placeholder.git</connection>
<url>https://github.com/xdev-software/hierarchical-stopwatch</url>
<connection>scm:git:https://github.com/xdev-software/hierarchical-stopwatch.git</connection>
</scm>

<inceptionYear>2023</inceptionYear>
<inceptionYear>2024</inceptionYear>

<organization>
<name>XDEV Software</name>
Expand Down Expand Up @@ -84,6 +84,14 @@
</repository>
</distributionManagement>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
Expand Down
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);
}
}
Loading

0 comments on commit 91732be

Please sign in to comment.