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

Setup profiler #87

Merged
merged 3 commits into from
Nov 29, 2021
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Clone this repository then run
colcon build
```

> You can pass `--cmake-args ' -DENABLE_PROFILER=1'` to use the profiler.
> See more on [this tutorial](https://ignitionrobotics.org/api/common/4.4/profiler.html)

## To test simulation in Ignition standalone (without MBARI integration)

This package comes with an empty example world. To run this example world simply
Expand Down
13 changes: 13 additions & 0 deletions lrauv_ignition_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)

project(lrauv_ignition_plugins)

# Option to enable profiler
option(ENABLE_PROFILER "Enable Ignition Profiler" FALSE)

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

#============================================================================
# Find dependencies
find_package(ignition-cmake2 REQUIRED)
Expand All @@ -31,6 +40,9 @@ set(IGN_PLUGIN_VER ${ignition-plugin1_VERSION_MAJOR})
find_package(ignition-utils1 REQUIRED)
set(IGN_UTILS_VER ${ignition-utils1_VERSION_MAJOR})

find_package(ignition-common4 REQUIRED COMPONENTS profiler)
set(IGN_COMMON_VER ${ignition-common4_VERSION_MAJOR})

find_package (Eigen3 3.3 REQUIRED)

find_package(PCL 1.2 REQUIRED)
Expand Down Expand Up @@ -87,6 +99,7 @@ function(add_lrauv_plugin PLUGIN)
set_property(TARGET ${PLUGIN} PROPERTY CXX_STANDARD 17)
target_link_libraries(${PLUGIN}
PUBLIC
ignition-common${IGN_COMMON_VER}::profiler
ignition-plugin${IGN_PLUGIN_VER}::ignition-plugin${IGN_PLUGIN_VER}
ignition-gazebo${IGN_GAZEBO_VER}::ignition-gazebo${IGN_GAZEBO_VER}
PRIVATE
Expand Down
26 changes: 21 additions & 5 deletions lrauv_ignition_plugins/src/ScienceSensorsSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <ignition/msgs/pointcloud_packed.pb.h>

#include <ignition/common/Profiler.hh>
#include <ignition/common/SystemPaths.hh>
#include <ignition/gazebo/World.hh>
#include <ignition/msgs/Utility.hh>
Expand Down Expand Up @@ -227,6 +228,8 @@ ScienceSensorsSystem::ScienceSensorsSystem()
/////////////////////////////////////////////////
void ScienceSensorsSystemPrivate::ReadData()
{
IGN_PROFILE("ScienceSensorsSystemPrivate::ReadData");

std::fstream fs;
fs.open(this->dataPath, std::ios::in);

Expand Down Expand Up @@ -435,6 +438,7 @@ void ScienceSensorsSystemPrivate::GenerateOctrees()
/////////////////////////////////////////////////
void ScienceSensorsSystemPrivate::PublishData()
{
IGN_PROFILE("ScienceSensorsSystemPrivate::PublishData");
this->cloudPub.Publish(this->PointCloudMsg());
}

Expand All @@ -444,6 +448,8 @@ float ScienceSensorsSystemPrivate::InterpolateData(
std::vector<int> &_inds,
std::vector<float> &_dists)
{
IGN_PROFILE("ScienceSensorsSystemPrivate::InterpolateData");

// Sanity checks
if (_inds.size() == 0 || _dists.size() == 0)
{
Expand Down Expand Up @@ -557,6 +563,9 @@ void ScienceSensorsSystem::PreUpdate(
void ScienceSensorsSystem::PostUpdate(const ignition::gazebo::UpdateInfo &_info,
const ignition::gazebo::EntityComponentManager &_ecm)
{
IGN_PROFILE_THREAD_NAME("ScienceSensorsSystem PostUpdate");
IGN_PROFILE("ScienceSensorsSystem::PostUpdate");

// Only update and publish if data has been loaded and simulation is not
// paused.
if (this->dataPtr->initialized && !_info.paused)
Expand Down Expand Up @@ -609,12 +618,15 @@ void ScienceSensorsSystem::PostUpdate(const ignition::gazebo::UpdateInfo &_info,
std::vector<float> spatialSqrDist;

// Search in octree to find spatial index of science data
if (this->dataPtr->spatialOctrees[this->dataPtr->timeIdx].nearestKSearch(
searchPoint, k, spatialIdx, spatialSqrDist) <= 0)
{
ignwarn << "No data found near sensor location " << sensorLatLon.value()
<< std::endl;
continue;
IGN_PROFILE("ScienceSensorsSystem::PostUpdate nearestKSearch");
if (this->dataPtr->spatialOctrees[this->dataPtr->timeIdx].nearestKSearch(
searchPoint, k, spatialIdx, spatialSqrDist) <= 0)
{
ignwarn << "No data found near sensor location " << sensorLatLon.value()
<< std::endl;
continue;
}
}
// Debug output
/*
Expand Down Expand Up @@ -691,6 +703,8 @@ void ScienceSensorsSystem::PostUpdate(const ignition::gazebo::UpdateInfo &_info,
void ScienceSensorsSystem::RemoveSensorEntities(
const ignition::gazebo::EntityComponentManager &_ecm)
{
IGN_PROFILE("ScienceSensorsSystem::RemoveSensorEntities");

_ecm.EachRemoved<ignition::gazebo::components::CustomSensor>(
[&](const ignition::gazebo::Entity &_entity,
const ignition::gazebo::components::CustomSensor *)->bool
Expand Down Expand Up @@ -722,6 +736,8 @@ bool ScienceSensorsSystemPrivate::ScienceDataService(
//////////////////////////////////////////////////
ignition::msgs::PointCloudPacked ScienceSensorsSystemPrivate::PointCloudMsg()
{
IGN_PROFILE("ScienceSensorsSystemPrivate::PointCloudMsg");

ignition::msgs::PointCloudPacked msg;

if (this->timeIdx < 0 || this->timeIdx >= this->timestamps.size())
Expand Down
3 changes: 3 additions & 0 deletions lrauv_ignition_plugins/src/VisualizePointCloud.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "VisualizePointCloud.hh"

#include <ignition/common/Console.hh>
#include <ignition/common/Profiler.hh>

#include <ignition/plugin/Register.hh>

Expand Down Expand Up @@ -206,6 +207,8 @@ void VisualizePointCloud::OnService(const ignition::msgs::PointCloudPacked &_res
//////////////////////////////////////////////////
void VisualizePointCloud::PublishMarkers()
{
IGN_PROFILE("VisualizePointCloud::PublishMarkers");

// If point cloud empty, do nothing. (PointCloudPackedIteratorBase errors on
// empty cloud.)
if (this->dataPtr->pcMsg.height() == 0 && this->dataPtr->pcMsg.width() == 0)
Expand Down