mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
(chore) commandline option for printing current memory stats for debugging
This commit is contained in:
parent
7992024451
commit
15414b26f6
2 changed files with 61 additions and 1 deletions
|
|
@ -31,7 +31,13 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.cli.*;
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
import org.apache.commons.cli.CommandLineParser;
|
||||||
|
import org.apache.commons.cli.DefaultParser;
|
||||||
|
import org.apache.commons.cli.HelpFormatter;
|
||||||
|
import org.apache.commons.cli.Option;
|
||||||
|
import org.apache.commons.cli.Options;
|
||||||
|
import org.apache.commons.cli.ParseException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -72,6 +78,8 @@ public class CommandLineApplication {
|
||||||
private static final Option CHECK_ASSERTIONS = Option.builder("c").longOpt("check-assertions").hasArg()
|
private static final Option CHECK_ASSERTIONS = Option.builder("c").longOpt("check-assertions").hasArg()
|
||||||
.desc("Check the result using defined assertions").argName("assertions-file").build();
|
.desc("Check the result using defined assertions").argName("assertions-file").build();
|
||||||
|
|
||||||
|
private static final Option PRINT_MEM_STATS = Option.builder("m").longOpt("memory-stats").desc("Prints some memory stats").build();
|
||||||
|
|
||||||
private CommandLineApplication() {
|
private CommandLineApplication() {
|
||||||
// main class -> hide constructor
|
// main class -> hide constructor
|
||||||
}
|
}
|
||||||
|
|
@ -146,6 +154,9 @@ public class CommandLineApplication {
|
||||||
Assertions assertions = loadAssertions(cmd.getOptionValue(CHECK_ASSERTIONS.getOpt()));
|
Assertions assertions = loadAssertions(cmd.getOptionValue(CHECK_ASSERTIONS.getOpt()));
|
||||||
check.getCheckSteps().add(new CheckAssertionAction(assertions, ObjectFactory.createProcessor()));
|
check.getCheckSteps().add(new CheckAssertionAction(assertions, ObjectFactory.createProcessor()));
|
||||||
}
|
}
|
||||||
|
if (cmd.hasOption(PRINT_MEM_STATS.getOpt())) {
|
||||||
|
check.getCheckSteps().add(new PrintMemoryStats());
|
||||||
|
}
|
||||||
|
|
||||||
log.info("Setup completed in {}ms\n", System.currentTimeMillis() - start);
|
log.info("Setup completed in {}ms\n", System.currentTimeMillis() - start);
|
||||||
|
|
||||||
|
|
@ -285,6 +296,7 @@ public class CommandLineApplication {
|
||||||
options.addOption(EXTRACT_HTML);
|
options.addOption(EXTRACT_HTML);
|
||||||
options.addOption(DEBUG);
|
options.addOption(DEBUG);
|
||||||
options.addOption(CHECK_ASSERTIONS);
|
options.addOption(CHECK_ASSERTIONS);
|
||||||
|
options.addOption(PRINT_MEM_STATS);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||||
|
* one or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. KoSIT licenses this file
|
||||||
|
* to you 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 de.kosit.validationtool.cmd;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andreas Penski
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class PrintMemoryStats implements de.kosit.validationtool.impl.tasks.CheckAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void check(final Bag results) {
|
||||||
|
Runtime.getRuntime().gc();
|
||||||
|
final Runtime runtime = Runtime.getRuntime();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
long maxMemory = runtime.maxMemory();
|
||||||
|
long allocatedMemory = runtime.totalMemory();
|
||||||
|
long freeMemory = runtime.freeMemory();
|
||||||
|
NumberFormat format = NumberFormat.getInstance();
|
||||||
|
|
||||||
|
sb.append("free memory: " + format.format(freeMemory / 1024));
|
||||||
|
sb.append("MB allocated memory: " + format.format(allocatedMemory / 1024));
|
||||||
|
sb.append("MB max memory: " + format.format(maxMemory / 1024));
|
||||||
|
sb.append("MB total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) + "MB");
|
||||||
|
log.info("{}", sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue