mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +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_Sustain.h" />
|
||||||
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_ThreadName.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_Time.h" />
|
||||||
|
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_TimedDestroy.h" />
|
||||||
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_UptimeTimer.h" />
|
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_UptimeTimer.h" />
|
||||||
<ClInclude Include="..\..\modules\ripple_client\ripple_client.h" />
|
<ClInclude Include="..\..\modules\ripple_client\ripple_client.h" />
|
||||||
<ClInclude Include="..\..\modules\ripple_core\functional\ripple_Config.h" />
|
<ClInclude Include="..\..\modules\ripple_core\functional\ripple_Config.h" />
|
||||||
|
|||||||
@@ -1688,6 +1688,9 @@
|
|||||||
<ClInclude Include="..\..\modules\ripple_app\boost\ripple_SslContext.h">
|
<ClInclude Include="..\..\modules\ripple_app\boost\ripple_SslContext.h">
|
||||||
<Filter>[1] Ripple\ripple_app\boost</Filter>
|
<Filter>[1] Ripple\ripple_app\boost</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_TimedDestroy.h">
|
||||||
|
<Filter>[1] Ripple\ripple_basics\utility</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CustomBuild Include="..\..\modules\ripple_data\protocol\ripple.proto">
|
<CustomBuild Include="..\..\modules\ripple_data\protocol\ripple.proto">
|
||||||
|
|||||||
@@ -174,38 +174,18 @@ Ledger::Ledger (const std::string& rawLedger, bool hasPrefix) :
|
|||||||
|
|
||||||
Ledger::~Ledger ()
|
Ledger::~Ledger ()
|
||||||
{
|
{
|
||||||
double txDeleteSeconds = 0;
|
if (mTransactionMap)
|
||||||
|
|
||||||
{
|
{
|
||||||
int64 const startTime (Time::getHighResolutionTicks ());
|
logTimedDestroy <Ledger> (mTransactionMap,
|
||||||
|
String ("mTransactionMap with ") +
|
||||||
mTransactionMap.reset ();
|
String::fromNumber (mTransactionMap->size ()) + " items");
|
||||||
|
|
||||||
txDeleteSeconds = Time::highResolutionTicksToSeconds (
|
|
||||||
Time::getHighResolutionTicks () - startTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double acctDeleteSeconds = 0;
|
if (mAccountStateMap)
|
||||||
|
|
||||||
{
|
{
|
||||||
int64 const startTime (Time::getHighResolutionTicks ());
|
logTimedDestroy <Ledger> (mAccountStateMap,
|
||||||
|
String ("mAccountStateMap with ") +
|
||||||
mAccountStateMap.reset ();
|
String::fromNumber (mAccountStateMap->size ()) + " items");
|
||||||
|
|
||||||
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.";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,28 @@
|
|||||||
|
|
||||||
SETUP_LOG (SHAMap)
|
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
|
void SHAMapNode::setMHash () const
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|||||||
@@ -34,9 +34,11 @@ public:
|
|||||||
explicit SHAMap (SHAMapType t, uint32 seq = 1);
|
explicit SHAMap (SHAMapType t, uint32 seq = 1);
|
||||||
SHAMap (SHAMapType t, uint256 const & hash);
|
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
|
// 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_Sustain.h"
|
||||||
#include "utility/ripple_ThreadName.h"
|
#include "utility/ripple_ThreadName.h"
|
||||||
#include "utility/ripple_Time.h"
|
#include "utility/ripple_Time.h"
|
||||||
|
#include "utility/ripple_TimedDestroy.h"
|
||||||
#include "utility/ripple_UptimeTimer.h"
|
#include "utility/ripple_UptimeTimer.h"
|
||||||
|
|
||||||
#include "types/ripple_UInt256.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