This commit is contained in:
Lion Kortlepel 2024-03-07 00:45:00 +01:00
parent e4826e8bf1
commit c85e026c2d
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
4 changed files with 10 additions and 5 deletions

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <boost/circular_buffer.hpp>
#include <boost/thread/synchronized_value.hpp> #include <boost/thread/synchronized_value.hpp>
#include <chrono> #include <chrono>
#include <cstddef> #include <cstddef>
#include <limits> #include <limits>
#include <unordered_map>
namespace prof { namespace prof {
@ -38,9 +38,10 @@ struct UnitExecutionTime {
Stats stats() const; Stats stats() const;
/// Returns the number of elements the moving average is calculated over. /// Returns the number of elements the moving average is calculated over.
size_t measurement_count() const { return m_total_calls; } size_t measurement_count() const;
private: private:
std::mutex m_mtx {};
size_t m_total_calls {}; size_t m_total_calls {};
double m_sum {}; double m_sum {};
// sum of measurements squared (for running stdev) // sum of measurements squared (for running stdev)

View File

@ -20,6 +20,7 @@ void prof::UnitProfileCollection::add_sample(const std::string& unit, const Dura
} }
prof::Stats prof::UnitExecutionTime::stats() const { prof::Stats prof::UnitExecutionTime::stats() const {
std::unique_lock lock(m_mtx);
Stats result {}; Stats result {};
// calculate sum // calculate sum
result.n = m_total_calls; result.n = m_total_calls;
@ -33,6 +34,7 @@ prof::Stats prof::UnitExecutionTime::stats() const {
} }
void prof::UnitExecutionTime::add_sample(const Duration& dur) { void prof::UnitExecutionTime::add_sample(const Duration& dur) {
std::unique_lock lock(m_mtx);
m_sum += dur.count(); m_sum += dur.count();
m_measurement_sqr_sum += dur.count() * dur.count(); m_measurement_sqr_sum += dur.count() * dur.count();
m_min = std::min(dur.count(), m_min); m_min = std::min(dur.count(), m_min);
@ -51,3 +53,8 @@ std::unordered_map<std::string, prof::Stats> prof::UnitProfileCollection::all_st
} }
return result; return result;
} }
size_t prof::UnitExecutionTime::measurement_count() const {
std::unique_lock lock(m_mtx);
return m_total_calls;
}

View File

@ -20,7 +20,6 @@
#include "Common.h" #include "Common.h"
#include "Http.h" #include "Http.h"
#include "LuaAPI.h" #include "LuaAPI.h"
#include "Profiling.h"
#include "SignalHandling.h" #include "SignalHandling.h"
#include "TConfig.h" #include "TConfig.h"
#include "THeartbeatThread.h" #include "THeartbeatThread.h"
@ -31,7 +30,6 @@
#include "TResourceManager.h" #include "TResourceManager.h"
#include "TServer.h" #include "TServer.h"
#include <chrono>
#include <iostream> #include <iostream>
#include <thread> #include <thread>

View File

@ -6,7 +6,6 @@
"boost-spirit", "boost-spirit",
"boost-uuid", "boost-uuid",
"boost-variant", "boost-variant",
"boost-circular-buffer",
"cpp-httplib", "cpp-httplib",
"doctest", "doctest",
"fmt", "fmt",