Report model load time in simulate if it takes more than 0.5 seconds.

PiperOrigin-RevId: 650933302
Change-Id: Id33aa9935a6b4f493dfa9a913f8a424b3f387fa1
This commit is contained in:
Yuval Tassa
2024-07-10 02:55:08 -07:00
committed by Copybara-Service
parent 462cfa5ceb
commit 17f6b12930
+9
View File
@@ -213,6 +213,7 @@ mjModel* LoadModel(const char* file, mj::Simulate& sim) {
// load and compile
char loadError[kErrorLength] = "";
mjModel* mnew = 0;
auto load_start = mj::Simulate::Clock::now();
if (mju::strlen_arr(filename)>4 &&
!std::strncmp(filename + mju::strlen_arr(filename) - 4, ".mjb",
mju::sizeof_arr(filename) - mju::strlen_arr(filename)+4)) {
@@ -222,6 +223,7 @@ mjModel* LoadModel(const char* file, mj::Simulate& sim) {
}
} else {
mnew = mj_loadXML(filename, nullptr, loadError, kErrorLength);
// remove trailing newline character from loadError
if (loadError[0]) {
int error_length = mju::strlen_arr(loadError);
@@ -230,6 +232,13 @@ mjModel* LoadModel(const char* file, mj::Simulate& sim) {
}
}
}
auto load_interval = mj::Simulate::Clock::now() - load_start;
double load_seconds = Seconds(load_interval).count();
// if no error and load took more than 1/2 seconds, report load time
if (!loadError[0] && load_seconds > 0.5) {
mju::sprintf_arr(loadError, "Model loaded in %.1g seconds", load_seconds);
}
mju::strcpy_arr(sim.load_error, loadError);