Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

[Gazebo 11] Added ignition common profiler #2776

Merged
merged 12 commits into from
Jul 29, 2020
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ if(NOT DEFINED BUILD_TESTING)
set(BUILD_TESTING OFF)
endif()

option(ENABLE_PROFILER "Enable Ignition Profiler" FALSE)

if(ENABLE_PROFILER)
add_definitions("-DIGN_PROFILER_ENABLE=1")
else()
add_definitions("-DIGN_PROFILER_ENABLE=0")
endif()

#============================================================================
# We turn off extensions because (1) we do not ever want to use non-standard
# compiler extensions, and (2) this variable is on by default, causing cmake
Expand Down Expand Up @@ -260,7 +268,11 @@ filter_valid_compiler_flags(${WARN_LEVEL}
# Check and add visibility hidden by default. Only in UNIX
# Windows and MacosX does not handled properly the hidden compilation
if (UNIX AND NOT APPLE)
filter_valid_compiler_flags(-fvisibility=hidden -fvisibility-inlines-hidden)
if (ENABLE_PROFILER)
filter_valid_compiler_flags(-fvisibility-inlines-hidden)
else()
filter_valid_compiler_flags(-fvisibility=hidden -fvisibility-inlines-hidden)
endif()
endif()

if (MSVC)
Expand Down
5 changes: 5 additions & 0 deletions gazebo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ add_dependencies(gazebo_sensors gazebo_rendering)

gz_add_executable(gzserver server_main.cc)

if (${ENABLE_PROFILER})
set(IGN_PROFILE_LIBS ${IGNITION-COMMON_LIBRARIES})
endif()

target_link_libraries(gzserver
libgazebo
gazebo_common
Expand All @@ -64,6 +68,7 @@ target_link_libraries(gzserver
${freeimage_LIBRARIES}
${TBB_LIBRARIES}
${ogre_libraries}
${IGN_PROFILE_LIBS}
)

if (UNIX)
Expand Down
13 changes: 13 additions & 0 deletions gazebo/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <sdf/sdf.hh>

#include <ignition/math/Rand.hh>
#include "ignition/common/Profiler.hh"

#include "gazebo/gazebo.hh"
#include "gazebo/transport/transport.hh"
Expand Down Expand Up @@ -596,22 +597,34 @@ void Server::Run()

this->dataPtr->initialized = true;

IGN_PROFILE_THREAD_NAME("gzserver");
// Stay on this loop until Gazebo needs to be shut down
// The server and sensor manager outlive worlds
while (!this->dataPtr->stop)
{
IGN_PROFILE("Server::Run");
IGN_PROFILE_BEGIN("ProcessControlMsgs");
if (this->dataPtr->lockstep)
rendering::wait_for_render_request("", 0.100);
// bool ret = rendering::wait_for_render_request("", 0.100);
// if (ret == false)
// gzerr << "time out reached!" << std::endl;

this->ProcessControlMsgs();
IGN_PROFILE_END();

if (physics::worlds_running())
{
IGN_PROFILE_BEGIN("run_once");
sensors::run_once();
IGN_PROFILE_END();
}
else if (sensors::running())
{
IGN_PROFILE_BEGIN("stop");
sensors::stop();
IGN_PROFILE_END();
}

if (!this->dataPtr->lockstep)
common::Time::MSleep(1);
Expand Down
1 change: 1 addition & 0 deletions gazebo/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ target_link_libraries(gazebo_common
ignition-common3::graphics
${IGNITION-FUEL_TOOLS_LIBRARIES}
${IGNITION-MATH_LIBRARIES}
${IGNITION-COMMON_LIBRARIES}
${libdl_library}
${libtar_LIBRARIES}
${SDFormat_LIBRARIES}
Expand Down
68 changes: 65 additions & 3 deletions gazebo/common/Event.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
#include <memory>
#include <mutex>

#include <gazebo/gazebo_config.h>
#include <gazebo/common/Time.hh>
#include <gazebo/common/CommonTypes.hh>
#include "gazebo/gazebo_config.h"
#include "gazebo/common/Time.hh"
#include "gazebo/common/CommonTypes.hh"
#include "gazebo/util/system.hh"

#include "ignition/common/Profiler.hh"

namespace gazebo
{
/// \ingroup gazebo_event
Expand Down Expand Up @@ -268,13 +270,19 @@ namespace gazebo
/// \brief Signal the event for all subscribers.
public: void Signal()
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback0");
iter.second->callback();
IGN_PROFILE_END();
}
}
}

Expand All @@ -283,13 +291,19 @@ namespace gazebo
public: template< typename P >
void Signal(const P &_p)
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback1");
iter.second->callback(_p);
IGN_PROFILE_END();
}
}
}

Expand All @@ -299,13 +313,19 @@ namespace gazebo
public: template< typename P1, typename P2 >
void Signal(const P1 &_p1, const P2 &_p2)
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback2");
iter.second->callback(_p1, _p2);
IGN_PROFILE_END();
}
}
}

Expand All @@ -316,13 +336,19 @@ namespace gazebo
public: template< typename P1, typename P2, typename P3 >
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3)
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback3");
iter.second->callback(_p1, _p2, _p3);
IGN_PROFILE_END();
}
}
}

Expand All @@ -335,13 +361,19 @@ namespace gazebo
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3,
const P4 &_p4)
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback4");
iter.second->callback(_p1, _p2, _p3, _p4);
IGN_PROFILE_END();
}
}
}

Expand All @@ -356,13 +388,19 @@ namespace gazebo
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3,
const P4 &_p4, const P5 &_p5)
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback5");
iter.second->callback(_p1, _p2, _p3, _p4, _p5);
IGN_PROFILE_END();
}
}
}

Expand All @@ -378,13 +416,19 @@ namespace gazebo
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3,
const P4 &_p4, const P5 &_p5, const P6 &_p6)
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback6");
iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6);
IGN_PROFILE_END();
}
}
}

Expand All @@ -401,13 +445,19 @@ namespace gazebo
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3,
const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7)
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback7");
iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
IGN_PROFILE_END();
}
}
}

Expand All @@ -426,14 +476,18 @@ namespace gazebo
const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7,
const P8 &_p8)
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback8");
iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
IGN_PROFILE_END();
}
}
}
Expand All @@ -455,15 +509,19 @@ namespace gazebo
const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7,
const P8 &_p8, const P9 &_p9)
{
IGN_PROFILE("Event::Signal");

this->Cleanup();

this->SetSignaled(true);
for (const auto &iter: this->connections)
{
if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback9");
iter.second->callback(
_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
IGN_PROFILE_END();
}
}
}
Expand Down Expand Up @@ -491,10 +549,14 @@ namespace gazebo
this->SetSignaled(true);
for (const auto &iter: this->connections)
{
IGN_PROFILE("Event::Signal");

if (iter.second->on)
{
IGN_PROFILE_BEGIN("callback10");
iter.second->callback(
_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
IGN_PROFILE_END();
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions gazebo/physics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,18 @@ target_compile_definitions(gazebo_physics
PRIVATE BUILDING_DLL_GZ_PHYSICS
)

if (${ENABLE_PROFILER})
set(IGN_PROFILE_LIBS ${IGNITION-COMMON_LIBRARIES})
endif()

target_link_libraries(gazebo_physics
gazebo_common
gazebo_util
gazebo_ode
gazebo_opcode
${Boost_LIBRARIES}
${IGNITION-TRANSPORT_LIBRARIES}
${IGN_PROFILE_LIBS}
)

# Link in Bullet support if present
Expand Down
Loading