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