Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYSTEMDS-3602] Settings warnings memory #1871

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/main/java/org/apache/sysds/utils/SettingsChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -61,10 +63,13 @@ else if(JRE_Mem_Byte < Logging_Limit && JRE_Mem_Byte * 10 < Sys_Mem_Byte) {
}

private static long maxMemMachine() {
if("Linux".equals(System.getProperty("os.name"))) {
String sys = System.getProperty("os.name");
if("Linux".equals(sys)) {
return maxMemMachineLinux();
}
// TODO add windows.
else if(sys.contains("Mac OS")) {
return maxMemMachineOSX();
}
else {
return -1;
}
Expand All @@ -78,11 +83,24 @@ private static long maxMemMachineLinux() {
return Long.parseLong(currentLine.split(":")[1].split("kB")[0].strip());
}
catch(Exception e) {
LOG.error(e);
e.printStackTrace();
return -1;
}
}

private static long maxMemMachineOSX() {
try {
String command = "sysctl hw.memsize";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
String memStr = new String(pr.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
return Long.parseLong(memStr.trim().substring(12, memStr.length()-1));
}
catch(IOException e) {
throw new RuntimeException(e);
}
}

/**
* Converts a number of bytes in a long to a human readable string with GB, MB, KB and B.
*
Expand Down
Loading