CI: added sync test with memory leak detection
This commit is contained in:
+3
-4
@@ -81,9 +81,6 @@ void p2pool_version()
|
||||
printf("P2Pool %s\n", p2pool::VERSION);
|
||||
}
|
||||
|
||||
void memory_tracking_start();
|
||||
void memory_tracking_stop();
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc == 1) {
|
||||
@@ -124,7 +121,9 @@ int main(int argc, char* argv[])
|
||||
|
||||
p2pool::destroy_crypto_cache();
|
||||
|
||||
memory_tracking_stop();
|
||||
if (!memory_tracking_stop()) {
|
||||
result = 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
#include "common.h"
|
||||
|
||||
// Simple memory leak detector for Windows users, works best in RelWithDebInfo configuration.
|
||||
#if defined(_WIN32) && 0
|
||||
#if defined(_WIN32) && defined(DEV_TRACK_MEMORY)
|
||||
|
||||
#include "uv_util.h"
|
||||
#include <atomic>
|
||||
#include <type_traits>
|
||||
#include <iostream>
|
||||
|
||||
#include <DbgHelp.h>
|
||||
|
||||
@@ -87,7 +88,7 @@ uint32_t num_allocations = 0;
|
||||
uint64_t total_allocated = 0;
|
||||
uint32_t cur_allocation_index = 1;
|
||||
|
||||
void show_top_10()
|
||||
void show_top_10_allocations()
|
||||
{
|
||||
TrackedAllocation* buf = reinterpret_cast<TrackedAllocation*>(VirtualAlloc(nullptr, sizeof(TrackedAllocation) * N, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));
|
||||
if (!buf) {
|
||||
@@ -263,6 +264,9 @@ void* calloc_hook(size_t count, size_t size) noexcept
|
||||
|
||||
void memory_tracking_start()
|
||||
{
|
||||
// Trigger std::ostream initialization to avoid reporting it as leaks
|
||||
std::cout << "Memory leak detection = " << 1 << std::endl;
|
||||
|
||||
SymInitialize(GetCurrentProcess(), NULL, TRUE);
|
||||
|
||||
using namespace p2pool;
|
||||
@@ -272,7 +276,7 @@ void memory_tracking_start()
|
||||
track_memory = true;
|
||||
}
|
||||
|
||||
void memory_tracking_stop()
|
||||
bool memory_tracking_stop()
|
||||
{
|
||||
using namespace p2pool;
|
||||
|
||||
@@ -298,6 +302,8 @@ void memory_tracking_stop()
|
||||
}
|
||||
|
||||
SymCleanup(h);
|
||||
|
||||
return (total_leaks == 0);
|
||||
}
|
||||
|
||||
NOINLINE void* operator new(size_t n) { return p2pool::allocate(n); }
|
||||
@@ -313,7 +319,7 @@ NOINLINE void operator delete[](void* p, size_t) noexcept { p2pool::free_hook(p)
|
||||
// cppcheck-suppress functionStatic
|
||||
void memory_tracking_start() {}
|
||||
// cppcheck-suppress functionStatic
|
||||
void memory_tracking_stop() {}
|
||||
bool memory_tracking_stop() { return true; }
|
||||
|
||||
namespace p2pool {
|
||||
|
||||
|
||||
+3
-3
@@ -1152,7 +1152,7 @@ void P2PServer::download_missing_blocks()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!m_missingBlockRequests.insert({ client->m_peerId, *id.u64() }).second) {
|
||||
if (!m_missingBlockRequests.emplace(client->m_peerId, *id.u64()).second) {
|
||||
// We already asked this peer about this block
|
||||
// Don't try to ask another peer, leave it for another timer tick
|
||||
continue;
|
||||
@@ -2362,7 +2362,7 @@ void P2PServer::P2PClient::on_block_notify(const uint8_t* buf)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!server->m_blockNotifyRequests.insert(*id.u64()).second || !server->m_missingBlockRequests.insert({ m_peerId, *id.u64() }).second) {
|
||||
if (!server->m_blockNotifyRequests.insert(*id.u64()).second || !server->m_missingBlockRequests.emplace(m_peerId, *id.u64()).second) {
|
||||
LOGINFO(6, "BLOCK_REQUEST for id = " << id << " was already sent");
|
||||
return;
|
||||
}
|
||||
@@ -2541,7 +2541,7 @@ void P2PServer::P2PClient::post_handle_incoming_block(const PoolBlock& block, co
|
||||
}
|
||||
}
|
||||
|
||||
if (!server->m_missingBlockRequests.insert({ m_peerId, *id.u64() }).second) {
|
||||
if (!server->m_missingBlockRequests.emplace(m_peerId, *id.u64()).second) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -2104,6 +2104,9 @@ void SideChain::prune_old_blocks()
|
||||
|
||||
if (cur_time >= m_firstPruneTime + 120) {
|
||||
LOGINFO(0, log::LightGreen() << "[DEV] Synchronization finished successfully, stopping P2Pool now");
|
||||
#ifdef DEV_TRACK_MEMORY
|
||||
show_top_10_allocations();
|
||||
#endif
|
||||
print_status(false);
|
||||
P2PServer* server = m_pool->p2p_server();
|
||||
if (server) {
|
||||
|
||||
+5
-1
@@ -301,10 +301,14 @@ bool get_dns_txt_records_base(const std::string& host, Callback<void, const char
|
||||
template<typename T>
|
||||
FORCEINLINE bool get_dns_txt_records(const std::string& host, T&& callback) { return get_dns_txt_records_base(host, Callback<void, const char*, size_t>::Derived<T>(std::move(callback))); }
|
||||
|
||||
#ifdef DEV_TRACK_MEMORY
|
||||
void show_top_10_allocations();
|
||||
#endif
|
||||
|
||||
} // namespace p2pool
|
||||
|
||||
void memory_tracking_start();
|
||||
void memory_tracking_stop();
|
||||
bool memory_tracking_stop();
|
||||
void p2pool_usage();
|
||||
void p2pool_version();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user