mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-03 17:35:51 +00:00
Add profiler
This commit is contained in:
48
include/xrpl/beast/core/FunctionProfiler.h
Normal file
48
include/xrpl/beast/core/FunctionProfiler.h
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
#ifndef RIPPLE_BASICS_FUNCTIONPROFILER_H_INCLUDED
|
||||
#define RIPPLE_BASICS_FUNCTIONPROFILER_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
#include <sstream>
|
||||
#include <source_location>
|
||||
#include <csignal>
|
||||
|
||||
namespace beast {
|
||||
|
||||
void logProfilingResults();
|
||||
class FunctionProfiler
|
||||
{
|
||||
std::string functionName;
|
||||
std::chrono::steady_clock::time_point start;
|
||||
public:
|
||||
|
||||
inline static std::unordered_map<std::string, std::chrono::nanoseconds> funcionDurations;
|
||||
FunctionProfiler(std::source_location location = std::source_location::current()): functionName(location.function_name()), start(std::chrono::steady_clock::now())
|
||||
{
|
||||
}
|
||||
|
||||
~FunctionProfiler() noexcept
|
||||
{
|
||||
auto duration = std::chrono::steady_clock::now() - start;
|
||||
funcionDurations[functionName] += std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
inline std::string getProfilingResults()
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Function profiling results:" << std::endl;
|
||||
for (const auto& [name, duration] : FunctionProfiler::funcionDurations)
|
||||
{
|
||||
ss << " " << name << ": " << duration.count() << " ns" << std::endl;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <cstddef>
|
||||
#include <new>
|
||||
#include <type_traits>
|
||||
#include <xrpl/beast/core/FunctionProfiler.h>
|
||||
|
||||
namespace beast {
|
||||
|
||||
@@ -88,12 +89,14 @@ public:
|
||||
void
|
||||
operator()(void const* key, std::size_t len) noexcept
|
||||
{
|
||||
FunctionProfiler _;
|
||||
XXH3_64bits_update(state_, key, len);
|
||||
}
|
||||
|
||||
explicit
|
||||
operator std::size_t() noexcept
|
||||
{
|
||||
FunctionProfiler _;
|
||||
return XXH3_64bits_digest(state_);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
#include <xrpl/protocol/Protocol.h>
|
||||
#include <xrpl/protocol/STParsedJSON.h>
|
||||
#include <xrpl/resource/Fees.h>
|
||||
#include <xrpl/beast/core/FunctionProfiler.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
@@ -1647,6 +1648,9 @@ ApplicationImp::run()
|
||||
void
|
||||
ApplicationImp::signalStop(std::string msg)
|
||||
{
|
||||
std::cout << "signal stop!!!" << std::endl;
|
||||
JLOG(m_journal.warn()) << beast::getProfilingResults();
|
||||
|
||||
if (!isTimeToStop.exchange(true))
|
||||
{
|
||||
if (msg.empty())
|
||||
|
||||
Reference in New Issue
Block a user