Better memory tracking for validator

This commit is contained in:
Grahame Grieve 2021-04-21 17:40:42 +10:00
parent 78ab95ff1c
commit 7d2df18fb9
7 changed files with 32 additions and 5 deletions

View File

@ -54,9 +54,9 @@ public class OperationOutcomeUtilities {
issue.addExpression(message.getLocation());
}
// pass through line/col if they're present
if (message.getLine() != 0)
if (message.getLine() >= 0)
issue.addExtension().setUrl(ToolingExtensions.EXT_ISSUE_LINE).setValue(new IntegerType(message.getLine()));
if (message.getCol() != 0)
if (message.getCol() >= 0)
issue.addExtension().setUrl(ToolingExtensions.EXT_ISSUE_COL).setValue(new IntegerType(message.getCol()));
issue.setSeverity(convert(message.getLevel()));
CodeableConcept c = new CodeableConcept();

View File

@ -1346,6 +1346,21 @@ public class Utilities {
return length + BT;
}
public static String describeSize(long length) {
if (length < 0) throw new IllegalArgumentException("File length of < 0 passed in...");
if (length > Math.pow(ONE_MB, 3)) {
return length / ((long) Math.pow(ONE_MB, 3)) + GB;
}
if (length > Math.pow(ONE_MB, 2)) {
return length / ((long) Math.pow(ONE_MB, 2)) + MB;
}
if (length > ONE_MB) {
return length / (ONE_MB) + KB;
}
return length + BT;
}
public static List<byte[]> splitBytes(byte[] array, byte[] delimiter) {
List<byte[]> byteArrays = new LinkedList<byte[]>();
if (delimiter.length == 0)

View File

@ -386,6 +386,7 @@ public class I18nConstants {
public static final String TERMINOLOGY_TX_CODE_NOTVALID = "Terminology_TX_Code_NotValid";
public static final String TERMINOLOGY_TX_CODE_UNKNOWN = "Terminology_TX_Code_Unknown";
public static final String TERMINOLOGY_TX_CODE_VALUESET = "Terminology_TX_Code_ValueSet";
public static final String Terminology_TX_Code_ValueSet_MISSING = "Terminology_TX_Code_ValueSet_MISSING";
public static final String TERMINOLOGY_TX_CODE_VALUESETMAX = "Terminology_TX_Code_ValueSetMax";
public static final String TERMINOLOGY_TX_CODE_VALUESET_EXT = "Terminology_TX_Code_ValueSet_Ext";
public static final String TERMINOLOGY_TX_CODING_COUNT = "Terminology_TX_Coding_Count";

View File

@ -164,6 +164,9 @@ public class ValidationMessage implements Comparator<ValidationMessage>, Compara
public boolean isError() {
return this == FATAL || this == ERROR;
}
public boolean isHint() {
return this == INFORMATION;
}
}
public enum IssueType {

View File

@ -130,6 +130,7 @@ Terminology_TX_Binding_NoSource2 = Binding has no source, so can''t be checked
Terminology_TX_Code_NotValid = Code {0} is not a valid code in code system {1}
Terminology_TX_Code_Unknown = Unknown Code ({0}#{1})
Terminology_TX_Code_ValueSet = No code provided, and a code is required from the value set {0} ({1})
Terminology_TX_Code_ValueSet_MISSING = No code provided, and a code is required from the value set
Terminology_TX_Code_ValueSetMax = No code provided, and a code must be provided from the value set {0} (max value set {1})
Terminology_TX_Code_ValueSet_Ext = No code provided, and a code should be provided from the value set {0} ({1})
Terminology_TX_Coding_Count = Expected {0} but found {1} coding elements

View File

@ -61,6 +61,7 @@ POSSIBILITY OF SUCH DAMAGE.
import org.hl7.fhir.r5.model.ImplementationGuide;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.utilities.TimeTracker;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.validation.cli.model.CliContext;
import org.hl7.fhir.validation.cli.services.ComparisonService;
@ -238,6 +239,6 @@ public class ValidatorCli {
}
break;
}
System.out.println("Done. " + tt.report());
System.out.println("Done. " + tt.report()+". Max Memory = "+Utilities.describeSize(Runtime.getRuntime().maxMemory()));
}
}

View File

@ -24,6 +24,8 @@ import org.hl7.fhir.validation.cli.utils.EngineMode;
import org.hl7.fhir.validation.cli.utils.VersionSourceInformation;
import java.io.FileOutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.util.ArrayList;
import java.util.List;
@ -66,6 +68,7 @@ public class ValidationService {
messages.forEach(outcome::addMessage);
response.addOutcome(outcome);
}
System.out.println(" Max Memory: "+Runtime.getRuntime().maxMemory());
return response;
}
@ -87,7 +90,8 @@ public class ValidationService {
List<ValidationRecord> records = new ArrayList<>();
Resource r = validator.validate(cliContext.getSources(), cliContext.getProfiles(), records);
int ec = 0;
System.out.println("Done. " + validator.getContext().clock().report());
MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
System.out.println("Done. " + validator.getContext().clock().report()+". Memory = "+Utilities.describeSize(mbean.getHeapMemoryUsage().getUsed()+mbean.getNonHeapMemoryUsage().getUsed()));
System.out.println();
if (cliContext.getOutput() == null) {
@ -211,7 +215,9 @@ public class ValidationService {
public String initializeValidator(CliContext cliContext, String definitions, TimeTracker tt, String sessionId) throws Exception {
tt.milestone();
if (!sessionCache.sessionExists(sessionId)) {
if (sessionId != null) {
System.out.println("No such cached session exists for session id " + sessionId + ", re-instantiating validator.");
}
System.out.print(" Load FHIR v" + cliContext.getSv() + " from " + definitions);
ValidationEngine validator = new ValidationEngine(definitions, cliContext.getSv(), tt);
sessionId = sessionCache.cacheSession(validator);