Skip to content

Commit 38308f0

Browse files
ntfshardiche033
authored andcommitted
Better GZ_PROFILE instrumentation for rendering sensors (#532)
Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com> (cherry picked from commit 76532a6) Signed-off-by: Ian Chen <ichen@openrobotics.org> # Conflicts: # src/LogicalCameraSensor.cc
1 parent 67f492a commit 38308f0

File tree

12 files changed

+43
-27
lines changed

12 files changed

+43
-27
lines changed

examples/loop_sensor/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int main(int argc, char **argv)
7272
{
7373
auto sensor = link->SensorByIndex(s);
7474

75-
gz::sensors::Sensor *sensorPtr;
75+
gz::sensors::Sensor *sensorPtr{};
7676
if (sensor->Type() == sdf::SensorType::ALTIMETER)
7777
{
7878
sensorPtr = mgr.CreateSensor<gz::sensors::AltimeterSensor>(

include/gz/sensors/Manager.hh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
#ifndef GZ_SENSORS_MANAGER_HH_
1818
#define GZ_SENSORS_MANAGER_HH_
1919

20+
#include <chrono>
2021
#include <memory>
21-
#include <string>
2222
#include <utility>
2323
#include <type_traits>
24-
#include <vector>
2524
#include <sdf/sdf.hh>
2625
#include <gz/utils/SuppressWarning.hh>
2726
#include <gz/common/Console.hh>
@@ -42,7 +41,7 @@ namespace gz
4241
/// \brief Loads and runs sensors
4342
///
4443
/// This class is responsible for loading and running sensors, and
45-
/// providing sensors with common environments to generat data from.
44+
/// providing sensors with common environments to generate data from.
4645
///
4746
/// The primary interface through which to load a sensor is LoadSensor().
4847
/// This takes an sdf element pointer that should be configured with
@@ -62,7 +61,7 @@ namespace gz
6261
/// \return True if successfully initialized, false if not
6362
public: bool Init();
6463

65-
/// \brief Create a sensor from an SDF ovject with a known sensor type.
64+
/// \brief Create a sensor from an SDF object with a known sensor type.
6665
/// \sa Sensor()
6766
/// \param[in] _sdf An SDF element or DOM object.
6867
/// \tparam SensorType Sensor type

src/BoundingBoxCameraSensor.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,9 @@ rendering::BoundingBoxCameraPtr
393393
void BoundingBoxCameraSensor::OnNewBoundingBoxes(
394394
const std::vector<rendering::BoundingBox> &_boxes)
395395
{
396+
GZ_PROFILE("BoundingBoxCameraSensor::OnNewBoundingBoxes");
396397
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
397-
this->dataPtr->boundingBoxes.clear();
398-
for (const auto &box : _boxes)
399-
this->dataPtr->boundingBoxes.push_back(box);
398+
this->dataPtr->boundingBoxes = _boxes;
400399
}
401400

402401
//////////////////////////////////////////////////

src/CameraSensor.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*
1616
*/
1717

18-
#include <gz/msgs/boolean.pb.h>
1918
#include <gz/msgs/camera_info.pb.h>
2019
#include <gz/msgs/image.pb.h>
2120

@@ -490,8 +489,8 @@ bool CameraSensor::Update(const std::chrono::steady_clock::duration &_now)
490489
{
491490
if (this->dataPtr->generatingData)
492491
{
493-
gzdbg << "Disabling camera sensor: '" << this->Name() << "' data "
494-
<< "generation. " << std::endl;;
492+
gzdbg << "Disabling camera sensor: '" << this->Name()
493+
<< "' data generation. " << std::endl;
495494
this->dataPtr->generatingData = false;
496495
}
497496

@@ -501,8 +500,8 @@ bool CameraSensor::Update(const std::chrono::steady_clock::duration &_now)
501500
{
502501
if (!this->dataPtr->generatingData)
503502
{
504-
gzdbg << "Enabling camera sensor: '" << this->Name() << "' data "
505-
<< "generation." << std::endl;;
503+
gzdbg << "Enabling camera sensor: '" << this->Name()
504+
<< "' data generation." << std::endl;
506505
this->dataPtr->generatingData = true;
507506
}
508507
}

src/DepthCameraSensor.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ void DepthCameraSensor::OnNewDepthFrame(const float *_scan,
465465
unsigned int /*_channels*/,
466466
const std::string &_format)
467467
{
468+
GZ_PROFILE("DepthCameraSensor::OnNewDepthFrame");
468469
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
469470

470471
unsigned int depthSamples = _width * _height;
@@ -492,6 +493,7 @@ void DepthCameraSensor::OnNewRgbPointCloud(const float *_scan,
492493
unsigned int _channels,
493494
const std::string &/*_format*/)
494495
{
496+
GZ_PROFILE("DepthCameraSensor::OnNewRgbPointCloud");
495497
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
496498

497499
unsigned int pointCloudSamples = _width * _height;
@@ -599,10 +601,12 @@ bool DepthCameraSensor::Update(
599601
msg.set_data(this->dataPtr->depthBuffer,
600602
rendering::PixelUtil::MemorySize(rendering::PF_FLOAT32_R,
601603
width, height));
602-
603604
this->AddSequence(msg.mutable_header(), "default");
604-
this->dataPtr->pub.Publish(msg);
605605

606+
{
607+
GZ_PROFILE("DepthCameraSensor::Update Publish");
608+
this->dataPtr->pub.Publish(msg);
609+
}
606610

607611
if (this->dataPtr->imageEvent.ConnectionCount() > 0u)
608612
{

src/GpuLidarSensor.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ void GpuLidarSensor::OnNewLidarFrame(const float *_scan,
242242
unsigned int _width, unsigned int _height, unsigned int _channels,
243243
const std::string &_format)
244244
{
245+
GZ_PROFILE("GpuLidarSensor::OnNewLidarFrame");
245246
std::lock_guard<std::mutex> lock(this->lidarMutex);
246247

247248
unsigned int samples = _width * _height * _channels;

src/ImuSensor_TEST.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ TEST(ImuSensor_TEST, CustomRpyParentFrame)
508508
}
509509

510510
sdf::ElementPtr sensorWithLocalization(
511-
std::string _orientationLocalization)
511+
const std::string &_orientationLocalization)
512512
{
513513
std::ostringstream stream;
514514
stream

src/LogicalCameraSensor.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,13 @@ bool LogicalCameraSensor::Update(
166166
frame->set_key("frame_id");
167167
frame->add_value(this->FrameId());
168168

169-
// publish
170169
this->AddSequence(this->dataPtr->msg.mutable_header());
171-
this->dataPtr->pub.Publish(this->dataPtr->msg);
170+
171+
// publish
172+
{
173+
GZ_PROFILE("LogicalCameraSensor::Update Publish");
174+
this->dataPtr->pub.Publish(this->dataPtr->msg);
175+
}
172176

173177
return true;
174178
}

src/RgbdCameraSensor.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ void RgbdCameraSensorPrivate::OnNewDepthFrame(const float *_scan,
430430
unsigned int /*_channels*/,
431431
const std::string &/*_format*/)
432432
{
433+
GZ_PROFILE("RgbdCameraSensorPrivate::OnNewDepthFrame");
433434
std::lock_guard<std::mutex> lock(this->mutex);
434435

435436
unsigned int depthSamples = _width * _height;
@@ -447,6 +448,7 @@ void RgbdCameraSensorPrivate::OnNewRgbPointCloud(const float *_scan,
447448
unsigned int _channels,
448449
const std::string &/*_format*/)
449450
{
451+
GZ_PROFILE("RgbdCameraSensorPrivate::OnNewRgbPointCloud");
450452
std::lock_guard<std::mutex> lock(this->mutex);
451453

452454
unsigned int pointCloudSamples = _width * _height;
@@ -512,7 +514,7 @@ bool RgbdCameraSensor::Update(const std::chrono::steady_clock::duration &_now)
512514
// generate sensor data
513515
this->Render();
514516

515-
// create and publish the depthmessage
517+
// create and publish the depth message
516518
if (this->HasDepthConnections())
517519
{
518520
msgs::Image msg;

src/SegmentationCameraSensor.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ void SegmentationCameraSensor::OnNewSegmentationFrame(const uint8_t * _data,
434434
unsigned int _width, unsigned int _height, unsigned int _channels,
435435
const std::string &/*_format*/)
436436
{
437+
GZ_PROFILE("SegmentationCameraSensor::OnNewSegmentationFrame");
437438
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
438439

439440
unsigned int bufferSize = _width * _height * _channels;
@@ -539,8 +540,11 @@ bool SegmentationCameraSensor::Update(
539540
width, height));
540541

541542
// Publish
542-
this->dataPtr->coloredMapPublisher.Publish(this->dataPtr->coloredMapMsg);
543-
this->dataPtr->labelsMapPublisher.Publish(this->dataPtr->labelsMapMsg);
543+
{
544+
GZ_PROFILE("SegmentationCameraSensor::Update Publish");
545+
this->dataPtr->coloredMapPublisher.Publish(this->dataPtr->coloredMapMsg);
546+
this->dataPtr->labelsMapPublisher.Publish(this->dataPtr->labelsMapMsg);
547+
}
544548

545549
// Trigger callbacks.
546550
if (this->dataPtr->imageEvent.ConnectionCount() > 0u)

0 commit comments

Comments
 (0)