From bdb3183989d8544b15bf600a5018d7056d795da0 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 23 Mar 2022 16:13:44 +0000 Subject: [PATCH] Remove std::cout Now we have an allocation free formatting routine, remove std::cout from tracing. --- src/backend/backend.h | 5 ++--- src/backend/globalconfig.h | 2 +- src/ds/defines.h | 7 +++++++ src/mem/corealloc.h | 25 +++++++++++++------------ src/mem/globalalloc.h | 11 +++++------ src/mem/localalloc.h | 25 ++++++++++++------------- src/mem/threadalloc.h | 4 ++-- src/pal/pal_posix.h | 3 +-- 8 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/backend/backend.h b/src/backend/backend.h index 4c169d6..03f04f7 100644 --- a/src/backend/backend.h +++ b/src/backend/backend.h @@ -277,8 +277,7 @@ namespace snmalloc auto p = local_state.object_range->alloc_range(size); #ifdef SNMALLOC_TRACING - std::cout << "Alloc chunk: " << p.unsafe_ptr() << " (" << size << ")" - << std::endl; + message<1024>("Alloc chunk: {} ({})", p.unsafe_ptr(), size); #endif if (p == nullptr) { @@ -286,7 +285,7 @@ namespace snmalloc meta_cap, PAGEMAP_METADATA_STRUCT_SIZE); errno = ENOMEM; #ifdef SNMALLOC_TRACING - std::cout << "Out of memory" << std::endl; + message<1024>("Out of memory"); #endif return {p, nullptr}; } diff --git a/src/backend/globalconfig.h b/src/backend/globalconfig.h index a496aa3..3117662 100644 --- a/src/backend/globalconfig.h +++ b/src/backend/globalconfig.h @@ -60,7 +60,7 @@ namespace snmalloc { FlagLock lock{initialisation_lock}; #ifdef SNMALLOC_TRACING - std::cout << "Run init_impl" << std::endl; + message<1024>("Run init_impl"); #endif if (initialised) diff --git a/src/ds/defines.h b/src/ds/defines.h index 0503a85..869310d 100644 --- a/src/ds/defines.h +++ b/src/ds/defines.h @@ -205,6 +205,13 @@ namespace snmalloc */ template [[noreturn]] inline void report_fatal_error(Args... args); + + /** + * Forward declaration so that this can be called before the pal header is + * included. + */ + template + inline void message(Args... args); } // namespace snmalloc #ifdef SNMALLOC_CHECK_CLIENT diff --git a/src/mem/corealloc.h b/src/mem/corealloc.h index bd42b4e..ad6e81a 100644 --- a/src/mem/corealloc.h +++ b/src/mem/corealloc.h @@ -342,8 +342,10 @@ namespace snmalloc #endif #ifdef SNMALLOC_TRACING - std::cout << "Slab " << start_of_slab.unsafe_ptr() - << " is unused, Object sizeclass " << sizeclass << std::endl; + message<1024>( + "Slab {} is unused, Object sizeclass {}", + start_of_slab.unsafe_ptr(), + sizeclass); #else UNUSED(start_of_slab); #endif @@ -412,7 +414,7 @@ namespace snmalloc size_t size = bits::one_at_bit(entry_sizeclass); #ifdef SNMALLOC_TRACING - std::cout << "Large deallocation: " << size << std::endl; + message<1024>("Large deallocation: {}", size); #else UNUSED(size); #endif @@ -437,7 +439,7 @@ namespace snmalloc alloc_classes[sizeclass].length++; #ifdef SNMALLOC_TRACING - std::cout << "Slab is woken up" << std::endl; + message<1024>("Slab is woken up"); #endif ticker.check_tick(); @@ -483,7 +485,7 @@ namespace snmalloc auto cb = [this, &need_post](freelist::HeadPtr msg) SNMALLOC_FAST_PATH_LAMBDA { #ifdef SNMALLOC_TRACING - std::cout << "Handling remote" << std::endl; + message<1024>("Handling remote"); #endif auto& entry = @@ -562,7 +564,7 @@ namespace snmalloc void init() { #ifdef SNMALLOC_TRACING - std::cout << "Making an allocator." << std::endl; + message<1024>("Making an allocator."); #endif // Entropy must be first, so that all data-structures can use the key // it generates. @@ -776,8 +778,7 @@ namespace snmalloc size_t slab_size = sizeclass_to_slab_size(sizeclass); #ifdef SNMALLOC_TRACING - std::cout << "rsize " << rsize << std::endl; - std::cout << "slab size " << slab_size << std::endl; + message<1024>("small_alloc_slow rsize={} slab size={}", rsize, slab_size); #endif auto [slab, meta] = SharedStateHandle::alloc_chunk( @@ -872,7 +873,7 @@ namespace snmalloc void attach(LocalCache* c) { #ifdef SNMALLOC_TRACING - std::cout << "Attach cache to " << this << std::endl; + message<1024>("Attach cache to {}", this); #endif attached_cache = c; @@ -916,7 +917,7 @@ namespace snmalloc init_message_queue(); #ifdef SNMALLOC_TRACING - std::cout << "debug_is_empty - done" << std::endl; + message<1024>("debug_is_empty - done"); #endif return sent_something; } @@ -934,7 +935,7 @@ namespace snmalloc bool debug_is_empty(bool* result) { #ifdef SNMALLOC_TRACING - std::cout << "debug_is_empty" << std::endl; + message<1024>("debug_is_empty"); #endif if (attached_cache == nullptr) { @@ -943,7 +944,7 @@ namespace snmalloc LocalCache temp(public_state()); attach(&temp); #ifdef SNMALLOC_TRACING - std::cout << "debug_is_empty - attach a cache" << std::endl; + message<1024>("debug_is_empty - attach a cache"); #endif auto sent_something = debug_is_empty_impl(result); diff --git a/src/mem/globalalloc.h b/src/mem/globalalloc.h index f32413e..0152f6c 100644 --- a/src/mem/globalalloc.h +++ b/src/mem/globalalloc.h @@ -94,7 +94,7 @@ namespace snmalloc auto* alloc = AllocPool::iterate(); # ifdef SNMALLOC_TRACING - std::cout << "debug check empty: first " << alloc << std::endl; + message<1024>("debug check empty: first {}", alloc); # endif bool done = false; bool okay = true; @@ -102,7 +102,7 @@ namespace snmalloc while (!done) { # ifdef SNMALLOC_TRACING - std::cout << "debug_check_empty: Check all allocators!" << std::endl; + message<1024>("debug_check_empty: Check all allocators!"); # endif done = true; alloc = AllocPool::iterate(); @@ -111,7 +111,7 @@ namespace snmalloc while (alloc != nullptr) { # ifdef SNMALLOC_TRACING - std::cout << "debug check empty: " << alloc << std::endl; + message<1024>("debug check empty: {}", alloc); # endif // Check that the allocator has freed all memory. // repeat the loop if empty caused message sends. @@ -119,13 +119,12 @@ namespace snmalloc { done = false; # ifdef SNMALLOC_TRACING - std::cout << "debug check empty: sent messages " << alloc - << std::endl; + message<1024>("debug check empty: sent messages {}", alloc); # endif } # ifdef SNMALLOC_TRACING - std::cout << "debug check empty: okay = " << okay << std::endl; + message<1024>("debug check empty: okay = {}", okay); # endif alloc = AllocPool::iterate(alloc); } diff --git a/src/mem/localalloc.h b/src/mem/localalloc.h index db32d61..50a1cd2 100644 --- a/src/mem/localalloc.h +++ b/src/mem/localalloc.h @@ -151,7 +151,7 @@ namespace snmalloc if (post_teardown) { #ifdef SNMALLOC_TRACING - std::cout << "post_teardown flush()" << std::endl; + message<1024>("post_teardown flush()"); #endif // We didn't have an allocator because the thread is being torndown. // We need to return any local state, so we don't leak it. @@ -188,8 +188,7 @@ namespace snmalloc // set up meta data so sizeclass is correct, and hence alloc size, and // external pointer. #ifdef SNMALLOC_TRACING - std::cout << "size " << size << " pow2 size " - << bits::next_pow2_bits(size) << std::endl; + message<1024>("size {} pow2size {}", size, bits::next_pow2_bits(size)); #endif // Initialise meta data for a successful large allocation. @@ -263,8 +262,10 @@ namespace snmalloc if (core_alloc != nullptr) { #ifdef SNMALLOC_TRACING - std::cout << "Remote dealloc post" << p.unsafe_ptr() << " size " - << alloc_size(p.unsafe_ptr()) << std::endl; + message<1024>( + "Remote dealloc post {} ({})", + p.unsafe_ptr(), + alloc_size(p.unsafe_ptr())); #endif const MetaslabMetaEntry& entry = SharedStateHandle::Pagemap::template get_metaentry( @@ -364,8 +365,7 @@ namespace snmalloc c->attach(&local_cache); core_alloc = c; #ifdef SNMALLOC_TRACING - std::cout << "init(): core_alloc=" << core_alloc << "@" << &local_cache - << std::endl; + message<1024>("init(): core_alloc={} @ {}", core_alloc, &local_cache); #endif // local_cache.stats.sta rt(); } @@ -407,7 +407,7 @@ namespace snmalloc // it is new to hit slow paths. core_alloc = nullptr; #ifdef SNMALLOC_TRACING - std::cout << "flush(): core_alloc=" << core_alloc << std::endl; + message<1024>("flush(): core_alloc={}", core_alloc); #endif local_cache.remote_allocator = &SharedStateHandle::unused_remote; local_cache.remote_dealloc_cache.capacity = 0; @@ -651,8 +651,8 @@ namespace snmalloc local_cache.remote_dealloc_cache.template dealloc( entry.get_remote()->trunc_id(), p_tame, key_global); # ifdef SNMALLOC_TRACING - std::cout << "Remote dealloc fast" << p_raw << " size " - << alloc_size(p_raw) << std::endl; + message<1024>( + "Remote dealloc fast {} ({})", p_raw, alloc_size(p_raw)); # endif return; } @@ -667,7 +667,7 @@ namespace snmalloc snmalloc_check_client(p_tame == nullptr, "Not allocated by snmalloc."); # ifdef SNMALLOC_TRACING - std::cout << "nullptr deallocation" << std::endl; + message<1024>("nullptr deallocation"); # endif return; #endif @@ -689,8 +689,7 @@ namespace snmalloc void teardown() { #ifdef SNMALLOC_TRACING - std::cout << "Teardown: core_alloc=" << core_alloc << "@" << &local_cache - << std::endl; + message<1024>("Teardown: core_alloc={} @ {}", core_alloc, &local_cache); #endif post_teardown = true; if (core_alloc != nullptr) diff --git a/src/mem/threadalloc.h b/src/mem/threadalloc.h index 1ab5892..bbda32d 100644 --- a/src/mem/threadalloc.h +++ b/src/mem/threadalloc.h @@ -139,7 +139,7 @@ namespace snmalloc static char p_teardown_val = 1; pthread_setspecific(p_key.get(), &p_teardown_val); # ifdef SNMALLOC_TRACING - std::cout << "Using pthread clean up" << std::endl; + message<1024>("Using pthread clean up"); # endif } # elif defined(SNMALLOC_USE_CXX_THREAD_DESTRUCTORS) @@ -157,7 +157,7 @@ namespace snmalloc []() { ThreadAlloc::get().teardown(); }); UNUSED(dummy); # ifdef SNMALLOC_TRACING - std::cout << "Using C++ destructor clean up" << std::endl; + message<1024>("Using C++ destructor clean up"); # endif } # endif diff --git a/src/pal/pal_posix.h b/src/pal/pal_posix.h index 242125f..16c5ef7 100644 --- a/src/pal/pal_posix.h +++ b/src/pal/pal_posix.h @@ -336,8 +336,7 @@ namespace snmalloc if (p != MAP_FAILED) { #ifdef SNMALLOC_TRACING - std::cout << "Pal_posix reserved: " << p << " (" << size << ")" - << std::endl; + snmalloc::message<1024>("Pal_posix reserved: {} ({})", p, size); #endif return p; }