Skip to content

Commit c071fd3

Browse files
committed
[Gazebo 11] Added ignition common profiler (gazebosim#2776)
* Added profiler to OdePhysics, sensors and some plugins Signed-off-by: ahcorde <[email protected]> * Added profiler to Physic engines: Bullet, DART and Simbody Signed-off-by: ahcorde <[email protected]> * Added profiler to plugins Signed-off-by: ahcorde <[email protected]> * Added more models to profiler.world Signed-off-by: ahcorde <[email protected]> * Add missing ; Signed-off-by: ahcorde <[email protected]> * Added option ENABLE_PROFILER to cmake Signed-off-by: ahcorde <[email protected]> * Used the same convention in all profiler calls Signed-off-by: ahcorde <[email protected]> * Added profiler to Event.hh Signed-off-by: ahcorde <[email protected]> * Fixed gazebo_common link against ignition_common Signed-off-by: ahcorde <[email protected]> * Added condition to use -fvisibility=hidden when profiler is disabled Signed-off-by: ahcorde <[email protected]> * make linters happy Signed-off-by: ahcorde <[email protected]>
1 parent 7dc6453 commit c071fd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1900
-16
lines changed

CMakeLists.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if(NOT DEFINED BUILD_TESTING)
3737
set(BUILD_TESTING OFF)
3838
endif()
3939

40+
option(ENABLE_PROFILER "Enable Ignition Profiler" FALSE)
41+
42+
if(ENABLE_PROFILER)
43+
add_definitions("-DIGN_PROFILER_ENABLE=1")
44+
else()
45+
add_definitions("-DIGN_PROFILER_ENABLE=0")
46+
endif()
47+
4048
#============================================================================
4149
# We turn off extensions because (1) we do not ever want to use non-standard
4250
# compiler extensions, and (2) this variable is on by default, causing cmake
@@ -254,7 +262,11 @@ filter_valid_compiler_flags(${WARN_LEVEL}
254262
# Check and add visibility hidden by default. Only in UNIX
255263
# Windows and MacosX does not handled properly the hidden compilation
256264
if (UNIX AND NOT APPLE)
257-
filter_valid_compiler_flags(-fvisibility=hidden -fvisibility-inlines-hidden)
265+
if (ENABLE_PROFILER)
266+
filter_valid_compiler_flags(-fvisibility-inlines-hidden)
267+
else()
268+
filter_valid_compiler_flags(-fvisibility=hidden -fvisibility-inlines-hidden)
269+
endif()
258270
endif()
259271

260272
if (MSVC)

gazebo/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ add_dependencies(gazebo_sensors gazebo_rendering)
5151

5252
gz_add_executable(gzserver server_main.cc)
5353

54+
if (${ENABLE_PROFILER})
55+
set(IGN_PROFILE_LIBS ${IGNITION-COMMON_LIBRARIES})
56+
endif()
57+
5458
target_link_libraries(gzserver
5559
libgazebo
5660
gazebo_common
@@ -64,6 +68,7 @@ target_link_libraries(gzserver
6468
${freeimage_LIBRARIES}
6569
${TBB_LIBRARIES}
6670
${ogre_libraries}
71+
${IGN_PROFILE_LIBS}
6772
)
6873

6974
if (UNIX)

gazebo/Server.cc

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <sdf/sdf.hh>
3434

3535
#include <ignition/math/Rand.hh>
36+
#include "ignition/common/Profiler.hh"
3637

3738
#include "gazebo/gazebo.hh"
3839
#include "gazebo/transport/transport.hh"
@@ -580,16 +581,28 @@ void Server::Run()
580581

581582
this->dataPtr->initialized = true;
582583

584+
IGN_PROFILE_THREAD_NAME("gzserver");
583585
// Stay on this loop until Gazebo needs to be shut down
584586
// The server and sensor manager outlive worlds
585587
while (!this->dataPtr->stop)
586588
{
589+
IGN_PROFILE("Server::Run");
590+
IGN_PROFILE_BEGIN("ProcessControlMsgs");
587591
this->ProcessControlMsgs();
592+
IGN_PROFILE_END();
588593

589594
if (physics::worlds_running())
595+
{
596+
IGN_PROFILE_BEGIN("run_once");
590597
sensors::run_once();
598+
IGN_PROFILE_END();
599+
}
591600
else if (sensors::running())
601+
{
602+
IGN_PROFILE_BEGIN("stop");
592603
sensors::stop();
604+
IGN_PROFILE_END();
605+
}
593606

594607
common::Time::MSleep(1);
595608
}

gazebo/common/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ target_compile_definitions(gazebo_common
247247

248248
target_link_libraries(gazebo_common
249249
${IGNITION-MATH_LIBRARIES}
250+
${IGNITION-COMMON_LIBRARIES}
250251
${libdl_library}
251252
${libtool_library}
252253
${Boost_LIBRARIES}

gazebo/common/Event.hh

+65-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
#include <memory>
2525
#include <mutex>
2626

27-
#include <gazebo/gazebo_config.h>
28-
#include <gazebo/common/Time.hh>
29-
#include <gazebo/common/CommonTypes.hh>
27+
#include "gazebo/gazebo_config.h"
28+
#include "gazebo/common/Time.hh"
29+
#include "gazebo/common/CommonTypes.hh"
3030
#include "gazebo/util/system.hh"
3131

32+
#include "ignition/common/Profiler.hh"
33+
3234
namespace gazebo
3335
{
3436
/// \ingroup gazebo_event
@@ -268,13 +270,19 @@ namespace gazebo
268270
/// \brief Signal the event for all subscribers.
269271
public: void Signal()
270272
{
273+
IGN_PROFILE("Event::Signal");
274+
271275
this->Cleanup();
272276

273277
this->SetSignaled(true);
274278
for (const auto &iter: this->connections)
275279
{
276280
if (iter.second->on)
281+
{
282+
IGN_PROFILE_BEGIN("callback0");
277283
iter.second->callback();
284+
IGN_PROFILE_END();
285+
}
278286
}
279287
}
280288

@@ -283,13 +291,19 @@ namespace gazebo
283291
public: template< typename P >
284292
void Signal(const P &_p)
285293
{
294+
IGN_PROFILE("Event::Signal");
295+
286296
this->Cleanup();
287297

288298
this->SetSignaled(true);
289299
for (const auto &iter: this->connections)
290300
{
291301
if (iter.second->on)
302+
{
303+
IGN_PROFILE_BEGIN("callback1");
292304
iter.second->callback(_p);
305+
IGN_PROFILE_END();
306+
}
293307
}
294308
}
295309

@@ -299,13 +313,19 @@ namespace gazebo
299313
public: template< typename P1, typename P2 >
300314
void Signal(const P1 &_p1, const P2 &_p2)
301315
{
316+
IGN_PROFILE("Event::Signal");
317+
302318
this->Cleanup();
303319

304320
this->SetSignaled(true);
305321
for (const auto &iter: this->connections)
306322
{
307323
if (iter.second->on)
324+
{
325+
IGN_PROFILE_BEGIN("callback2");
308326
iter.second->callback(_p1, _p2);
327+
IGN_PROFILE_END();
328+
}
309329
}
310330
}
311331

@@ -316,13 +336,19 @@ namespace gazebo
316336
public: template< typename P1, typename P2, typename P3 >
317337
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3)
318338
{
339+
IGN_PROFILE("Event::Signal");
340+
319341
this->Cleanup();
320342

321343
this->SetSignaled(true);
322344
for (const auto &iter: this->connections)
323345
{
324346
if (iter.second->on)
347+
{
348+
IGN_PROFILE_BEGIN("callback3");
325349
iter.second->callback(_p1, _p2, _p3);
350+
IGN_PROFILE_END();
351+
}
326352
}
327353
}
328354

@@ -335,13 +361,19 @@ namespace gazebo
335361
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3,
336362
const P4 &_p4)
337363
{
364+
IGN_PROFILE("Event::Signal");
365+
338366
this->Cleanup();
339367

340368
this->SetSignaled(true);
341369
for (const auto &iter: this->connections)
342370
{
343371
if (iter.second->on)
372+
{
373+
IGN_PROFILE_BEGIN("callback4");
344374
iter.second->callback(_p1, _p2, _p3, _p4);
375+
IGN_PROFILE_END();
376+
}
345377
}
346378
}
347379

@@ -356,13 +388,19 @@ namespace gazebo
356388
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3,
357389
const P4 &_p4, const P5 &_p5)
358390
{
391+
IGN_PROFILE("Event::Signal");
392+
359393
this->Cleanup();
360394

361395
this->SetSignaled(true);
362396
for (const auto &iter: this->connections)
363397
{
364398
if (iter.second->on)
399+
{
400+
IGN_PROFILE_BEGIN("callback5");
365401
iter.second->callback(_p1, _p2, _p3, _p4, _p5);
402+
IGN_PROFILE_END();
403+
}
366404
}
367405
}
368406

@@ -378,13 +416,19 @@ namespace gazebo
378416
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3,
379417
const P4 &_p4, const P5 &_p5, const P6 &_p6)
380418
{
419+
IGN_PROFILE("Event::Signal");
420+
381421
this->Cleanup();
382422

383423
this->SetSignaled(true);
384424
for (const auto &iter: this->connections)
385425
{
386426
if (iter.second->on)
427+
{
428+
IGN_PROFILE_BEGIN("callback6");
387429
iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6);
430+
IGN_PROFILE_END();
431+
}
388432
}
389433
}
390434

@@ -401,13 +445,19 @@ namespace gazebo
401445
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3,
402446
const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7)
403447
{
448+
IGN_PROFILE("Event::Signal");
449+
404450
this->Cleanup();
405451

406452
this->SetSignaled(true);
407453
for (const auto &iter: this->connections)
408454
{
409455
if (iter.second->on)
456+
{
457+
IGN_PROFILE_BEGIN("callback7");
410458
iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
459+
IGN_PROFILE_END();
460+
}
411461
}
412462
}
413463

