Skip to content

Commit

Permalink
[profile] Initial profiling setup with Tracy
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Mar 25, 2024
1 parent 383140b commit 059b0cd
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 11 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@ jobs:
- uses: johnwason/vcpkg-action@v6
with:
# TODO: Add ode and coin-or-ipopt
pkgs: assimp eigen3 fcl fmt spdlog bullet3 freeglut glfw3 nlopt opengl osg pagmo2 tinyxml2 urdfdom
pkgs: >
assimp
eigen3
fcl
fmt
spdlog
bullet3
freeglut
glfw3
nlopt
opengl
osg
pagmo2
tinyxml2
tracy
urdfdom
triplet: x64-windows
revision: "2024.02.14"
github-binarycache: true
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/publish_dartpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,25 @@ jobs:
if: ${{ matrix.os == 'windows-latest' && (matrix.release_only == false || github.ref == 'refs/heads/main') }}
uses: johnwason/vcpkg-action@v6
with:
pkgs: assimp ccd eigen3 fcl fmt spdlog bullet3 coin-or-ipopt freeglut glfw3 imgui nlopt ode opengl osg pagmo2 tinyxml2 urdfdom
pkgs: >
assimp
ccd
eigen3
fcl
fmt
spdlog
bullet3
coin-or-ipopt
freeglut
glfw3
imgui
nlopt
ode
opengl
osg
pagmo2
tinyxml2
urdfdom
triplet: x64-windows
revision: "2024.02.14"
github-binarycache: true
Expand Down
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build dependencies
brew 'cmake'
brew 'pkg-config'
brew 'tracy'

brew 'assimp'
brew 'bullet'
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ dart_option(DART_ENABLE_SIMD
"Build DART with all SIMD instructions on the current local machine" OFF)
dart_option(DART_BUILD_GUI_OSG "Build osgDart library" ON)
dart_option(DART_BUILD_DARTPY "Build dartpy" ON)
dart_option(DART_BUILD_PROFILE "Build DART with profiling options" OFF)
dart_option(DART_CODECOV "Turn on codecov support" OFF)
dart_option(DART_FAST_DEBUG "Add -O1 option for DEBUG mode build" OFF)
# GCC and Clang add ANSI-formatted colors when they detect the output medium is a
Expand Down
16 changes: 16 additions & 0 deletions cmake/DARTFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ endif()
# Optional dependencies
#=======================

