RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
Tracer.java
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5package org.wpilib.system;
6
7import java.util.HashMap;
8import java.util.Map;
9import java.util.function.Consumer;
10import org.wpilib.driverstation.DriverStationErrors;
11
20public class Tracer {
21 private static final long MIN_PRINT_PERIOD = 1_000_000_000; // nanoseconds
22
23 private long m_lastEpochsPrintTime; // nanoseconds
24 private long m_startTime; // nanoseconds
25
26 private final Map<String, Long> m_epochs = new HashMap<>(); // nanoseconds
27
29 public Tracer() {
30 resetTimer();
31 }
32
34 public void clearEpochs() {
35 m_epochs.clear();
36 resetTimer();
37 }
38
40 public final void resetTimer() {
41 m_startTime = RobotController.getMonotonicTime();
42 }
43
55 public void addEpoch(String epochName) {
56 long currentTime = RobotController.getMonotonicTime();
57 m_epochs.put(epochName, currentTime - m_startTime);
58 m_startTime = currentTime;
59 }
60
62 public void printEpochs() {
64 }
65
73 public void printEpochs(Consumer<String> output) {
75 if (now - m_lastEpochsPrintTime > MIN_PRINT_PERIOD) {
76 StringBuilder sb = new StringBuilder();
77 m_lastEpochsPrintTime = now;
78 m_epochs.forEach(
79 (key, value) -> sb.append(String.format("\t%s: %.6fs\n", key, value / 1.0e9)));
80 if (sb.length() > 0) {
81 output.accept(sb.toString());
82 }
83 }
84 }
85}
static void reportWarning(String warning, boolean printTrace)
void addEpoch(String epochName)
Definition Tracer.java:55
final void resetTimer()
Definition Tracer.java:40
void printEpochs(Consumer< String > output)
Definition Tracer.java:73