@@ -426,14 +476,18 @@ namespace gazebo
426476
const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7,
427477
const P8 &_p8)
428478
{
479+
IGN_PROFILE("Event::Signal");
480+
429481
this->Cleanup();
430482

431483
this->SetSignaled(true);
432484
for (const auto &iter: this->connections)
433485
{
434486
if (iter.second->on)
435487
{
488+
IGN_PROFILE_BEGIN("callback8");
436489
iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
490+
IGN_PROFILE_END();
437491
}
438492
}
439493
}
@@ -455,15 +509,19 @@ namespace gazebo
455509
const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7,
456510
const P8 &_p8, const P9 &_p9)
457511
{
512+
IGN_PROFILE("Event::Signal");
513+
458514
this->Cleanup();
459515

460516
this->SetSignaled(true);
461517
for (const auto &iter: this->connections)
462518
{
463519
if (iter.second->on)
464520
{
521+
IGN_PROFILE_BEGIN("callback9");
465522
iter.second->callback(
466523
_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
524+
IGN_PROFILE_END();
467525
}
468526
}
469527
}
@@ -491,10 +549,14 @@ namespace gazebo
491549
this->SetSignaled(true);
492550
for (const auto &iter: this->connections)
493551
{
552+
IGN_PROFILE("Event::Signal");
553+
494554
if (iter.second->on)
495555
{
556+
IGN_PROFILE_BEGIN("callback10");
496557
iter.second->callback(
497558
_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
559+
IGN_PROFILE_END();
498560
}
499561
}
500562
}

gazebo/physics/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,18 @@ target_compile_definitions(gazebo_physics
158158
PRIVATE BUILDING_DLL_GZ_PHYSICS
159159
)
160160

161+
if (${ENABLE_PROFILER})
162+
set(IGN_PROFILE_LIBS ${IGNITION-COMMON_LIBRARIES})
163+
endif()
164+
161165
target_link_libraries(gazebo_physics
162166
gazebo_common
163167
gazebo_util
164168
gazebo_ode
165169
gazebo_opcode
166170
${Boost_LIBRARIES}
167171
${IGNITION-TRANSPORT_LIBRARIES}
172+
${IGN_PROFILE_LIBS}
168173
)
169174

170175
# Link in Bullet support if present

0 commit comments

Comments
 (0)