mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Fix Watchdog epoch prints being off by three orders of magnitude (#2414)
This was caused by m_epochs storing the timestamps as nanoseconds while the epoch printing code expects microseconds. Adding a duration cast fixes this. Java stores the epoch timestamps in a double as microseconds, so it doesn't exhibit this bug. The comments were updated to make this more obvious. Fixes #2392.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -134,12 +134,18 @@ void Watchdog::AddEpoch(wpi::StringRef epochName) {
|
||||
}
|
||||
|
||||
void Watchdog::PrintEpochs() {
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::microseconds;
|
||||
|
||||
auto now = hal::fpga_clock::now();
|
||||
if (now - m_lastEpochsPrintTime > kMinPrintPeriod) {
|
||||
m_lastEpochsPrintTime = now;
|
||||
for (const auto& epoch : m_epochs) {
|
||||
wpi::outs() << '\t' << epoch.getKey() << ": "
|
||||
<< wpi::format("%.6f", epoch.getValue().count() / 1.0e6)
|
||||
<< wpi::format(
|
||||
"%.6f",
|
||||
duration_cast<microseconds>(epoch.getValue()).count() /
|
||||
1.0e6)
|
||||
<< "s\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user