[commands] Add GetName to Subsystem, use in Scheduler tracer epochs (#5836)

This commit is contained in:
Ryan Blue
2023-12-01 02:10:53 -05:00
committed by GitHub
parent ac7d726ac3
commit 1144115da0
9 changed files with 37 additions and 8 deletions

View File

@@ -183,7 +183,7 @@ void CommandScheduler::Run() {
if constexpr (frc::RobotBase::IsSimulation()) {
subsystem.getFirst()->SimulationPeriodic();
}
m_watchdog.AddEpoch("Subsystem Periodic()");
m_watchdog.AddEpoch(subsystem.getFirst()->GetName() + ".Periodic()");
}
// Cache the active instance to avoid concurrency problems if SetActiveLoop()

View File

@@ -4,6 +4,8 @@
#include "frc2/command/Subsystem.h"
#include <wpi/Demangle.h>
#include "frc2/command/CommandPtr.h"
#include "frc2/command/Commands.h"
@@ -16,6 +18,10 @@ void Subsystem::Periodic() {}
void Subsystem::SimulationPeriodic() {}
std::string Subsystem::GetName() const {
return wpi::GetTypeName(*this);
}
void Subsystem::SetDefaultCommand(CommandPtr&& defaultCommand) {
CommandScheduler::GetInstance().SetDefaultCommand(this,
std::move(defaultCommand));

View File

@@ -18,11 +18,6 @@
namespace frc2 {
template <typename T>
std::string GetTypeName(const T& type) {
return wpi::Demangle(typeid(type).name());
}
/**
* A state machine representing a complete action to be performed by the robot.
* Commands are run by the CommandScheduler, and can be composed into

View File

@@ -6,6 +6,7 @@
#include <concepts>
#include <functional>
#include <string>
#include <utility>
#include <wpi/FunctionExtras.h>
@@ -59,6 +60,13 @@ class Subsystem {
*/
virtual void SimulationPeriodic();
/**
* Gets the name of this Subsystem.
*
* @return Name
*/
virtual std::string GetName() const;
/**
* Sets the default Command of the subsystem. The default command will be
* automatically scheduled when no other commands are scheduled that require

View File

@@ -30,7 +30,7 @@ class SubsystemBase : public Subsystem,
*
* @return Name
*/
std::string GetName() const;
std::string GetName() const override;
/**
* Sets the name of this Subsystem.