Ejemplo n.º 1
0
def test_env_var_enable():
    # test with env var not set
    os.environ.pop(_ENV_VAR_NAME, None)
    importlib.reload(profiling_utils)
    assert not profiling_utils._enable_profiling
    # We also call range_push/range_pop to verify they run without error.
    profiling_utils.range_push("test, env var not set")
    assert profiling_utils._helper.range_depth == 0
    profiling_utils.range_pop()

    # test with env var set to "0". This is equivalent to
    # `export HABITAT_PROFILING=0` on the command line.
    os.environ[_ENV_VAR_NAME] = "0"
    importlib.reload(profiling_utils)
    assert not profiling_utils._enable_profiling
    profiling_utils.range_push("test, HABITAT_PROFILING='0'")
    assert profiling_utils._helper.range_depth == 0
    profiling_utils.range_pop()

    # test with env var set to "1"
    os.environ[_ENV_VAR_NAME] = "1"
    importlib.reload(profiling_utils)
    assert profiling_utils._enable_profiling
    profiling_utils.range_push("test, HABITAT_PROFILING=True")
    assert profiling_utils._helper.range_depth == 1
    profiling_utils.range_pop()
Ejemplo n.º 2
0
def test_nested_range_push_pop():
    os.environ[_ENV_VAR_NAME] = "1"
    importlib.reload(profiling_utils)

    assert profiling_utils._helper.range_depth == 0
    profiling_utils.range_push("A")
    profiling_utils.range_push("B")
    profiling_utils.range_push("C")
    assert profiling_utils._helper.range_depth == 3
    profiling_utils.range_pop()
    profiling_utils.range_pop()
    profiling_utils.range_pop()
    assert profiling_utils._helper.range_depth == 0
Ejemplo n.º 3
0
def test_nested_range_push_pop():
    # Unfortunately, there isn't a way to verify correct behavior here. Ranges
    # get recorded in the Nvidia driver/profiler. Documentation for
    # torch.cuda.nvtx.range_push claims that it returns range stack depth, so I
    # hoped to use it as a behavior checker, but it seems to just return -1 or
    # -2 in practice.

    os.environ[env_var_name] = "1"
    importlib.reload(profiling_utils)

    profiling_utils.range_push("A")
    profiling_utils.range_push("B")
    profiling_utils.range_push("C")
    profiling_utils.range_pop()
    profiling_utils.range_pop()
    profiling_utils.range_pop()
def range_pop():
    r"""Wrapper for habitat_sim profiling_utils.range_pop"""
    if profiling_utils:
        profiling_utils.range_pop()
Ejemplo n.º 5
0
 def __exit__(self, *exc):
     elapsed = time.time() - self.start_time
     self.add_time_f(self.timer_name, elapsed)
     if profiling_utils is not None:
         profiling_utils.range_pop()
     return False