if(DART_BUILD_PROFILE)
include(FetchContent)
FetchContent_Declare(tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
GIT_TAG v0.10
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(tracy)
if(MSVC)
target_compile_options(external_lib_target PRIVATE /W0)
else()
target_compile_options(TracyClient PRIVATE -w)
endif()
endif()

find_package(Python3 COMPONENTS Interpreter Development)

option(DART_SKIP_spdlog "If ON, do not use spdlog even if it is found." OFF)
Expand Down
4 changes: 4 additions & 0 deletions dart/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ if(DART_CODECOV)
target_link_libraries(dart PUBLIC coverage_config)
endif()

if(DART_BUILD_PROFILE)
target_link_libraries(dart PUBLIC TracyClient)
endif()

install(FILES dart.hpp DESTINATION include/dart/ COMPONENT headers)

dart_format_add(${dart_core_headers} ${dart_core_sources})
59 changes: 59 additions & 0 deletions dart/common/Profile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2011-2024, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/main/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include <dart/config.hpp>

#if DART_BUILD_PROFILE
#include <tracy/Tracy.hpp>
#endif

#if DART_BUILD_PROFILE

#define DART_PROFILE_FRAME FrameMark
#define DART_PROFILE_SCOPED ZoneScoped
#define DART_PROFILE_SCOPED_N(name) ZoneScopedN(name)

#else // no-op

#define DART_PROFILE_FRAME
#define DART_PROFILE_SCOPED
#define DART_PROFILE_SCOPED_N(name)

#endif

namespace dart::common {

//

} // namespace dart::common
2 changes: 2 additions & 0 deletions dart/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@
#cmakedefine BT_USE_DOUBLE_PRECISION

#cmakedefine01 DART_USE_SYSTEM_IMGUI

#cmakedefine01 DART_BUILD_PROFILE
3 changes: 3 additions & 0 deletions dart/constraint/ConstraintSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "dart/dynamics/Joint.hpp"
#include "dart/dynamics/Skeleton.hpp"
#include "dart/dynamics/SoftBodyNode.hpp"
#include "dart/common/Profile.hpp"

#include <algorithm>

Expand Down Expand Up @@ -361,6 +362,8 @@ LCPSolver* ConstraintSolver::getLCPSolver() const
//==============================================================================
void ConstraintSolver::solve()
{
DART_PROFILE_SCOPED_N("ConstraintSolver::solve");

for (auto& skeleton : mSkeletons) {
skeleton->clearConstraintImpulses();
DART_SUPPRESS_DEPRECATED_BEGIN
Expand Down
22 changes: 15 additions & 7 deletions dart/simulation/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "dart/collision/CollisionGroup.hpp"
#include "dart/common/Console.hpp"
#include "dart/common/Profile.hpp"
#include "dart/constraint/BoxedLcpConstraintSolver.hpp"
#include "dart/constraint/ConstrainedGroup.hpp"
#include "dart/dynamics/Skeleton.hpp"
Expand Down Expand Up @@ -163,16 +164,22 @@ void World::reset()
void World::step(bool _resetCommand)
{
// Integrate velocity for unconstrained skeletons
for (auto& skel : mSkeletons) {
if (!skel->isMobile())
continue;

skel->computeForwardDynamics();
skel->integrateVelocities(mTimeStep);
{
DART_PROFILE_SCOPED_N("World::step - Integrate velocity");
for (auto& skel : mSkeletons) {
if (!skel->isMobile())
continue;

skel->computeForwardDynamics();
skel->integrateVelocities(mTimeStep);
}
}

// Detect activated constraints and compute constraint impulses
mConstraintSolver->solve();
{
DART_PROFILE_SCOPED_N("World::step - Solve constraints");
mConstraintSolver->solve();
}

// Compute velocity changes given constraint impulses
for (auto& skel : mSkeletons) {
Expand All @@ -195,6 +202,7 @@ void World::step(bool _resetCommand)

mTime += mTimeStep;
mFrame++;
DART_PROFILE_FRAME;
}

//==============================================================================
Expand Down
34 changes: 34 additions & 0 deletions docker/dev/v6.14/Dockerfile.tracy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use an Ubuntu base image
FROM ubuntu:22.04

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Install build dependencies, X11 libraries, CA certificates, and Wayland protocols
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
git \
libx11-dev \
libgl1-mesa-dev \
libgtk-3-dev \
xorg-dev \
ca-certificates \
wayland-protocols \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

# Clone the Tracy Profiler repository
RUN git clone --depth 1 https://github.com/wolfpld/tracy.git

# Build Tracy Profiler
WORKDIR /tracy/profiler/build/unix
RUN cmake ../.. && make

# Use the `entrypoint.sh` to start the profiler
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

# Reset the frontend to its default value
ENV DEBIAN_FRONTEND=
33 changes: 33 additions & 0 deletions docker/dev/v6.14/Dockerfile.tracy.archlinux
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Use an Arch Linux base image
FROM archlinux:latest

# Initialize the keyring, populate the Arch Linux keyring, and update the system
RUN pacman-key --init \
&& pacman-key --populate archlinux \
&& pacman -Sy archlinux-keyring --noconfirm \
&& pacman -Su --noconfirm

# Install build dependencies
RUN pacman -S --noconfirm base-devel \
cmake \
git \
freetype2 \
tbb \
debuginfod \
wayland \
dbus \
libxkbcommon \
libglvnd \
meson \
wayland-protocols \
--needed \
&& pacman -Scc --noconfirm

# Clone the Tracy Profiler repository
RUN git clone --depth 1 https://github.com/wolfpld/tracy.git -b master

# Build Tracy Profiler GUI
WORKDIR /tracy/profiler/build
RUN cmake -S ../ -B . && cmake --build . --config Release --parallel

ENTRYPOINT [ "/tracy/profiler/build/tracy-profiler" ]
8 changes: 8 additions & 0 deletions docker/dev/v6.14/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# entrypoint.sh

# Use the host's display server for the GUI
export DISPLAY=host.docker.internal:0

# Start Tracy Profiler
./tracy/profiler/build/unix/Tracy-release
4 changes: 2 additions & 2 deletions examples/speed_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ get_filename_component(example_name ${CMAKE_CURRENT_LIST_DIR} NAME)

project(${example_name})

set(required_components utils-urdf gui)
set(required_libraries dart dart-utils-urdf dart-gui)
set(required_components utils-urdf)
set(required_libraries dart dart-utils-urdf)

if(DART_IN_SOURCE_BUILD)
dart_build_example_in_source(${example_name} LINK_LIBRARIES ${required_libraries})
Expand Down

0 comments on commit 059b0cd

Please sign in to comment.