Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add performance profiling suite #546

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
"request": "launch"
}
]
}
}
21 changes: 21 additions & 0 deletions apps/cesium.omniverse.dev.trace.suite.kit
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
title = "Cesium For Omniverse Performance Tracing Suite App"
version = "0.0.0"
app = true

[dependencies]
"cesium.omniverse.dev.trace" = {}
"cesium.profiling.app" = {}

[settings]
app.window.title = "Cesium For Omniverse Performance Tracing Suite App"
app.useFabricSceneDelegate = true
app.runProfilingScenes = true

[settings.app.exts]
folders.'++' = [
"${app}", # Find other applications in this folder
"${app}/exts", # Find extensions in this folder
"${app}/../exts", # Find cesium.omniverse and cesium.usd.schemas
"${app}/../extern/nvidia/app/extscache" # Find omni.kit.window.material_graph
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .extension import * # noqa: F401 F403
68 changes: 68 additions & 0 deletions apps/exts/cesium.profiling.app/cesium/profiling/app/extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import carb.settings
import asyncio
from cesium.omniverse.utils import perform_action_after_n_frames_async
from cesium.omniverse.utils.cesium_interface import CesiumInterfaceManager
import omni.ext
import omni.usd
import omni.kit
import omni.kit.commands
import logging
import os


class CesiumProfilingExtension(omni.ext.IExt):

def __init__(self):
super().__init__()

self._logger: logging.Logger = logging.getLogger(__name__)

def on_startup(self, ext_id):
settings = carb.settings.get_settings()
if (settings.get("/app/runProfilingScenes")):
FRAMES_BEFORE_TESTING_BEGINS = 120
asyncio.ensure_future(perform_action_after_n_frames_async(FRAMES_BEFORE_TESTING_BEGINS,
self._run_profiling_suite))

def _run_profiling_suite(self):
asyncio.ensure_future(self._run_profiling_suite_async())

def _stop_profiler(self):
with CesiumInterfaceManager() as interface:
interface.shut_down_profiling()

def _start_profiler(self, file_basename):
with CesiumInterfaceManager() as interface:
interface.initialize_profiling(file_basename)

def _get_profiling_files(self, directory_path):
files = []
files_in_directory = os.listdir(directory_path)
for file_name in files_in_directory:
if file_name.endswith('.usdc'):
usd_file_path = os.path.join(directory_path, file_name)
files.append(usd_file_path)
return files

async def _run_profiling_suite_async(self):
self._stop_profiler()

scene_test_duration = 20
between_test_scene_duration = 5
current_working_directory = os.getcwd()
test_directory = os.path.join(current_working_directory, "tests/testAssets/usd/flattened")
profiling_usd_files = self._get_profiling_files(test_directory)

for usd_file in profiling_usd_files:
file_basename = os.path.splitext(os.path.basename(usd_file))[0]
stage = omni.usd.get_context().open_stage(usd_file)
if stage:
self._start_profiler(file_basename)
omni.kit.commands.execute('ToolbarPlayButtonClicked')
await asyncio.sleep(scene_test_duration)
omni.kit.commands.execute('ToolbarStopButtonClicked')
omni.usd.get_context().close_stage()
self._stop_profiler()
await asyncio.sleep(between_test_scene_duration)
else:
self._logger.warning("Could not open file" + usd_file)
11 changes: 11 additions & 0 deletions apps/exts/cesium.profiling.app/config/extension.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
title = "Cesium for Omniverse Performance Profiling Extension"
version = "0.0.0"
app = false
toggleable = false

[dependencies]
"cesium.omniverse" = {}

[[python.module]]
name = "cesium.profiling.app"
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ICesiumOmniverseInterface:
def get_render_statistics(self, *args, **kwargs) -> Any: ...
def get_session(self, *args, **kwargs) -> Any: ...
def get_set_default_token_result(self, *args, **kwargs) -> Any: ...
def initialize_profiling(self, arg0: str) -> None: ...
def is_default_token_set(self) -> bool: ...
def is_tracing_enabled(self) -> bool: ...
def on_shutdown(self) -> None: ...
Expand All @@ -92,6 +93,7 @@ class ICesiumOmniverseInterface:
def reload_tileset(self, arg0: str) -> None: ...
def select_token(self, arg0: str, arg1: str) -> None: ...
def set_georeference_origin(self, arg0: float, arg1: float, arg2: float) -> None: ...
def shut_down_profiling(self) -> None: ...
def specify_token(self, arg0: str) -> None: ...
@overload
def update_troubleshooting_details(self, arg0: str, arg1: int, arg2: int, arg3: int) -> None: ...
Expand Down
2 changes: 2 additions & 0 deletions include/cesium/omniverse/CesiumOmniverse.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class ICesiumOmniverseInterface {
*/
virtual void addGlobeAnchorToPrim(const char* path, double latitude, double longitude, double height) noexcept = 0;
virtual bool isTracingEnabled() noexcept = 0;
virtual void initializeProfiling(const char* path) noexcept = 0;
virtual void shutDownProfiling() noexcept = 0;
};

} // namespace cesium::omniverse
4 changes: 3 additions & 1 deletion src/bindings/PythonBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ PYBIND11_MODULE(CesiumOmniversePythonBindings, m) {
.def("credits_start_next_frame", &ICesiumOmniverseInterface::creditsStartNextFrame)
.def("is_tracing_enabled", &ICesiumOmniverseInterface::isTracingEnabled)
.def("add_global_anchor_to_prim", py::overload_cast<const char*>(&ICesiumOmniverseInterface::addGlobeAnchorToPrim))
.def("add_global_anchor_to_prim", py::overload_cast<const char*, double, double, double>(&ICesiumOmniverseInterface::addGlobeAnchorToPrim));
.def("add_global_anchor_to_prim", py::overload_cast<const char*, double, double, double>(&ICesiumOmniverseInterface::addGlobeAnchorToPrim))
.def("initialize_profiling", &ICesiumOmniverseInterface::initializeProfiling)
.def("shut_down_profiling", &ICesiumOmniverseInterface::shutDownProfiling);
// clang-format on

py::class_<CesiumIonSession, std::shared_ptr<CesiumIonSession>>(m, "CesiumIonSession")
Expand Down
23 changes: 23 additions & 0 deletions src/core/include/cesium/omniverse/Profiler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

namespace cesium::omniverse {

class Profiler {
public:
Profiler(const Profiler&) = delete;
Profiler(Profiler&&) = delete;

static Profiler& getInstance() {
static Profiler instance;
return instance;
}

void initializeProfiling(const char* fileIdentifier);
void shutDownProfiling();

private:
Profiler() = default;
~Profiler() = default;
};

} // namespace cesium::omniverse
23 changes: 23 additions & 0 deletions src/core/src/Profiler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "cesium/omniverse/Profiler.h"

#include "cesium/omniverse/Context.h"

#include <CesiumUtility/Tracing.h>
#include <spdlog/fmt/fmt.h>

#include <chrono>

namespace cesium::omniverse {

void Profiler::initializeProfiling(const char* fileIdentifier) {
const auto timeNow = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::steady_clock::now());
const auto timeSinceEpoch = timeNow.time_since_epoch().count();
auto cesiumExtensionLocation = Context::instance().getCesiumExtensionLocation();
const auto profileFilePath =
cesiumExtensionLocation / fmt::format("cesium-trace-{}-{}.json", fileIdentifier, timeSinceEpoch);
CESIUM_TRACE_INIT(profileFilePath.string());
}
void Profiler::shutDownProfiling() {
CESIUM_TRACE_SHUTDOWN();
}
} // namespace cesium::omniverse
9 changes: 9 additions & 0 deletions src/public/CesiumOmniverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "cesium/omniverse/Context.h"
#include "cesium/omniverse/FabricUtil.h"
#include "cesium/omniverse/OmniTileset.h"
#include "cesium/omniverse/Profiler.h"
#include "cesium/omniverse/UsdUtil.h"
#include "cesium/omniverse/Viewport.h"

Expand Down Expand Up @@ -156,6 +157,14 @@ class CesiumOmniversePlugin final : public ICesiumOmniverseInterface {
return false;
#endif
}

void initializeProfiling(const char* path) noexcept override {
Profiler::getInstance().initializeProfiling(path);
}

void shutDownProfiling() noexcept override {
Profiler::getInstance().shutDownProfiling();
}
};
} // namespace cesium::omniverse

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.