Profile Rep

Hello, I’d like to time how long it takes my rep to complete all it’s renders. Any ideas on how I could check when it’s done? Maybe some event handler I could keep track of?

Bump bump bump

Hi @lelandplusplus Can you give a bit more information on the script you’d like to profile/time? If you’re running a script, you could use something like this:

import time

frame_count = 10

tic = time.perf_counter()
toc = time.perf_counter()

print(f"COMPLETE - {frame_count} frames, {frame_count/(toc - tic):0.2f} fps ")

Hey @pcallender, thanks for getting back to me!

I did end up implementing a solution like this:

class Timer:
    total_time = 0

def time_it(method):
    def timed(*args,**kw):
        ts = time.time()
        result = method(*args, **kw)
        te = time.time()
        elapsed_time = te-ts
        Timer.total_time += elapsed_time
        print("____________________________________________________________")
        print(f"{method.__name__} took {elapsed_time:.6f} sec")
        print(f"Total time: {Timer.total_time:.6f} sec")
        return result
    return timed

def time_method(method_name):
    def class_decorator(cls):
        orig_method = getattr(cls,method_name)
        setattr(cls, method_name, time_it(orig_method))
        return cls
    return class_decorator

def some_event():
    from  omni.replicator.core import BasicWriter
    TimedWriter = time_method('write')(BasicWriter)
    # Use replicator to render

Results aren’t bad for an astronaut, here are the last two writes on 100 writes of the astronaut on a NVIDIA GeForce RTX 3090 Ti.

____________________________________________________________
write took 0.000271 sec
Total time: 0.036470 sec
____________________________________________________________
write took 0.000285 sec
Total time: 0.036755 sec

Now I’m trying to wrap the Renderer.render with the the same but I’m hitting an error on importing the Render class from “app/extscache/omni.services.pip_archive-0.4.3/pip_prebundle/omniverse_idl/idl/templates/renderer.py line 12”:

from idl.templates.renderer import Renderer

It looks like Code doesn’t have access to idl. Is there a way for me to install this or otherwise reference it so that it doesn’t throw this exception:

2023-10-13 19:15:55 [Error] [omni.ext._impl.custom_importer] Failed to import python module manifold.renderer. Error: No module named 'idl'. Traceback:

Hi @leland.fowler.chem Not sure about the failed import, but here’s another possible way to tackle profiling the capture time. I asked around and creating a callback on the orchestrator seems like a decent way to go. I’ll also put in a feature request for debug info like this to be optionally printed out.

import omni.replicator.core as rep
import time

camera_positions = [(1347,825,1440), (0, 825, 1440),(1440,825,0)]

# Create the lights
distance_light = rep.create.light(rotation=(400,-23,-94), intensity=10000, temperature=6500, light_type="distant")
cylinder_light = rep.create.light(position=(0,0,0),rotation=(0,-180,-180),light_type="disk")

# Create the environment
cone = rep.create.cone(position=(0,100,0), scale=2)
floor = rep.create.cube(position=(0,0,0), scale=(10,0.1,10))
wall1 = rep.create.cube(position=(-450,250,0), scale=(1,5,10))
wall2 = rep.create.cube(position=(0,250,-450), scale=(10,5,1))

#Create the replicator camera
camera = rep.create.camera(position=(1347,825,1440), look_at=(0,100,0), focus_distance=200,f_stop=8)

# Set the renderer to Path Traced
rep.settings.set_render_pathtraced(samples_per_pixel=64)

# Create the render product
render_product  = rep.create.render_product(camera, (1920, 1080))

# Initialize and attach writer
writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(output_dir="_subframes_pt_example", rgb=True)
writer.attach([render_product])

time_list = []

def my_callback(status):
    print(f"Orchestrator Status: {status}")
    if (str(status) == 'Status.STARTED'):
        time_list.append(time.perf_counter())
    
    if (str(status) == 'Status.STOPPED'):
        time_list.append(time.perf_counter())
        print(f"COMPLETE - {(time_list[1] - time_list[0]):0.2f} s elapsed")

# register callback
my_callback = rep.orchestrator.register_status_callback(my_callback)

# Render 3 frames, with 50 subframes
with rep.trigger.on_frame(num_frames=3, rt_subframes=50):
    with camera:
        rep.modify.pose(position=rep.distribution.sequence(camera_positions), look_at=(0,100,0))
1 Like

Hey @pcallender, elegant solution!

I hadn’t grokked the orchestrator yet but I’d been originally hoping that I could define a callback just as you described.

Thanks a bunch pcallender!

@pcallender, I’m able to run your code and then run the replicator and get the images without errors but I can’t seem to get the terminal output. Is there something I need to do to capture that?

This is all I’m seeing:

[14.315s] RTX ready
[company.hello.world] MyExtension startup
Clicked Renderer
Clicked Renderer

Just tested in Code 2023.1.1. This is the output I see in the script editor:

image

In the console, you ought to be able to see the printouts by selecting verbose (and in this case I added a search filter since verbose shows everything)

Hope this helps!

1 Like

Yep works in script editor! Not sure what’s up in my VsCode bit this is a good place to figure it out. Thanks again @pcallender!