Skip to content

Commit

Permalink
#69 timings
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 2, 2024
1 parent 3f69e3d commit 656fe2f
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 39 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# The MIT License (MIT)
#
# Copyright (c) 2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
name: benchmark
'on':
push:
branches:
- master
jobs:
benchmark:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
- uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ubuntu-jdk-21-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
ubuntu-jdk-21-maven-
- run: mvn clean test -Dtest=OptimizeMojoTest#optimizesJustOneLargeJnaClass --errors --batch-mode
- run: |
sum=$(cat target/jna-summary.txt)
perl -i -pe "s/<!-- benchmark_begin -->.*<!-- benchmark_end -->/${sum}/g" README.md
- uses: peter-evans/create-pull-request@v7
with:
branch: benchmark
commit-message: 'new benchmark results'
delete-branch: true
title: 'New benchmarking results'
assignees: yegor256
base: master
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ is not true,
[submit a ticket](https://github.com/objectionary/hone-maven-plugin/issues),
we will try to fix.

## Benchmark

Here is the result of the latest processing of a large Java class:

<!-- benchmark_begin -->
...
<!-- benchmark_end -->

## How to Contribute

Fork repository, make changes, then send us
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ SOFTWARE.
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>farea</artifactId>
<version>0.4.0</version>
<version>0.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/org/eolang/hone/AbstractMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.eolang.hone;

import com.jcabi.log.Logger;
import java.io.File;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -37,14 +38,32 @@
* in Maven Plugin API design.</p>
*
* @since 0.1.0
* @checkstyle VisibilityModifierCheck (500 lines)
*/
abstract class AbstractMojo extends org.apache.maven.plugin.AbstractMojo {

/**
* The "target/" directory of Maven project.
*
* @since 0.1.0
*/
@Parameter(
property = "hone.target",
defaultValue = "${project.build.directory}"
)
protected File target;

/**
* Timings.
*
* @since 0.1.0
*/
protected Timings timings;

/**
* Docker image to use.
*
* @since 0.1.0
* @checkstyle VisibilityModifierCheck (5 lines)
*/
@Parameter(property = "hone.image", defaultValue = "yegor256/hone")
protected String image;
Expand All @@ -53,7 +72,6 @@ abstract class AbstractMojo extends org.apache.maven.plugin.AbstractMojo {
* Use "sudo" for "docker".
*
* @since 0.1.0
* @checkstyle VisibilityModifierCheck (5 lines)
*/
@Parameter(property = "hone.sudo", defaultValue = "false")
protected boolean sudo;
Expand All @@ -62,7 +80,6 @@ abstract class AbstractMojo extends org.apache.maven.plugin.AbstractMojo {
* Skip the execution, if set to TRUE.
*
* @since 0.1.0
* @checkstyle VisibilityModifierCheck (5 lines)
*/
@Parameter(property = "hone.skip", defaultValue = "false")
private boolean skip;
Expand All @@ -74,6 +91,7 @@ public final void execute() throws MojoExecutionException {
Logger.info(this, "Execution skipped");
return;
}
this.timings = new Timings(this.target.toPath().resolve("hone-timings.csv"));
try {
this.exec();
} catch (final IOException ex) {
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/org/eolang/hone/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,19 @@ public void exec() throws IOException {
for (final String file : new String[] {"entry.sh", "normalize.sh"}) {
temp.path().resolve(file).toFile().setExecutable(true);
}
new IoChecked<>(
new Retry<>(
(Scalar<Object>) () -> new Docker(this.sudo).exec(
"build",
"--pull",
"--tag", this.image,
temp.path().toString()
this.timings.through(
"build",
() -> new IoChecked<>(
new Retry<>(
(Scalar<Object>) () -> new Docker(this.sudo).exec(
"build",
"--pull",
"--tag", this.image,
temp.path().toString()
)
)
)
).value();
).value()
);
}
}
}
17 changes: 4 additions & 13 deletions src/main/java/org/eolang/hone/OptimizeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.jcabi.log.Logger;
import com.sun.security.auth.module.UnixSystem;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -92,17 +91,6 @@ public final class OptimizeMojo extends AbstractMojo {
@Parameter(property = "hone.jeo-version")
private String jeoVersion;

/**
* The "target/" directory of Maven project.
*
* @since 0.1.0
*/
@Parameter(
property = "hone.target",
defaultValue = "${project.build.directory}"
)
private File target;

@Override
public void exec() throws IOException {
final Collection<String> command = new LinkedList<>(
Expand Down Expand Up @@ -148,7 +136,10 @@ public void exec() throws IOException {
)
);
command.add(this.image);
new Docker(this.sudo).exec(command);
this.timings.through(
"optimize",
() -> new Docker(this.sudo).exec(command)
);
Logger.info(this, "Bytecode was optimized in '%s'", this.target);
}
}
7 changes: 5 additions & 2 deletions src/main/java/org/eolang/hone/PullMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ public final class PullMojo extends AbstractMojo {

@Override
public void exec() throws IOException {
new Docker(this.sudo).exec(
this.timings.through(
"pull",
this.image
() -> new Docker(this.sudo).exec(
"pull",
this.image
)
);
Logger.info(this, "Docker image '%s' was pulled", this.image);
}
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/org/eolang/hone/Timings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.hone;

import com.jcabi.log.Logger;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

/**
* Timings.
*
* @since 0.1.0
*/
final class Timings {

/**
* Path of the file.
*/
private final Path path;

/**
* Ctor.
* @param file Location of the CSV file to modify
*/
Timings(final Path file) {
this.path = file;
}

/**
* Run and record.
* @param name Name of the action
* @param action The action
* @throws IOException If fails
*/
public void through(final String name, final Timings.Action action) throws IOException {
final long start = System.currentTimeMillis();
try {
action.exec();
} finally {
final File dir = this.path.toFile().getParentFile();
if (dir.mkdirs()) {
Logger.debug(this, "Directory created: %[file]s", dir);
}
Files.write(
this.path,
String.format(
"%s,%d\n", name, System.currentTimeMillis() - start
).getBytes(),
StandardOpenOption.APPEND, StandardOpenOption.CREATE
);
}
}

/**
* What to do.
*
* @since 0.1.0
*/
public interface Action {
/**
* Exec it.
* @throws IOException If fails
*/
void exec() throws IOException;
}

}
Loading

0 comments on commit 656fe2f

Please sign in to comment.