Skip to content

Commit

Permalink
wip: added true sample time indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed May 8, 2024
1 parent 91fafe3 commit d376e5d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/Gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ void Gui::drawStartButton(PlotHandlerBase* activePlotHandler)

ImGui::PopStyleColor(3);
ImGui::EndDisabled();

drawDescriptionWithNumber("Average sampling frequency: ", plotHandler->getAverageSamplingFrequency());
}

void Gui::drawDebugProbes()
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/GuiPlots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void Gui::drawPlotCurve(Plot* plot, ScrollingBuffer<double>& time, std::map<std:
PlotHandler::Settings settings = plotHandler->getSettings();
ImPlot::SetupAxis(ImAxis_Y1, NULL, ImPlotAxisFlags_AutoFit);
ImPlot::SetupAxis(ImAxis_X1, "time[s]", 0);
const double viewportWidth = plotHandler->getAverageSamplingPeriod() * settings.maxViewportPoints;
const double viewportWidth = plotHandler->getAverageSamplingFrequency() * settings.maxViewportPoints;
const double min = *time.getLastElement() < viewportWidth ? 0.0f : *time.getLastElement() - viewportWidth;
const double max = min == 0.0f ? *time.getLastElement() : min + viewportWidth;
ImPlot::SetupAxisLimits(ImAxis_X1, min, max, ImPlotCond_Always);
Expand Down
12 changes: 6 additions & 6 deletions src/PlotHandler/PlotHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void PlotHandler::setProbeSettings(const IDebugProbe::DebugProbeSettings& settin

void PlotHandler::dataHandler()
{
std::chrono::time_point<std::chrono::steady_clock> start;
uint32_t timer = 0;
double lastT = 0.0;
double sum = 0.0;
Expand All @@ -66,9 +67,8 @@ void PlotHandler::dataHandler()
{
if (viewerState == state::RUN)
{
std::this_thread::sleep_for(std::chrono::microseconds(100));
auto finish = std::chrono::steady_clock::now();
double t = std::chrono::duration_cast<std::chrono::duration<double>>(finish - start).count();
double period = std::chrono::duration_cast<std::chrono::duration<double>>(finish - start).count();

if (probeSettings.mode == IDebugProbe::Mode::HSS)
{
Expand Down Expand Up @@ -97,7 +97,7 @@ void PlotHandler::dataHandler()
timer++;
}

else if (t > ((1.0 / settings.sampleFrequencyHz) * timer))
else if (period > ((1.0 / settings.sampleFrequencyHz) * timer))
{
for (auto& [key, plot] : plotsMap)
{
Expand All @@ -118,14 +118,14 @@ void PlotHandler::dataHandler()
std::lock_guard<std::mutex> lock(*mtx);
for (auto& [name, ser] : plot->getSeriesMap())
plot->addPoint(name, ser->var->getValue());
plot->addTimePoint(t);
plot->addTimePoint(period);
}
timer++;
}

sum += (t - lastT);
sum += (period - lastT);
averageSamplingFrequency = sum / timer;
lastT = t;
lastT = period;
}
else
std::this_thread::sleep_for(std::chrono::milliseconds(20));
Expand Down
3 changes: 1 addition & 2 deletions src/PlotHandler/PlotHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ class PlotHandler : public PlotHandlerBase
void setProbeSettings(const IDebugProbe::DebugProbeSettings& settings);

void setDebugProbe(std::shared_ptr<IDebugProbe> probe);
double getAverageSamplingPeriod() const { return averageSamplingFrequency; }
double getAverageSamplingFrequency() const { return averageSamplingFrequency; }

private:
void dataHandler();
std::vector<std::pair<uint32_t, uint8_t>> createAddressSizeVector();

private:
std::unique_ptr<TargetMemoryHandler> varReader;
std::chrono::time_point<std::chrono::steady_clock> start;
IDebugProbe::DebugProbeSettings probeSettings{};
Settings settings{};
double averageSamplingFrequency;
Expand Down

0 comments on commit d376e5d

Please sign in to comment.