You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemds.apache.org by ba...@apache.org on 2023/08/02 11:29:09 UTC

[systemds] branch main updated: [SYSTEMDS-3602] Settings warning memory (OS X)

This is an automated email from the ASF dual-hosted git repository.

baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new e045582ab1 [SYSTEMDS-3602] Settings warning memory (OS X)
e045582ab1 is described below

commit e045582ab1ccb8d0363228903608d66482530c58
Author: OlgaOvcharenko <ov...@gmail.com>
AuthorDate: Wed Aug 2 01:23:11 2023 +0200

    [SYSTEMDS-3602] Settings warning memory (OS X)
    
    Add OS X mem check (for Mac).
    
    Closes #1871
---
 .../org/apache/sysds/utils/SettingsChecker.java    | 24 +++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sysds/utils/SettingsChecker.java b/src/main/java/org/apache/sysds/utils/SettingsChecker.java
index dd92583a37..210263813b 100644
--- a/src/main/java/org/apache/sysds/utils/SettingsChecker.java
+++ b/src/main/java/org/apache/sysds/utils/SettingsChecker.java
@@ -21,6 +21,8 @@ package org.apache.sysds.utils;
 
 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;
@@ -61,10 +63,13 @@ public interface SettingsChecker {
 	}
 
 	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;
 		}
@@ -78,11 +83,24 @@ public interface SettingsChecker {
 			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.
 	 *