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

Gazebo 9 profiler - take 2 #2813

Merged
merged 18 commits into from
Aug 11, 2020
Merged
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
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 Gazebo Profiler" FALSE)

if(ENABLE_PROFILER)
add_definitions("-DGZ_PROFILER_ENABLE=1")
else()
add_definitions("-DGZ_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 @@ -254,7 +262,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
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 "gazebo/common/Profiler.hh"

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

this->dataPtr->initialized = true;

GZ_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)
{
GZ_PROFILE("Server::Run");
GZ_PROFILE_BEGIN("ProcessControlMsgs");
if (this->dataPtr->lockstep)
rendering::wait_for_render_request("", 0.100);

this->ProcessControlMsgs();
GZ_PROFILE_END();

if (physics::worlds_running())
{
GZ_PROFILE_BEGIN("run_once");
sensors::run_once();
GZ_PROFILE_END();
}
else if (sensors::running())
{
GZ_PROFILE_BEGIN("stop");
sensors::stop();
GZ_PROFILE_END();
}

if (!this->dataPtr->lockstep)
common::Time::MSleep(1);
Expand Down
63 changes: 63 additions & 0 deletions gazebo/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,62 @@ if (HAVE_IGNITION_FUEL_TOOLS)
)
endif()

# Start profiler
set (sources ${sources}
Profiler.cc
)

set (remotery_sources
./Remotery/lib/Remotery.c
./Remotery/lib/Remotery.h
RemoteryProfilerImpl.cc
)

if (APPLE)
set (remotery_sources ${remotery_sources}
./Remotery/lib/RemoteryMetal.mm
)
find_library(FOUNDATION Foundation
HINTS /System/Library/Frameworks
)
endif()

list(APPEND sources ${remotery_sources})

set(RMT_ENABLED 1)
set(RMT_USE_TINYCRT 0)
set(RMT_USE_CUDA 0)
set(RMT_USE_D3D11 0)
set(RMT_USE_OPENGL 0)
set(RMT_USE_METAL 0)

if(UNIX OR WIN32)
set(RMT_USE_OPENGL 1)
endif()

if(WIN32)
set(RMT_USE_D3D11 1)
endif()

if(APPLE)
set (RMT_USE_METAL 1)
endif()

configure_file(RemoteryConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/RemoteryConfig.h)

set(GZ_PROFILER_VIS_PATH share/gazebo-${GAZEBO_MAJOR_VERSION}/profiler_vis)

configure_file(Remotery/gz_remotery_vis.in
${CMAKE_CURRENT_BINARY_DIR}/gz_remotery_vis)

install(PROGRAMS
${CMAKE_CURRENT_BINARY_DIR}/gz_remotery_vis
DESTINATION bin)

install(DIRECTORY Remotery/vis/
DESTINATION ${CMAKE_INSTALL_PREFIX}/${GZ_PROFILER_VIS_PATH})
# End profiler

gz_build_tests(${gtest_sources} EXTRA_LIBS gazebo_common ${tinyxml_LIBRARIES})

set (common_headers "")
Expand Down Expand Up @@ -262,8 +318,15 @@ target_link_libraries(gazebo_common
${TBB_LIBRARIES}
${SDFormat_LIBRARIES}
${IGNITION-FUEL_TOOLS_LIBRARIES}
${PROFILER_LIBRARIES}
)

if(ENABLE_PROFILER)
target_compile_definitions(gazebo_common
PRIVATE BUILDING_DLL_GZ_PROFILER
)
endif()

if (UNIX)
target_link_libraries(gazebo_common pthread)
endif()
Expand Down
85 changes: 85 additions & 0 deletions gazebo/common/Profiler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2018 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/*
This is a backport of Ignition Common's profiler
*/

#include "Profiler.hh"
#include "ProfilerImpl.hh"
#include "RemoteryProfilerImpl.hh"

using namespace gazebo::common;

//////////////////////////////////////////////////
Profiler::Profiler():
impl(nullptr)
{
impl = new RemoteryProfilerImpl();
}

//////////////////////////////////////////////////
Profiler::~Profiler()
{
if (this->impl)
delete this->impl;
this->impl = nullptr;
}

//////////////////////////////////////////////////
void Profiler::SetThreadName(const char * _name)
{
if (this->impl)
this->impl->SetThreadName(_name);
}

//////////////////////////////////////////////////
void Profiler::LogText(const char * _text)
{
if (this->impl)
this->impl->LogText(_text);
}

//////////////////////////////////////////////////
void Profiler::BeginSample(const char * _name, uint32_t* _hash)
{
if (this->impl)
this->impl->BeginSample(_name, _hash);
}

//////////////////////////////////////////////////
void Profiler::EndSample()
{
if (this->impl)
this->impl->EndSample();
}

//////////////////////////////////////////////////
std::string Profiler::ImplementationName() const
{
if (this->impl)
return this->impl->Name();
else
return "disabled";
}


//////////////////////////////////////////////////
bool Profiler::Valid() const
{
return this->impl != nullptr;
}
Loading