wip
This commit is contained in:
parent
fb8182a10e
commit
270f187e2a
@ -2,6 +2,7 @@
|
||||
#define MEMINFO_HPP
|
||||
|
||||
#include "util/log.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/resource.h>
|
||||
@ -10,18 +11,27 @@
|
||||
namespace osrm::util
|
||||
{
|
||||
|
||||
inline void DumpMemoryStats()
|
||||
inline size_t PeakRAMUsedInBytes()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
rusage usage;
|
||||
getrusage(RUSAGE_SELF, &usage);
|
||||
#ifdef __linux__
|
||||
// Under linux, ru.maxrss is in kb
|
||||
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss * 1024;
|
||||
return usage.ru_maxrss * 1024;
|
||||
#else // __linux__
|
||||
// Under BSD systems (OSX), it's in bytes
|
||||
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss;
|
||||
return usage.ru_maxrss;
|
||||
#endif // __linux__
|
||||
#else // _WIN32
|
||||
return 0;
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
inline void DumpMemoryStats()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
util::Log() << "RAM: peak bytes used: " << PeakRAMUsedInBytes();
|
||||
#else // _WIN32
|
||||
util::Log() << "RAM: peak bytes used: <not implemented on Windows>";
|
||||
#endif // _WIN32
|
||||
|
@ -14,14 +14,14 @@
|
||||
namespace osrm::util
|
||||
{
|
||||
|
||||
#if 1
|
||||
|
||||
template <typename T, size_t MinItemsInBlock = 1024>
|
||||
template <typename T>
|
||||
class PoolAllocator;
|
||||
|
||||
template <typename T, size_t MinItemsInBlock = 1024>
|
||||
template <typename T>
|
||||
class MemoryManager
|
||||
{
|
||||
private:
|
||||
constexpr static size_t MIN_ITEMS_IN_BLOCK = 1024;
|
||||
public:
|
||||
static std::shared_ptr<MemoryManager> instance()
|
||||
{
|
||||
@ -82,7 +82,7 @@ private:
|
||||
|
||||
void allocate_block(size_t items_in_block)
|
||||
{
|
||||
items_in_block = std::max(items_in_block, MinItemsInBlock);
|
||||
items_in_block = std::max(items_in_block, MIN_ITEMS_IN_BLOCK);
|
||||
|
||||
size_t block_size = items_in_block * sizeof(T);
|
||||
T *block = static_cast<T *>(std::malloc(block_size));
|
||||
@ -104,21 +104,21 @@ private:
|
||||
size_t total_allocated_ = 0;
|
||||
};
|
||||
|
||||
template <typename T, size_t MinItemsInBlock>
|
||||
template <typename T>
|
||||
class PoolAllocator
|
||||
{
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
PoolAllocator() noexcept : pool(MemoryManager<T, MinItemsInBlock>::instance()) {};
|
||||
PoolAllocator() noexcept : pool(MemoryManager<T>::instance()) {};
|
||||
|
||||
template <typename U>
|
||||
PoolAllocator(const PoolAllocator<U> &) noexcept : pool(MemoryManager<T, MinItemsInBlock>::instance()) {}
|
||||
PoolAllocator(const PoolAllocator<U> &) noexcept : pool(MemoryManager<T>::instance()) {}
|
||||
|
||||
template <typename U>
|
||||
struct rebind
|
||||
{
|
||||
using other = PoolAllocator<U, MinItemsInBlock>;
|
||||
using other = PoolAllocator<U>;
|
||||
};
|
||||
|
||||
T *allocate(std::size_t n)
|
||||
@ -139,13 +139,7 @@ public:
|
||||
PoolAllocator &operator=(PoolAllocator &&) noexcept = default;
|
||||
|
||||
private:
|
||||
std::shared_ptr<MemoryManager<T, MinItemsInBlock>> pool;
|
||||
|
||||
static size_t get_next_power_of_two_exponent(size_t n)
|
||||
{
|
||||
BOOST_ASSERT(n > 0);
|
||||
return (sizeof(size_t) * 8) - std::countl_zero(n - 1);
|
||||
}
|
||||
std::shared_ptr<MemoryManager<T>> pool;
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
@ -160,7 +154,4 @@ bool operator!=(const PoolAllocator<T> &, const PoolAllocator<U> &)
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
template <typename T> using PoolAllocator = std::allocator<T>;
|
||||
#endif
|
||||
} // namespace osrm::util
|
||||
|
@ -194,8 +194,7 @@ template <typename NodeID,
|
||||
typename Key,
|
||||
typename Weight,
|
||||
typename Data,
|
||||
typename IndexStorage = ArrayStorage<NodeID, NodeID>,
|
||||
bool ThreadLocal = true>
|
||||
typename IndexStorage = ArrayStorage<NodeID, NodeID>>
|
||||
class QueryHeap
|
||||
{
|
||||
private:
|
||||
@ -214,16 +213,13 @@ class QueryHeap
|
||||
}
|
||||
};
|
||||
|
||||
using AllocatorType = typename std::conditional<ThreadLocal,
|
||||
PoolAllocator<HeapData>,
|
||||
std::allocator<HeapData>>::type;
|
||||
|
||||
|
||||
using HeapContainer = boost::heap::d_ary_heap<HeapData,
|
||||
boost::heap::arity<4>,
|
||||
boost::heap::mutable_<true>,
|
||||
boost::heap::compare<std::greater<HeapData>>,
|
||||
boost::heap::allocator<AllocatorType>>;
|
||||
boost::heap::allocator<PoolAllocator<HeapData>>>;
|
||||
using HeapHandle = typename HeapContainer::handle_type;
|
||||
|
||||
public:
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "osrm/coordinate.hpp"
|
||||
#include "osrm/engine_config.hpp"
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
#include "util/meminfo.hpp"
|
||||
#include "osrm/osrm.hpp"
|
||||
#include "osrm/status.hpp"
|
||||
|
||||
@ -655,6 +655,8 @@ try
|
||||
std::cerr << "Unknown benchmark: " << benchmarkToRun << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::cerr << "Peak RAM: " << osrm::util::PeakRAMUsedInBytes() / (1024 * 1024) << "MB" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
|
@ -65,4 +65,4 @@ benchmark: data $(DATA_NAME).requests
|
||||
checksum:
|
||||
$(MD5SUM) $(DATA_NAME).osm.pbf $(DATA_NAME).poly > data.md5sum
|
||||
|
||||
.PHONY: clean checksum data
|
||||
.PHONY: clean checksum benchmark data
|
Loading…
Reference in New Issue
Block a user