mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
encapsulate and instrument
This commit is contained in:
42
include/xrpl/basics/MallocTrim.h
Normal file
42
include/xrpl/basics/MallocTrim.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef XRPL_BASICS_MALLOCTRIM_H_INCLUDED
|
||||
#define XRPL_BASICS_MALLOCTRIM_H_INCLUDED
|
||||
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
struct MallocTrimReport
|
||||
{
|
||||
bool supported{false};
|
||||
int trimResult{-1};
|
||||
long rssBeforeKB{-1};
|
||||
long rssAfterKB{-1};
|
||||
|
||||
long
|
||||
deltaKB() const
|
||||
{
|
||||
return rssAfterKB - rssBeforeKB;
|
||||
}
|
||||
};
|
||||
|
||||
/** Attempt to return freed memory to the operating system.
|
||||
*
|
||||
* This function is only effective on Linux with glibc. On other platforms,
|
||||
* it returns a report indicating the operation is unsupported.
|
||||
*
|
||||
* @param tag Optional identifier for logging/debugging purposes
|
||||
* @param journal Journal for logging diagnostic information
|
||||
* @return Report containing before/after memory metrics
|
||||
*
|
||||
* @note This is intended for use after cache sweeps or other operations
|
||||
* that free significant amounts of memory.
|
||||
*/
|
||||
MallocTrimReport
|
||||
mallocTrim(std::optional<std::string> const& tag, beast::Journal journal);
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
#endif
|
||||
@@ -2,12 +2,9 @@
|
||||
#define XRPL_BASICS_TAGGEDCACHE_IPP_INCLUDED
|
||||
|
||||
#include <xrpl/basics/IntrusivePointer.ipp>
|
||||
#include <xrpl/basics/MallocTrim.h>
|
||||
#include <xrpl/basics/TaggedCache.h>
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
namespace ripple {
|
||||
|
||||
template <
|
||||
@@ -331,9 +328,7 @@ TaggedCache<
|
||||
.count()
|
||||
<< "ms";
|
||||
|
||||
#ifdef __GLIBC__
|
||||
(void)malloc_trim(0);
|
||||
#endif
|
||||
mallocTrim(std::optional<std::string>(m_name), m_journal);
|
||||
}
|
||||
|
||||
template <
|
||||
|
||||
Reference in New Issue
Block a user