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:
Tyler Veness
2020-03-15 19:56:08 -07:00
committed by GitHub
parent 510936a2a0
commit 4228d3609e
2 changed files with 16 additions and 10 deletions

View File

@@ -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. */
@@ -26,17 +26,17 @@ import java.util.concurrent.locks.ReentrantLock;
@SuppressWarnings("PMD.TooManyMethods")
public class Watchdog implements Closeable, Comparable<Watchdog> {
// Used for timeout print rate-limiting
private static final long kMinPrintPeriod = 1000000; // us
private static final long kMinPrintPeriod = 1000000; // microseconds
private long m_startTime; // us
private long m_timeout; // us
private long m_expirationTime; // us
private long m_startTime; // microseconds
private long m_timeout; // microseconds
private long m_expirationTime; // microseconds
private final Runnable m_callback;
private long m_lastTimeoutPrintTime; // us
private long m_lastEpochsPrintTime; // us
private long m_lastTimeoutPrintTime; // microseconds
private long m_lastEpochsPrintTime; // microseconds
@SuppressWarnings("PMD.UseConcurrentHashMap")
private final Map<String, Long> m_epochs = new HashMap<>();
private final Map<String, Long> m_epochs = new HashMap<>(); // microseconds
boolean m_isExpired;
boolean m_suppressTimeoutMessage;