Esempio 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()
Esempio 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
Esempio 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_push(msg: str):
    r"""Wrapper for habitat_sim profiling_utils.range_push"""
    if profiling_utils:
        profiling_utils.range_push(msg)
Esempio n. 5
0
 def __enter__(self):
     if profiling_utils is not None:
         profiling_utils.range_push(self.timer_name)
     self.start_time = time.time()
     return self