From ce12c7a9070d7be6cd0b0292646570dc363a5aa2 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 22 Jun 2022 18:55:37 +0200 Subject: [PATCH 1/2] Add Tracy Profiler --- CMakeLists.txt | 6 ++++++ src/STPManager.cpp | 10 ++++------ .../positionControl/BBTrajectories/WorldObjects.cpp | 2 ++ src/control/positionControl/PositionControl.cpp | 2 ++ src/stp/Play.cpp | 2 ++ src/stp/Skill.cpp | 2 ++ src/stp/Tactic.cpp | 2 ++ src/world/World.cpp | 2 ++ 8 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec848876fb..a4bbdda733 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ target_include_directories(roboteam_ai_skills PRIVATE include/roboteam_ai ) target_link_libraries(roboteam_ai_skills + PRIVATE Tracy::TracyClient PRIVATE roboteam_networking PRIVATE roboteam_utils PRIVATE Qt5::Widgets @@ -91,6 +92,7 @@ target_include_directories(roboteam_ai_tactics PRIVATE include/roboteam_ai ) target_link_libraries(roboteam_ai_tactics + PRIVATE Tracy::TracyClient PRIVATE roboteam_utils PRIVATE roboteam_networking PRIVATE Qt5::Widgets @@ -173,6 +175,7 @@ target_include_directories(roboteam_ai_plays PRIVATE include/roboteam_ai ) target_link_libraries(roboteam_ai_plays + PRIVATE Tracy::TracyClient PUBLIC roboteam_interface_utils_lib PRIVATE roboteam_networking PRIVATE roboteam_utils @@ -286,6 +289,7 @@ target_include_directories(roboteam_ai_control PRIVATE include/roboteam_ai ) target_link_libraries(roboteam_ai_control + PRIVATE Tracy::TracyClient PRIVATE roboteam_networking PRIVATE roboteam_utils PRIVATE Qt5::Widgets @@ -360,6 +364,7 @@ target_include_directories(roboteam_ai_world PRIVATE include/roboteam_ai ) target_link_libraries(roboteam_ai_world + PRIVATE Tracy::TracyClient PRIVATE roboteam_networking PRIVATE roboteam_utils PRIVATE Qt5::Widgets @@ -375,6 +380,7 @@ target_include_directories(roboteam_ai PRIVATE include/roboteam_ai ) target_link_libraries(roboteam_ai + PRIVATE Tracy::TracyClient PRIVATE roboteam_utils PRIVATE Qt5::Widgets PRIVATE roboteam_networking diff --git a/src/STPManager.cpp b/src/STPManager.cpp index 5176f6bdcf..cf7e96cfaf 100644 --- a/src/STPManager.cpp +++ b/src/STPManager.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include #include "control/ControlModule.h" @@ -99,13 +101,8 @@ void STPManager::start() { roboteam_utils::Timer stpTimer; stpTimer.loop( [&]() { - // uncomment the 4 lines of code below to time and display the duration of each loop of the AI - // std::chrono::steady_clock::time_point tStart = std::chrono::steady_clock::now(); + ZoneScopedN("STP Loop"); runOneLoopCycle(); - // std::chrono::steady_clock::time_point tStop = std::chrono::steady_clock::now(); - - // auto loopcycleDuration = std::chrono::duration_cast((tStop - tStart)).count(); - // RTT_DEBUG("Loop cycle duration = ", loopcycleDuration); amountOfCycles++; // update the measured FPS, but limit this function call to only run 5 times/s at most @@ -178,6 +175,7 @@ void STPManager::runOneLoopCycle() { } void STPManager::decidePlay(world::World *_world) { + ZoneScopedN("Decide Play") ai::stp::PlayEvaluator::clearGlobalScores(); // reset all evaluations ai::stp::ComputationManager::clearStoredComputations(); diff --git a/src/control/positionControl/BBTrajectories/WorldObjects.cpp b/src/control/positionControl/BBTrajectories/WorldObjects.cpp index 6844ba00bb..446f5af56d 100644 --- a/src/control/positionControl/BBTrajectories/WorldObjects.cpp +++ b/src/control/positionControl/BBTrajectories/WorldObjects.cpp @@ -3,6 +3,7 @@ // #include "control/positionControl/BBTrajectories/WorldObjects.h" +#include #include #include @@ -15,6 +16,7 @@ WorldObjects::WorldObjects() = default; std::optional WorldObjects::getFirstCollision(const rtt::world::World *world, const rtt::world::Field &field, const Trajectory2D &Trajectory, const std::unordered_map> &computedPaths, int robotId, ai::stp::AvoidObjects avoidObjects) { + ZoneScopedN("Get First Collision"); gameState = rtt::ai::GameStateManager::getCurrentGameState(); ruleset = gameState.getRuleSet(); // TODO: return the kind of collision diff --git a/src/control/positionControl/PositionControl.cpp b/src/control/positionControl/PositionControl.cpp index 94bbdb20b8..c85f18484d 100644 --- a/src/control/positionControl/PositionControl.cpp +++ b/src/control/positionControl/PositionControl.cpp @@ -6,6 +6,7 @@ #include "control/positionControl/BBTrajectories/BBTrajectory2D.h" #include "roboteam_utils/Print.h" +#include namespace rtt::ai::control { RobotCommand PositionControl::computeAndTrackPath(const rtt::world::Field &field, int robotId, const Vector2 ¤tPosition, const Vector2 ¤tVelocity, @@ -41,6 +42,7 @@ void PositionControl::setRobotPositions(std::vector &robotPositions) { rtt::BB::CommandCollision PositionControl::computeAndTrackTrajectory(const rtt::world::World *world, const rtt::world::Field &field, int robotId, Vector2 currentPosition, Vector2 currentVelocity, Vector2 targetPosition, double maxRobotVelocity, stp::PIDType pidType, stp::AvoidObjects avoidObjects) { + ZoneScopedN("ComputeAndTrackTrajectory"); double timeStep = 0.1; std::optional firstCollision; diff --git a/src/stp/Play.cpp b/src/stp/Play.cpp index f90c3ba42c..0f1c501389 100644 --- a/src/stp/Play.cpp +++ b/src/stp/Play.cpp @@ -6,6 +6,7 @@ #include "control/ControlUtils.h" #include "interface/widgets/MainControlsWidget.h" +#include namespace rtt::ai::stp { @@ -29,6 +30,7 @@ void Play::setWorld(world::World *world) noexcept { this->world = world; } void Play::updateField(world::Field field) noexcept { this->field = field; } void Play::update() noexcept { + ZoneScopedN("Play Update"); // clear roleStatuses so it only contains the current tick's statuses roleStatuses.clear(); // RTT_INFO("Play executing: ", getName()) diff --git a/src/stp/Skill.cpp b/src/stp/Skill.cpp index 190c42a127..ed590e949d 100644 --- a/src/stp/Skill.cpp +++ b/src/stp/Skill.cpp @@ -6,6 +6,7 @@ #include "control/ControlModule.h" #include "world/World.hpp" +#include namespace rtt::ai::stp { @@ -28,6 +29,7 @@ void Skill::refreshRobotCommand() noexcept { void Skill::terminate() noexcept {} Status Skill::update(StpInfo const& info) noexcept { + ZoneScopedN("Skill Update"); robot = info.getRobot(); auto result = onUpdate(info); currentStatus = result; diff --git a/src/stp/Tactic.cpp b/src/stp/Tactic.cpp index e794dde48f..04c6e0f3a8 100644 --- a/src/stp/Tactic.cpp +++ b/src/stp/Tactic.cpp @@ -5,6 +5,7 @@ #include "stp/Tactic.h" #include +#include namespace rtt::ai::stp { @@ -15,6 +16,7 @@ void Tactic::initialize() noexcept { } Status Tactic::update(StpInfo const &info) noexcept { + ZoneScopedN("Tactic Update"); // Update skill info auto skill_info = calculateInfoForSkill(info); diff --git a/src/world/World.cpp b/src/world/World.cpp index a5644cb2be..c02e0e7e77 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -3,6 +3,7 @@ // #include "world/World.hpp" +#include namespace rtt::world { WorldData const &World::setWorld(WorldData &newWorld) noexcept { @@ -91,6 +92,7 @@ void World::updateTickTime() noexcept { } void World::updatePositionControl() { + ZoneScopedN("Update Position Control"); std::vector robotPositions(getWorld()->getRobotsNonOwning().size()); std::transform(getWorld()->getRobotsNonOwning().begin(), getWorld()->getRobotsNonOwning().end(), robotPositions.begin(), [](const auto &robot) -> Vector2 { return (robot->getPos()); }); From 95acf6c26fa5a49d9c5d884ccbe46bd96d652d6f Mon Sep 17 00:00:00 2001 From: mirixx Date: Mon, 19 Sep 2022 14:40:01 +0200 Subject: [PATCH 2/2] changed the path to header file "Tracy.hpp" The path to the header file was working had to add a directory above it. --- src/STPManager.cpp | 4 ++-- src/control/positionControl/BBTrajectories/WorldObjects.cpp | 2 +- src/control/positionControl/PositionControl.cpp | 3 +-- src/stp/Play.cpp | 2 +- src/stp/Skill.cpp | 2 +- src/stp/Tactic.cpp | 2 +- src/world/World.cpp | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/STPManager.cpp b/src/STPManager.cpp index 905c568cfb..cd46fa7a01 100644 --- a/src/STPManager.cpp +++ b/src/STPManager.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include "tracy/Tracy.hpp" #include @@ -176,7 +176,7 @@ void STPManager::runOneLoopCycle() { } void STPManager::decidePlay(world::World *_world) { - ZoneScopedN("Decide Play") + ZoneScopedN("Decide Play"); ai::stp::PlayEvaluator::clearGlobalScores(); // reset all evaluations ai::stp::ComputationManager::clearStoredComputations(); diff --git a/src/control/positionControl/BBTrajectories/WorldObjects.cpp b/src/control/positionControl/BBTrajectories/WorldObjects.cpp index a37b91cf52..82bf96e0b7 100644 --- a/src/control/positionControl/BBTrajectories/WorldObjects.cpp +++ b/src/control/positionControl/BBTrajectories/WorldObjects.cpp @@ -3,7 +3,7 @@ // #include "control/positionControl/BBTrajectories/WorldObjects.h" -#include +#include "tracy/Tracy.hpp" #include #include "world/World.hpp" diff --git a/src/control/positionControl/PositionControl.cpp b/src/control/positionControl/PositionControl.cpp index c81007183b..8cb8520e21 100644 --- a/src/control/positionControl/PositionControl.cpp +++ b/src/control/positionControl/PositionControl.cpp @@ -6,8 +6,7 @@ #include "control/positionControl/BBTrajectories/BBTrajectory2D.h" #include "roboteam_utils/Print.h" -#include - +#include "tracy/Tracy.hpp" namespace rtt::ai::control { RobotCommand PositionControl::computeAndTrackPath(const rtt::world::Field &field, int robotId, const Vector2 ¤tPosition, const Vector2 ¤tVelocity, Vector2 &targetPosition, stp::PIDType pidType) { diff --git a/src/stp/Play.cpp b/src/stp/Play.cpp index 8c03984beb..6446459bad 100644 --- a/src/stp/Play.cpp +++ b/src/stp/Play.cpp @@ -6,7 +6,7 @@ #include "control/ControlUtils.h" #include "interface/widgets/MainControlsWidget.h" -#include +#include "tracy/Tracy.hpp" namespace rtt::ai::stp { diff --git a/src/stp/Skill.cpp b/src/stp/Skill.cpp index ed590e949d..533846c199 100644 --- a/src/stp/Skill.cpp +++ b/src/stp/Skill.cpp @@ -6,7 +6,7 @@ #include "control/ControlModule.h" #include "world/World.hpp" -#include +#include "tracy/Tracy.hpp" namespace rtt::ai::stp { diff --git a/src/stp/Tactic.cpp b/src/stp/Tactic.cpp index 66f2c5fb79..cb7d0a8e7d 100644 --- a/src/stp/Tactic.cpp +++ b/src/stp/Tactic.cpp @@ -5,7 +5,7 @@ #include "stp/Tactic.h" #include -#include +#include "tracy/Tracy.hpp" namespace rtt::ai::stp { diff --git a/src/world/World.cpp b/src/world/World.cpp index c02e0e7e77..fd973be97f 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -3,7 +3,7 @@ // #include "world/World.hpp" -#include +#include "tracy/Tracy.hpp" namespace rtt::world { WorldData const &World::setWorld(WorldData &newWorld) noexcept {