allwpilib
allwpilib copied to clipboard
Tracer epochs for subsystem periodics are named differently in C++
There's a Tracer epoch for each subsystem periodic, and in Java it's named with the subsystem's name (ie subsystem.getClass().getSimpleName()) but in C++ the name is hardcoded to "Subsystem Periodic()"; maybe this is due to C++ not having runtime reflection?
Yes, that's why.
The command epochs use GetTypeName, so if that works then why can't it be used here as well? Or does GetTypeName not work either?
There's GetName() which calls GetTypeName(), but I'm not sure whether it returns the name of the base class or the derived class.
#include <iostream>
#include <typeinfo>
class A {
public:
virtual ~A() = default;
};
class B : public A {};
int main()
{
A a{};
B b{};
A* ptr{&a};
std::cout<<typeid(*ptr).name() << "\n";
ptr = &b;
std::cout<<typeid(*ptr).name();
return 0;
}
prints this:
1A
1B
so I guess that as long as there's a virtual method then it checks the derived class. I don't know what that 1 prefix is about though.
@Starlight220 did you check for if this worked for all platforms for debug and release? pybind11 only retrieves names of types for error messages when compiled for debug, not sure why that is (might be performance)
You can use this to demangle the names: https://github.com/pybind/pybind11/blob/ec24786eab4d170f21536c92422a59959e14dde4/include/pybind11/detail/typeid.h#L34
We already have this function in Command.h, which is what should be getting called instead of typeid() directly.
template <typename T>
std::string GetTypeName(const T& type) {
return wpi::Demangle(typeid(type).name());
}
If that doesn't make sense given you're printing a subsystem type instead of a command type, just use wpi::Demangle() like that function does.