mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-03 17:35:51 +00:00
Add logTimedDestroy and report in ~Ledger and ~SHAMap
This commit is contained in:
@@ -1511,6 +1511,7 @@
|
||||
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_Sustain.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_ThreadName.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_Time.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_TimedDestroy.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_UptimeTimer.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_client\ripple_client.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_core\functional\ripple_Config.h" />
|
||||
|
||||
@@ -1688,6 +1688,9 @@
|
||||
<ClInclude Include="..\..\modules\ripple_app\boost\ripple_SslContext.h">
|
||||
<Filter>[1] Ripple\ripple_app\boost</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_TimedDestroy.h">
|
||||
<Filter>[1] Ripple\ripple_basics\utility</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="..\..\modules\ripple_data\protocol\ripple.proto">
|
||||
|
||||
@@ -174,38 +174,18 @@ Ledger::Ledger (const std::string& rawLedger, bool hasPrefix) :
|
||||
|
||||
Ledger::~Ledger ()
|
||||
{
|
||||
double txDeleteSeconds = 0;
|
||||
|
||||
if (mTransactionMap)
|
||||
{
|
||||
int64 const startTime (Time::getHighResolutionTicks ());
|
||||
|
||||
mTransactionMap.reset ();
|
||||
|
||||
txDeleteSeconds = Time::highResolutionTicksToSeconds (
|
||||
Time::getHighResolutionTicks () - startTime);
|
||||
logTimedDestroy <Ledger> (mTransactionMap,
|
||||
String ("mTransactionMap with ") +
|
||||
String::fromNumber (mTransactionMap->size ()) + " items");
|
||||
}
|
||||
|
||||
double acctDeleteSeconds = 0;
|
||||
|
||||
if (mAccountStateMap)
|
||||
{
|
||||
int64 const startTime (Time::getHighResolutionTicks ());
|
||||
|
||||
mAccountStateMap.reset ();
|
||||
|
||||
acctDeleteSeconds = Time::highResolutionTicksToSeconds (
|
||||
Time::getHighResolutionTicks () - startTime);
|
||||
}
|
||||
|
||||
if (txDeleteSeconds >= 1)
|
||||
{
|
||||
WriteLog (lsWARNING, Ledger) << "mTransactionMap took " <<
|
||||
String (txDeleteSeconds, 1) << " seconds to destroy.";
|
||||
}
|
||||
|
||||
if (acctDeleteSeconds >= 1)
|
||||
{
|
||||
WriteLog (lsWARNING, Ledger) << "mAccountStateMap took " <<
|
||||
String (acctDeleteSeconds, 1) << " seconds to destroy.";
|
||||
logTimedDestroy <Ledger> (mAccountStateMap,
|
||||
String ("mAccountStateMap with ") +
|
||||
String::fromNumber (mAccountStateMap->size ()) + " items");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,28 @@
|
||||
|
||||
SETUP_LOG (SHAMap)
|
||||
|
||||
SHAMap::~SHAMap ()
|
||||
{
|
||||
mState = smsInvalid;
|
||||
|
||||
logTimedDestroy <SHAMap> (mTNByID,
|
||||
String ("mTNByID with ") +
|
||||
String::fromNumber (mTNByID.size ()) + " items");
|
||||
|
||||
if (mDirtyNodes)
|
||||
{
|
||||
logTimedDestroy <SHAMap> (mDirtyNodes,
|
||||
String ("mDirtyNodes with ") +
|
||||
String::fromNumber (mDirtyNodes->size ()) + " items");
|
||||
}
|
||||
|
||||
if (root)
|
||||
{
|
||||
logTimedDestroy <SHAMap> (root,
|
||||
String ("root node"));
|
||||
}
|
||||
}
|
||||
|
||||
void SHAMapNode::setMHash () const
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
@@ -34,9 +34,11 @@ public:
|
||||
explicit SHAMap (SHAMapType t, uint32 seq = 1);
|
||||
SHAMap (SHAMapType t, uint256 const & hash);
|
||||
|
||||
~SHAMap ()
|
||||
~SHAMap ();
|
||||
|
||||
std::size_t size () const noexcept
|
||||
{
|
||||
mState = smsInvalid;
|
||||
return mTNByID.size ();
|
||||
}
|
||||
|
||||
// Returns a new map that's a snapshot of this one. Force CoW
|
||||
|
||||
@@ -90,6 +90,7 @@ using namespace beast;
|
||||
#include "utility/ripple_Sustain.h"
|
||||
#include "utility/ripple_ThreadName.h"
|
||||
#include "utility/ripple_Time.h"
|
||||
#include "utility/ripple_TimedDestroy.h"
|
||||
#include "utility/ripple_UptimeTimer.h"
|
||||
|
||||
#include "types/ripple_UInt256.h"
|
||||
|
||||
90
modules/ripple_basics/utility/ripple_TimedDestroy.h
Normal file
90
modules/ripple_basics/utility/ripple_TimedDestroy.h
Normal file
@@ -0,0 +1,90 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_TIMEDDESTROY_H_INCLUDED
|
||||
#define RIPPLE_TIMEDDESTROY_H_INCLUDED
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/** Template class that performs destruction of an object.
|
||||
Default implementation simply calls delete
|
||||
*/
|
||||
template <typename Object>
|
||||
struct Destroyer
|
||||
{
|
||||
static void destroy (Object& object)
|
||||
{
|
||||
delete &object;
|
||||
}
|
||||
};
|
||||
|
||||
/** Specialization for boost::shared_ptr.
|
||||
*/
|
||||
template <typename Object>
|
||||
struct Destroyer <boost::shared_ptr <Object> >
|
||||
{
|
||||
static void destroy (boost::shared_ptr <Object>& p)
|
||||
{
|
||||
p.reset ();
|
||||
}
|
||||
};
|
||||
|
||||
/** Specialization for boost::unordered_map
|
||||
*/
|
||||
template <typename Key, typename Value>
|
||||
struct Destroyer <boost::unordered_map <Key, Value> >
|
||||
{
|
||||
static void destroy (boost::unordered_map <Key, Value>& v)
|
||||
{
|
||||
v.clear ();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Measure the time required to destroy an object.
|
||||
*/
|
||||
|
||||
template <typename Object>
|
||||
double timedDestroy (Object& object)
|
||||
{
|
||||
int64 const startTime (Time::getHighResolutionTicks ());
|
||||
|
||||
detail::Destroyer <Object>::destroy (object);
|
||||
|
||||
return Time::highResolutionTicksToSeconds (
|
||||
Time::getHighResolutionTicks () - startTime);
|
||||
}
|
||||
|
||||
/** Log the destruction of an object if the time exceeds a threshold.
|
||||
*/
|
||||
template <typename PartitionKey, typename Object>
|
||||
void logTimedDestroy (
|
||||
Object& object, String objectDescription, double thresholdSeconds = 1)
|
||||
{
|
||||
double seconds = timedDestroy (object);
|
||||
|
||||
if (seconds > thresholdSeconds)
|
||||
{
|
||||
LogSeverity const severity = lsWARNING;
|
||||
|
||||
if (seconds >= 10)
|
||||
seconds = std::floor (seconds + 0.5);
|
||||
else
|
||||
seconds = static_cast <int> ((seconds * 10 + 0.5) / 10);
|
||||
|
||||
Log (severity, LogPartition::get <PartitionKey> ()) <<
|
||||
objectDescription << " took "<<
|
||||
String (seconds) <<
|
||||
" seconds to destroy";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user