Skip to content

Commit

Permalink
Add OS X mem checker
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaOvcharenko committed Aug 1, 2023
1 parent 78bddba commit 39a2b46
Showing 1 changed file with 21 additions and 3 deletions.
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

0 comments on commit 39a2b46

Please sign in to comment.