2014-11-20 13:21:19 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010-2014 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; version 2
|
|
|
|
|
* of the License.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
package com.sheepit.client.os;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
2014-11-30 23:42:57 +00:00
|
|
|
import java.io.File;
|
2014-11-20 13:21:19 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
2015-01-25 19:07:32 +00:00
|
|
|
import java.util.List;
|
2015-01-16 17:51:50 +01:00
|
|
|
import java.util.Map;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
|
|
|
|
import com.sheepit.client.Log;
|
|
|
|
|
import com.sheepit.client.hardware.cpu.CPU;
|
|
|
|
|
|
|
|
|
|
public class Mac extends OS {
|
|
|
|
|
private final String NICE_BINARY_PATH = "nice";
|
|
|
|
|
private Boolean hasNiceBinary;
|
|
|
|
|
|
|
|
|
|
public Mac() {
|
|
|
|
|
super();
|
|
|
|
|
this.hasNiceBinary = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String name() {
|
|
|
|
|
return "mac";
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 23:42:57 +00:00
|
|
|
@Override
|
|
|
|
|
public String getRenderBinaryPath() {
|
|
|
|
|
return "Blender" + File.separator + "blender.app" + File.separator + "Contents" + File.separator + "MacOS" + File.separator + "blender";
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
@Override
|
|
|
|
|
public CPU getCPU() {
|
|
|
|
|
CPU ret = new CPU();
|
|
|
|
|
|
|
|
|
|
String command = "sysctl machdep.cpu.family machdep.cpu.brand_string";
|
|
|
|
|
|
|
|
|
|
Process p = null;
|
|
|
|
|
BufferedReader input = null;
|
|
|
|
|
try {
|
|
|
|
|
String line;
|
|
|
|
|
p = Runtime.getRuntime().exec(command);
|
|
|
|
|
input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
|
|
|
|
|
|
|
|
while ((line = input.readLine()) != null) {
|
|
|
|
|
String option_cpu_family = "machdep.cpu.family:";
|
|
|
|
|
String option_model_name = "machdep.cpu.brand_string:";
|
|
|
|
|
if (line.startsWith(option_model_name)) {
|
|
|
|
|
ret.setName(line.substring(option_model_name.length()).trim());
|
|
|
|
|
}
|
|
|
|
|
if (line.startsWith(option_cpu_family)) {
|
|
|
|
|
ret.setFamily(line.substring(option_cpu_family.length()).trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
input.close();
|
|
|
|
|
input = null;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception err) {
|
|
|
|
|
System.out.println("exception " + err);
|
|
|
|
|
err.printStackTrace();
|
|
|
|
|
ret.setName("Unknown Mac name");
|
|
|
|
|
ret.setFamily("Unknown Mac family");
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
if (input != null) {
|
|
|
|
|
try {
|
|
|
|
|
input.close();
|
|
|
|
|
}
|
|
|
|
|
catch (IOException e) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (p != null) {
|
|
|
|
|
p.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret.setModel("Unknown");
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-02-20 13:46:53 +01:00
|
|
|
public long getMemory() {
|
2014-11-20 13:21:19 +00:00
|
|
|
String command = "sysctl hw.memsize";
|
|
|
|
|
|
|
|
|
|
Process p = null;
|
|
|
|
|
BufferedReader input = null;
|
|
|
|
|
try {
|
|
|
|
|
String line;
|
|
|
|
|
p = Runtime.getRuntime().exec(command);
|
|
|
|
|
input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
|
|
|
|
|
|
|
|
while ((line = input.readLine()) != null) {
|
|
|
|
|
String option = "hw.memsize:";
|
|
|
|
|
if (line.startsWith(option)) {
|
|
|
|
|
String memory = line.substring(option.length()).trim(); // memory in bytes
|
|
|
|
|
|
2019-02-20 13:46:53 +01:00
|
|
|
return Long.parseLong(memory) / 1024;
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
input.close();
|
|
|
|
|
input = null;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception err) {
|
|
|
|
|
System.out.println("exception " + err);
|
|
|
|
|
err.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
if (input != null) {
|
|
|
|
|
try {
|
|
|
|
|
input.close();
|
|
|
|
|
}
|
|
|
|
|
catch (IOException e) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (p != null) {
|
|
|
|
|
p.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 17:33:50 +02:00
|
|
|
@Override
|
2019-02-20 13:46:53 +01:00
|
|
|
public long getFreeMemory() {
|
2018-08-10 17:33:50 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
@Override
|
2015-01-25 19:07:32 +00:00
|
|
|
public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
|
|
|
|
List<String> actual_command = command;
|
2014-11-20 13:21:19 +00:00
|
|
|
if (this.hasNiceBinary == null) {
|
|
|
|
|
this.checkNiceAvailability();
|
|
|
|
|
}
|
|
|
|
|
if (this.hasNiceBinary.booleanValue()) {
|
2015-01-25 19:07:32 +00:00
|
|
|
// launch the process in lowest priority
|
2017-01-05 09:58:27 +01:00
|
|
|
if (env != null) {
|
|
|
|
|
actual_command.add(0, env.get("PRIORITY"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
actual_command.add(0, "19");
|
|
|
|
|
}
|
2015-01-25 19:07:32 +00:00
|
|
|
actual_command.add(0, "-n");
|
|
|
|
|
actual_command.add(0, NICE_BINARY_PATH);
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2015-01-18 16:50:28 +01:00
|
|
|
Log.getInstance(null).error("No low priority binary, will not launch renderer in normal priority");
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
ProcessBuilder builder = new ProcessBuilder(actual_command);
|
|
|
|
|
builder.redirectErrorStream(true);
|
2015-01-16 17:51:50 +01:00
|
|
|
if (env != null) {
|
|
|
|
|
builder.environment().putAll(env);
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
return builder.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getCUDALib() {
|
|
|
|
|
return "/usr/local/cuda/lib/libcuda.dylib";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void checkNiceAvailability() {
|
|
|
|
|
ProcessBuilder builder = new ProcessBuilder();
|
|
|
|
|
builder.command(NICE_BINARY_PATH);
|
|
|
|
|
builder.redirectErrorStream(true);
|
|
|
|
|
Process process = null;
|
|
|
|
|
try {
|
|
|
|
|
process = builder.start();
|
|
|
|
|
this.hasNiceBinary = true;
|
|
|
|
|
}
|
|
|
|
|
catch (IOException e) {
|
|
|
|
|
this.hasNiceBinary = false;
|
2015-01-18 16:50:28 +01:00
|
|
|
Log.getInstance(null).error("Failed to find low priority binary, will not launch renderer in normal priority (" + e + ")");
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
if (process != null) {
|
|
|
|
|
process.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|