Move the Render info to a specific class

This commit is contained in:
Laurent Clouet
2015-04-27 20:10:36 +01:00
parent 2900607658
commit dbf55ff4bb
4 changed files with 132 additions and 71 deletions

View File

@@ -306,8 +306,8 @@ public class Client {
this.disableErrorSending = true; this.disableErrorSending = true;
if (this.renderingJob != null) { if (this.renderingJob != null) {
if (this.renderingJob.getProcess() != null) { if (this.renderingJob.getProcessRender().getProcess() != null) {
OS.getOS().kill(this.renderingJob.getProcess()); OS.getOS().kill(this.renderingJob.getProcessRender().getProcess());
this.renderingJob.setAskForRendererKill(true); this.renderingJob.setAskForRendererKill(true);
} }
} }
@@ -405,7 +405,7 @@ public class Client {
writer.close(); writer.close();
String args = "?type=" + (error == null ? "" : error.getValue()); String args = "?type=" + (error == null ? "" : error.getValue());
if (job_to_reset_ != null) { if (job_to_reset_ != null) {
args += "&frame=" + job_to_reset_.getFrameNumber() + "&job=" + job_to_reset_.getId() + "&render_time=" + job_to_reset_.getRenderDuration(); args += "&frame=" + job_to_reset_.getFrameNumber() + "&job=" + job_to_reset_.getId() + "&render_time=" + job_to_reset_.getProcessRender().getDuration();
if (job_to_reset_.getExtras() != null && job_to_reset_.getExtras().isEmpty() == false) { if (job_to_reset_.getExtras() != null && job_to_reset_.getExtras().isEmpty() == false) {
args += "&extras=" + job_to_reset_.getExtras(); args += "&extras=" + job_to_reset_.getExtras();
} }
@@ -516,6 +516,7 @@ public class Client {
protected Error.Type runRenderer(Job ajob) { protected Error.Type runRenderer(Job ajob) {
this.gui.status("Rendering"); this.gui.status("Rendering");
RenderProcess process = ajob.getProcessRender();
String core_script = "import bpy\n" + "bpy.context.user_preferences.system.compute_device_type = \"%s\"\n" + "bpy.context.scene.cycles.device = \"%s\"\n" + "bpy.context.user_preferences.system.compute_device = \"%s\"\n"; String core_script = "import bpy\n" + "bpy.context.user_preferences.system.compute_device_type = \"%s\"\n" + "bpy.context.scene.cycles.device = \"%s\"\n" + "bpy.context.user_preferences.system.compute_device = \"%s\"\n";
if (ajob.getUseGPU() && this.config.getGPUDevice() != null) { if (ajob.getUseGPU() && this.config.getGPUDevice() != null) {
core_script = String.format(core_script, "CUDA", "GPU", this.config.getGPUDevice().getCudaName()); core_script = String.format(core_script, "CUDA", "GPU", this.config.getGPUDevice().getCudaName());
@@ -584,14 +585,13 @@ public class Client {
} }
} }
long rending_start = new Date().getTime();
try { try {
String line; String line;
this.log.debug(command.toString()); this.log.debug(command.toString());
OS os = OS.getOS(); OS os = OS.getOS();
ajob.setProcess(os.exec(command, new_env)); process.start();
BufferedReader input = new BufferedReader(new InputStreamReader(ajob.getProcess().getInputStream())); ajob.getProcessRender().setProcess(os.exec(command, new_env));
BufferedReader input = new BufferedReader(new InputStreamReader(ajob.getProcessRender().getProcess().getInputStream()));
long last_update_status = 0; long last_update_status = 0;
this.log.debug("renderer output"); this.log.debug("renderer output");
@@ -630,32 +630,13 @@ public class Client {
return Error.Type.FAILED_TO_EXECUTE; return Error.Type.FAILED_TO_EXECUTE;
} }
long rending_end = new Date().getTime(); int exit_value = process.exitValue();
process.finish();
if (script_file != null) { if (script_file != null) {
script_file.delete(); script_file.delete();
} }
ajob.setRenderDuration((int) ((rending_end - rending_start) / 1000 + 1)); // render time is in seconds but the getTime is in milliseconds
int exit_value = 0;
try {
exit_value = ajob.getProcess().exitValue();
}
catch (IllegalThreadStateException e) {
// the process is not finished yet
exit_value = 0;
}
catch (Exception e) {
// actually is for java.io.IOException: GetExitCodeProcess error=6, The handle is invalid
// it was not declared throwable
// the process is not finished yet
exit_value = 0;
}
ajob.setProcess(null);
// find the picture file // find the picture file
final String filename_without_extension = ajob.getPrefixOutputImage() + ajob.getFrameNumber(); final String filename_without_extension = ajob.getPrefixOutputImage() + ajob.getFrameNumber();
@@ -689,8 +670,8 @@ public class Client {
return Error.Type.RENDERER_CRASHED; return Error.Type.RENDERER_CRASHED;
} }
if (exit_value == 127 && ajob.getRenderDuration() < 10) { if (exit_value == 127 && process.getDuration() < 10) {
this.log.error("Client::runRenderer renderer returned 127 and took " + ajob.getRenderDuration() + "s, some libraries may be missing"); this.log.error("Client::runRenderer renderer returned 127 and took " + process.getDuration() + "s, some libraries may be missing");
return Error.Type.RENDERER_MISSING_LIBRARIES; return Error.Type.RENDERER_MISSING_LIBRARIES;
} }
@@ -703,11 +684,11 @@ public class Client {
File scene_dir = new File(ajob.getSceneDirectory()); File scene_dir = new File(ajob.getSceneDirectory());
long date_modification_scene_directory = (long) Utils.lastModificationTime(scene_dir); long date_modification_scene_directory = (long) Utils.lastModificationTime(scene_dir);
if (date_modification_scene_directory > rending_start) { if (date_modification_scene_directory > process.getStartTime()) {
scene_dir.delete(); scene_dir.delete();
} }
this.gui.status(String.format("Frame rendered in %dmin%ds", ajob.getRenderDuration() / 60, ajob.getRenderDuration() % 60)); this.gui.status(String.format("Frame rendered in %dmin%ds", process.getDuration() / 60, process.getDuration() % 60));
return Error.Type.OK; return Error.Type.OK;
} }
@@ -822,7 +803,7 @@ public class Client {
extras_config = "&cores=" + this.config.getNbCores(); extras_config = "&cores=" + this.config.getNbCores();
} }
String url_real = String.format("%s?job=%s&frame=%s&rendertime=%d&revision=%s&memoryused=%s&extras=%s%s", this.server.getPage("validate-job"), ajob.getId(), ajob.getFrameNumber(), ajob.getRenderDuration(), ajob.getRevision(), ajob.getMemoryUsed(), ajob.getExtras(), extras_config); String url_real = String.format("%s?job=%s&frame=%s&rendertime=%d&revision=%s&memoryused=%s&extras=%s%s", this.server.getPage("validate-job"), ajob.getId(), ajob.getFrameNumber(), ajob.getProcessRender().getDuration(), ajob.getRevision(), ajob.getProcessRender().getMemoryUsed(), ajob.getExtras(), extras_config);
this.isValidatingJob = true; this.isValidatingJob = true;
int nb_try = 1; int nb_try = 1;
@@ -942,8 +923,8 @@ public class Client {
int end = element.indexOf(')'); int end = element.indexOf(')');
if (end > 0) { if (end > 0) {
long mem = Utils.parseNumber(element.substring(1, end).trim()); long mem = Utils.parseNumber(element.substring(1, end).trim());
if (mem > ajob.getMemoryUsed()) { if (mem > ajob.getProcessRender().getMemoryUsed()) {
ajob.setMemoryUsed(mem); ajob.getProcessRender().setMemoryUsed(mem);
} }
} }
} }
@@ -952,8 +933,8 @@ public class Client {
int end = element.indexOf('|'); int end = element.indexOf('|');
if (end > 0) { if (end > 0) {
long mem = Utils.parseNumber(element.substring(1, end).trim()); long mem = Utils.parseNumber(element.substring(1, end).trim());
if (mem > ajob.getMemoryUsed()) { if (mem > ajob.getProcessRender().getMemoryUsed()) {
ajob.setMemoryUsed(mem); ajob.getProcessRender().setMemoryUsed(mem);
} }
} }
} }

View File

@@ -31,16 +31,13 @@ public class Job {
private String revision; private String revision;
private String pictureFilename; private String pictureFilename;
private String path; // path inside of the archive private String path; // path inside of the archive
private int renderDuration; // in seconds
private long memoryUsed; // in kB
private String rendererCommand; private String rendererCommand;
private String script; private String script;
private boolean useGPU; private boolean useGPU;
private String extras; private String extras;
private String updateRenderingStatusMethod; private String updateRenderingStatusMethod;
private boolean synchronousUpload; private boolean synchronousUpload;
private RenderProcess render;
private Process process;
private boolean askForRendererKill; private boolean askForRendererKill;
private Configuration config; private Configuration config;
@@ -59,17 +56,19 @@ public class Job {
synchronousUpload = synchronous_upload_; synchronousUpload = synchronous_upload_;
pictureFilename = null; pictureFilename = null;
renderDuration = 0;
memoryUsed = 0;
script = script_; script = script_;
updateRenderingStatusMethod = update_method_; updateRenderingStatusMethod = update_method_;
process = null;
askForRendererKill = false; askForRendererKill = false;
render = new RenderProcess();
}
public RenderProcess getProcessRender() {
return render;
} }
public String toString() { public String toString() {
return String.format("Job (numFrame '%s' sceneMD5 '%s' rendererMD5 '%s' ID '%s' revision '%s' pictureFilename '%s' jobPath '%s' renderDuration '%s', memoryUsed %skB gpu %s extras '%s' updateRenderingStatusMethod '%s')", this.numFrame, this.sceneMD5, this.rendererMD5, this.id, this.revision, this.pictureFilename, this.path, this.renderDuration, this.memoryUsed, this.useGPU, this.extras, this.updateRenderingStatusMethod); return String.format("Job (numFrame '%s' sceneMD5 '%s' rendererMD5 '%s' ID '%s' revision '%s' pictureFilename '%s' jobPath '%s' gpu %s extras '%s' updateRenderingStatusMethod '%s' render %s)", numFrame, sceneMD5, rendererMD5, id, revision, pictureFilename, path, useGPU, extras, updateRenderingStatusMethod, render);
} }
public String getId() { public String getId() {
@@ -112,30 +111,6 @@ public class Job {
return askForRendererKill; return askForRendererKill;
} }
public void setProcess(Process val) {
process = val;
}
public Process getProcess() {
return process;
}
public long getMemoryUsed() {
return memoryUsed;
}
public void setMemoryUsed(long val) {
memoryUsed = val;
}
public int getRenderDuration() {
return renderDuration;
}
public void setRenderDuration(int val) {
renderDuration = val;
}
public String getRenderCommand() { public String getRenderCommand() {
return rendererCommand; return rendererCommand;
} }

View File

@@ -0,0 +1,105 @@
/*
* Copyright (C) 2015 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;
import java.util.Date;
public class RenderProcess {
private long start;
private long end;
private long memoryUsed; // in kB
private Process process;
public RenderProcess() {
process = null;
start = -1;
end = -1;
memoryUsed = 0;
}
public void setMemoryUsed(long val) {
memoryUsed = val;
}
public long getMemoryUsed() {
return memoryUsed;
}
public long getStartTime() {
return start;
}
public long getEndTime() {
return end;
}
/**
*
* @return duration in seconds
*/
public int getDuration() {
if (start != -1 && end != -1) {
return (int) ((end - start) / 1000);
}
else if (start != -1) {
return (int) ((new Date().getTime() - start) / 1000);
}
return 0;
}
public void finish() {
end = new Date().getTime();
process = null;
}
public void start() {
start = new Date().getTime();
}
public int exitValue() {
int value = 0;
if (process == null) {
return -1;
}
try {
value = process.exitValue();
}
catch (IllegalThreadStateException e) {
// the process is not finished yet
value = 0;
}
catch (Exception e) {
// actually is for java.io.IOException: GetExitCodeProcess error=6, The handle is invalid
// it was not declared throwable
// the process is not finished yet
value = 0;
}
return value;
}
public void setProcess(Process val) {
process = val;
}
public Process getProcess() {
return process;
}
}

View File

@@ -128,8 +128,8 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
if (ret == ServerCode.KEEPMEALIVE_STOP_RENDERING) { if (ret == ServerCode.KEEPMEALIVE_STOP_RENDERING) {
this.log.debug("Server::keeepmealive server asked to kill local render process"); this.log.debug("Server::keeepmealive server asked to kill local render process");
// kill the current process, it will generate an error but it's okay // kill the current process, it will generate an error but it's okay
if (this.client != null && this.client.getRenderingJob() != null && this.client.getRenderingJob().getProcess() != null) { if (this.client != null && this.client.getRenderingJob() != null && this.client.getRenderingJob().getProcessRender().getProcess() != null) {
OS.getOS().kill(this.client.getRenderingJob().getProcess()); OS.getOS().kill(this.client.getRenderingJob().getProcessRender().getProcess());
this.client.getRenderingJob().setAskForRendererKill(true); this.client.getRenderingJob().setAskForRendererKill(true);
} }
} }