mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
- Twine, StringRef, Format, and NativeFormatting have been removed - Logging now uses fmtlib style formatting - Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or std::puts()/std::fputs() (for unformatted strings). - A wpi/fmt/raw_ostream.h header has been added to enable fmt::print() with wpi::raw_ostream
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
// Copyright (c) FIRST and other WPILib contributors.
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
#include "frc/Tracer.h"
|
|
|
|
#include <fmt/format.h>
|
|
#include <wpi/SmallString.h>
|
|
#include <wpi/raw_ostream.h>
|
|
|
|
#include "frc/Errors.h"
|
|
|
|
using namespace frc;
|
|
|
|
Tracer::Tracer() {
|
|
ResetTimer();
|
|
}
|
|
|
|
void Tracer::ResetTimer() {
|
|
m_startTime = hal::fpga_clock::now();
|
|
}
|
|
|
|
void Tracer::ClearEpochs() {
|
|
ResetTimer();
|
|
m_epochs.clear();
|
|
}
|
|
|
|
void Tracer::AddEpoch(std::string_view epochName) {
|
|
auto currentTime = hal::fpga_clock::now();
|
|
m_epochs[epochName] = currentTime - m_startTime;
|
|
m_startTime = currentTime;
|
|
}
|
|
|
|
void Tracer::PrintEpochs() {
|
|
wpi::SmallString<128> buf;
|
|
wpi::raw_svector_ostream os(buf);
|
|
PrintEpochs(os);
|
|
if (!buf.empty()) {
|
|
FRC_ReportError(warn::Warning, "{}", buf.c_str());
|
|
}
|
|
}
|
|
|
|
void Tracer::PrintEpochs(wpi::raw_ostream& os) {
|
|
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) {
|
|
os << fmt::format(
|
|
"\t{}: {:.6f}s\n", epoch.getKey(),
|
|
duration_cast<microseconds>(epoch.getValue()).count() / 1.0e6);
|
|
}
|
|
}
|
|
}
|