mirror of
https://github.com/SlimeVR/SlimeVR-Tracker-ESP.git
synced 2026-04-06 02:01:57 +02:00
fix formating try 1
This commit is contained in:
@@ -22,7 +22,9 @@
|
||||
|
||||
namespace SlimeVR::Debugging {
|
||||
|
||||
void TimeTakenMeasurer::before(int measurement) { timings[measurement].start = micros(); }
|
||||
void TimeTakenMeasurer::before(int measurement) {
|
||||
timings[measurement].start = micros();
|
||||
}
|
||||
void TimeTakenMeasurer::after(int measurement) { timings[measurement].end = micros(); }
|
||||
|
||||
void TimeTakenMeasurer::calculate() {
|
||||
@@ -50,7 +52,7 @@ void TimeTakenMeasurer::nextPeriod() {
|
||||
lastTimingsPrint = millis();
|
||||
for (auto& timing : timings) {
|
||||
timing.timeTakenPercent = static_cast<float>(timing.timeTaken) / 1e3f
|
||||
/ static_cast<float>(sinceLastReportMillis) * 100;
|
||||
/ static_cast<float>(sinceLastReportMillis) * 100;
|
||||
timing.timeTotal = sinceLastReportMillis;
|
||||
timing.avg = timing.timeTaken / max(timing.count, 1ul);
|
||||
}
|
||||
@@ -75,10 +77,12 @@ void TimeTakenMeasurer::nextPeriod() {
|
||||
void TimeTakenMeasurer::report() {
|
||||
unsigned long totalTime = 0;
|
||||
unsigned long count = 0;
|
||||
for (size_t i = 0; i < pasttimings.size(); ++i) {
|
||||
const auto& timing = pasttimings[i];
|
||||
const auto& name = names[i];
|
||||
m_Logger.info("%-24s | avg: %5lu us | min: %5lu us | max: %5lu us | time taken: %5lu ms or %5.2f%% of %lu ms count: %lu",
|
||||
for (size_t i = 0; i < pasttimings.size(); ++i) {
|
||||
const auto& timing = pasttimings[i];
|
||||
const auto& name = names[i];
|
||||
m_Logger.info(
|
||||
"%-24s | avg: %5lu us | min: %5lu us | max: %5lu us | time taken: %5lu ms "
|
||||
"or %5.2f%% of %lu ms count: %lu",
|
||||
name.c_str(),
|
||||
timing.avg,
|
||||
timing.min,
|
||||
@@ -89,9 +93,14 @@ void TimeTakenMeasurer::report() {
|
||||
timing.count
|
||||
);
|
||||
totalTime = max(timing.timeTotal, totalTime);
|
||||
count = max (timing.count, count);
|
||||
count = max(timing.count, count);
|
||||
}
|
||||
m_Logger.info("Time Total: %lu ms Loops: %lu PrintReport Time: %lu ms", totalTime, count, millis()-lastTimingsPrint);
|
||||
m_Logger.info(
|
||||
"Time Total: %lu ms Loops: %lu PrintReport Time: %lu ms",
|
||||
totalTime,
|
||||
count,
|
||||
millis() - lastTimingsPrint
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace SlimeVR::Debugging
|
||||
|
||||
@@ -59,7 +59,6 @@ public:
|
||||
for (const auto& name : names) {
|
||||
this->names.push_back(name);
|
||||
this->timings.push_back({0, 2 ^ 64, 0, 0, 0, 0, 0, 0});
|
||||
//this->timingPoints.push_back({0, 0});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +66,6 @@ public:
|
||||
void after(int measurement);
|
||||
void calculate();
|
||||
|
||||
|
||||
private:
|
||||
void nextPeriod();
|
||||
void report();
|
||||
@@ -79,7 +77,7 @@ private:
|
||||
|
||||
std::vector<TimingMeasurement> pasttimings;
|
||||
SlimeVR::Logging::Logger m_Logger = SlimeVR::Logging::Logger("TimeTaken");
|
||||
unsigned long lastTimeTakenReportMillis = 0;
|
||||
unsigned long lastTimeTakenReportMillis = 0;
|
||||
};
|
||||
|
||||
} // namespace SlimeVR::Debugging
|
||||
|
||||
38
src/main.cpp
38
src/main.cpp
@@ -48,26 +48,23 @@ SlimeVR::Network::Connection networkConnection;
|
||||
// The order of the names should match the order of the measurements in the
|
||||
// timings array
|
||||
// The names are used to identify the measurements in the report
|
||||
std::vector<const char*> timingNames = {
|
||||
"tpsCounter.update()",
|
||||
"globalTimer.tick()",
|
||||
"Serial update()",
|
||||
"OTA::otaUpdate()",
|
||||
"networkManager.update()",
|
||||
"sensorManager.update()",
|
||||
"battery.Loop()",
|
||||
"ledManager.update()",
|
||||
"I2CSCAN::update()",
|
||||
"TARGET_LOOPTIME_MICROS",
|
||||
"Serial printState()",
|
||||
"IMU1 Sensor loop",
|
||||
"IMU2 Sensor loop"
|
||||
};
|
||||
std::vector<const char*> timingNames
|
||||
= {"tpsCounter.update()",
|
||||
"globalTimer.tick()",
|
||||
"Serial update()",
|
||||
"OTA::otaUpdate()",
|
||||
"networkManager.update()",
|
||||
"sensorManager.update()",
|
||||
"battery.Loop()",
|
||||
"ledManager.update()",
|
||||
"I2CSCAN::update()",
|
||||
"TARGET_LOOPTIME_MICROS",
|
||||
"Serial printState()",
|
||||
"IMU1 Sensor loop",
|
||||
"IMU2 Sensor loop"};
|
||||
SlimeVR::Debugging::TimeTakenMeasurer timingsMeasurer(timingNames);
|
||||
#define BENCHMARK_START(number) \
|
||||
timingsMeasurer.before(number);
|
||||
#define BENCHMARK_END(number) \
|
||||
timingsMeasurer.after(number);
|
||||
#define BENCHMARK_START(number) timingsMeasurer.before(number);
|
||||
#define BENCHMARK_END(number) timingsMeasurer.after(number);
|
||||
#else
|
||||
#define BENCHMARK_START(number)
|
||||
#define BENCHMARK_END(number)
|
||||
@@ -173,7 +170,7 @@ void loop() {
|
||||
I2CSCAN::update();
|
||||
BENCHMARK_END(8)
|
||||
#ifdef TARGET_LOOPTIME_MICROS
|
||||
BENCHMARK_START(9)
|
||||
BENCHMARK_START(9)
|
||||
long elapsed = (micros() - loopTime);
|
||||
if (elapsed < TARGET_LOOPTIME_MICROS) {
|
||||
long sleepus = TARGET_LOOPTIME_MICROS - elapsed - 100; // µs to sleep
|
||||
@@ -202,5 +199,4 @@ void loop() {
|
||||
#if DEBUG_MEASURE_TIME_TAKEN
|
||||
timingsMeasurer.calculate();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -159,8 +159,7 @@ void SensorManager::update() {
|
||||
#endif
|
||||
for (auto& sensor : m_Sensors) {
|
||||
#if DEBUG_MEASURE_TIME_TAKEN
|
||||
|
||||
timingsMeasurer.before(11+sensorcount);
|
||||
timingsMeasurer.before(11 + sensorcount);
|
||||
#endif
|
||||
if (sensor->isWorking()) {
|
||||
if (sensor->m_hwInterface != nullptr) {
|
||||
@@ -172,7 +171,7 @@ void SensorManager::update() {
|
||||
allIMUGood = false;
|
||||
}
|
||||
#if DEBUG_MEASURE_TIME_TAKEN
|
||||
timingsMeasurer.after(11+sensorcount);
|
||||
timingsMeasurer.after(11 + sensorcount);
|
||||
sensorcount++;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user