Script to Gather Peak RAM Usage after job

Hi,

I’m trying to write a script that will gather the Peak RAM Usage of all the tasks of a job and email it to the artist when the job is complete. I’m in Deadline 6.2.1

The event and email part I can handle, but I’m having trouble finding a way to get the PeakRAMUsage.

I think it may just be my small amount of Python scripting, but I’ve looked through every piece of documentation for Python in Deadline and came up with GetJobTasks which returns, among other things, the PeakRamUsage for tasks if I use it in the web service, but I can’t figure out how to get it to work in Deadline.

Could someone please just give me a clue, example, as to which module(s) to import, and what it should look like, if I wanted to just print the result of GetJobTasks or something simple.

Sorry that this is kind of a clueless question.

Thanks,
A

Hi,
Here’s an example that’s close to what your after:
github.com/ThinkboxSoftware/Dea … /FarmStats

So, here’s a working example to calculate the Peak RAM usage per completed job (I assume you mean by job and not all the peak RAM values per task, as your only interested in Peak?):

[code]from Deadline.Scripting import *
from Deadline.Jobs import *

def main():

print "Script Started..."

for job in RepositoryUtils.GetJobs( True ):
    # Filter completed jobs
    if job.JobStatus != "Completed":
        continue

    jobId = job.JobId

    job = RepositoryUtils.GetJob( jobId, True )
    tasks = RepositoryUtils.GetJobTasks( job, True )
    stats = JobUtils.CalculateJobStatistics( job, tasks )

    jobPeakRamUsage = stats.PeakRamUsage/1024/1024
    print "JobPeakRamUsage: %sMb" % jobPeakRamUsage

print "...Script Completed"[/code]

Copy the code into a file and call it something like: “PeakRamUsage.py” and execute it via DeadlineCommand like this:

DeadlineCommand.exe -ExecuteScript “/path/to/PeakRamUsage.py”

Hi Mike,

Thanks for the reply. This is super helpful!

Executing via Deadline Command works fine, but is there a way to get it to work in an event script so I can have it run when a job completes?

Testing via the Job script menu in Deadline for something that would just print the PeakRamUsage (small steps) yields an error:

2015-03-27 13:15:59: File “DeadlineUI\UI\Commands\ScriptCommands.py”, line 88, in InnerExecute
2015-03-27 13:15:59: Exception: Python Error: TypeError : No method matches given arguments (Python.Runtime.PythonException)
2015-03-27 13:15:59: Stack Trace:
2015-03-27 13:15:59: File “none”, line 7, in main
2015-03-27 13:15:59:
2015-03-27 13:15:59:
2015-03-27 13:15:59: at FranticX.Scripting.PythonNetScriptEngine.HandlePythonError(Exception e)
2015-03-27 13:15:59: at FranticX.Scripting.PythonNetScriptEngine.CallFunction(String functionName, PyObject[] args)
2015-03-27 13:15:59: at Deadline.Scripting.DeadlineScriptManager.CallFunction(String scopeName, String functionName)

from Deadline.Scripting import *
from Deadline.Jobs import *

def __main__():

    jobId = MonitorUtils.GetSelectedJobIds()
    job = RepositoryUtils.GetJob( jobId, True )
    tasks = RepositoryUtils.GetJobTasks( job, True )
    stats = JobUtils.CalculateJobStatistics( job, tasks )
    
    jobAverageFrameRenderTime = stats.AverageFrameRenderTime
    jobPeakRamUsage = stats.PeakRamUsage/1024/1024/1024
    
    print "JobAverageFrameRenderTime: %s" %  jobAverageFrameRenderTime
    print "JobPeakRamUsage: %s" % jobPeakRamUsage

Thanks,
A

MonitorUtils.GetSelectedJobIds()

returns a list of JobIds, so you would need to loop through them, as you might have more than 1 job selected in the monitor - job panel.

Here’s a job script that works:

[code]from System import TimeSpan

from Deadline.Scripting import *
from Deadline.Jobs import *

def main():

jobIds = MonitorUtils.GetSelectedJobIds()

for jobId in jobIds:
    job = RepositoryUtils.GetJob( jobId, True )
    tasks = RepositoryUtils.GetJobTasks( job, True )
    stats = JobUtils.CalculateJobStatistics( job, tasks )
    
    jobAverageFrameRenderTime = stats.AverageFrameRenderTime
    jobPeakRamUsage = stats.PeakRamUsage/1024/1024

    timeSpan = jobAverageFrameRenderTime
    timeSpan = "%02dd:%02dh:%02dm:%02ds" % (timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds)

    print "JobAverageFrameRenderTime: %s" %  timeSpan
    print "JobPeakRamUsage: %sMb" % jobPeakRamUsage[/code]

See attached for an event plugin as well.
JobStats.zip (2.61 KB)

Thank you!