[wpilibc] Output Tracer to DriverStation by default (#2469)

This matches the Java behavior.

Also optimizes Java to only create a StringBuffer and call
DriverStation.reportWarning if there is data to output.
This commit is contained in:
Peter Johnson
2020-04-05 23:09:21 -07:00
committed by GitHub
parent cb51029335
commit b46b5df16a
3 changed files with 32 additions and 10 deletions

View File

@@ -8,8 +8,11 @@
#include "frc/Tracer.h"
#include <wpi/Format.h>
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
#include "frc/DriverStation.h"
using namespace frc;
Tracer::Tracer() { ResetTimer(); }
@@ -28,6 +31,13 @@ void Tracer::AddEpoch(wpi::StringRef epochName) {
}
void Tracer::PrintEpochs() {
wpi::SmallString<128> buf;
wpi::raw_svector_ostream os(buf);
PrintEpochs(os);
if (!buf.empty()) DriverStation::ReportWarning(buf);
}
void Tracer::PrintEpochs(wpi::raw_ostream& os) {
using std::chrono::duration_cast;
using std::chrono::microseconds;
@@ -35,12 +45,11 @@ void Tracer::PrintEpochs() {
if (now - m_lastEpochsPrintTime > kMinPrintPeriod) {
m_lastEpochsPrintTime = now;
for (const auto& epoch : m_epochs) {
wpi::outs() << '\t' << epoch.getKey() << ": "
<< wpi::format(
"%.6f",
duration_cast<microseconds>(epoch.getValue()).count() /
1.0e6)
<< "s\n";
os << '\t' << epoch.getKey() << ": "
<< wpi::format(
"%.6f",
duration_cast<microseconds>(epoch.getValue()).count() / 1.0e6)
<< "s\n";
}
}
}