Skip to content

Commit

Permalink
Merge branch 'gazebo9' into ahcorde/publish/performance_metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ahcorde authored Aug 11, 2020
2 parents 328cd28 + be44390 commit 10c527a
Show file tree
Hide file tree
Showing 80 changed files with 16,121 additions and 19 deletions.
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
6 changes: 5 additions & 1 deletion cmake/GazeboUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ endmacro()
#################################################
macro (gz_install_library _name)
set_target_properties(${_name} PROPERTIES SOVERSION ${GAZEBO_MAJOR_VERSION} VERSION ${GAZEBO_VERSION_FULL})
install (TARGETS ${_name} DESTINATION ${LIB_INSTALL_DIR} COMPONENT shlib)
install (TARGETS ${_name}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
COMPONENT shlib)
endmacro ()

#################################################
Expand Down
6 changes: 6 additions & 0 deletions examples/stand_alone/custom_main_pkgconfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ link_directories(${GAZEBO_LIBRARY_DIRS})

add_executable(custom_main custom_main.cc)
target_link_libraries(custom_main ${GAZEBO_LIBRARIES})

if(${CMAKE_VERSION} VERSION_LESS "3.13.0")
link_directories(${Boost_LIBRARY_DIRS})
else()
target_link_directories(custom_main PUBLIC ${Boost_LIBRARY_DIRS})
endif()
14 changes: 14 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 @@ -710,19 +711,32 @@ void Server::Run()
this->dataPtr->node->Advertise<msgs::PerformanceMetrics>(
"~/performance_metrics", 100, 5);

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();
}

PublishPerformanceMetrics();

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
4 changes: 4 additions & 0 deletions gazebo/common/Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ void Material::SetTextureImage(const std::string &_tex,
}
}
}

// normalize the path
this->texImage = boost::filesystem::path(this->texImage)
.make_preferred().string();
}

//////////////////////////////////////////////////
Expand Down
19 changes: 14 additions & 5 deletions gazebo/common/ModelDatabase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,28 @@ std::string ModelDatabase::GetModelPath(const std::string &_uri,
continue;
}

std::string outputPath = getenv("HOME");
outputPath += "/.gazebo/models";

#ifndef _WIN32
TAR *tar;
tar_open(&tar, const_cast<char*>(tarfilename.c_str()),
nullptr, O_RDONLY, 0644, TAR_GNU);

std::string outputPath = getenv("HOME");
outputPath += "/.gazebo/models";

tar_extract_all(tar, const_cast<char*>(outputPath.c_str()));
#else
// Tar now is a built-in tool since Windows 10 build 17063.
std::string cmdline = "tar xzf \"";
cmdline += tarfilename + "\" -C \"";
cmdline += outputPath + "\"";
auto ret = system(cmdline.c_str());
if (ret != 0)
{
gzerr << "tar extract ret = " << ret << ", cmdline = " << cmdline << std::endl;
}
#endif
path = outputPath + "/" + modelName;

ModelDatabase::DownloadDependencies(path);
#endif
}

curl_easy_cleanup(curl);
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

0 comments on commit 10c527a

Please sign in to comment.