Skip to content

Commit bdb3183

Browse files
committed
Remove std::cout
Now we have an allocation free formatting routine, remove std::cout from tracing.
1 parent bb82ac1 commit bdb3183

8 files changed

Lines changed: 43 additions & 39 deletions

File tree

src/backend/backend.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,15 @@ namespace snmalloc
277277
auto p = local_state.object_range->alloc_range(size);
278278

279279
#ifdef SNMALLOC_TRACING
280-
std::cout << "Alloc chunk: " << p.unsafe_ptr() << " (" << size << ")"
281-
<< std::endl;
280+
message<1024>("Alloc chunk: {} ({})", p.unsafe_ptr(), size);
282281
#endif
283282
if (p == nullptr)
284283
{
285284
local_state.get_meta_range()->dealloc_range(
286285
meta_cap, PAGEMAP_METADATA_STRUCT_SIZE);
287286
errno = ENOMEM;
288287
#ifdef SNMALLOC_TRACING
289-
std::cout << "Out of memory" << std::endl;
288+
message<1024>("Out of memory");
290289
#endif
291290
return {p, nullptr};
292291
}

src/backend/globalconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace snmalloc
6060
{
6161
FlagLock lock{initialisation_lock};
6262
#ifdef SNMALLOC_TRACING
63-
std::cout << "Run init_impl" << std::endl;
63+
message<1024>("Run init_impl");
6464
#endif
6565

6666
if (initialised)

src/ds/defines.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ namespace snmalloc
205205
*/
206206
template<size_t BufferSize = 1024, typename... Args>
207207
[[noreturn]] inline void report_fatal_error(Args... args);
208+
209+
/**
210+
* Forward declaration so that this can be called before the pal header is
211+
* included.
212+
*/
213+
template<size_t BufferSize = 1024, typename... Args>
214+
inline void message(Args... args);
208215
} // namespace snmalloc
209216

210217
#ifdef SNMALLOC_CHECK_CLIENT

src/mem/corealloc.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,10 @@ namespace snmalloc
342342
#endif
343343

344344
#ifdef SNMALLOC_TRACING
345-
std::cout << "Slab " << start_of_slab.unsafe_ptr()
346-
<< " is unused, Object sizeclass " << sizeclass << std::endl;
345+
message<1024>(
346+
"Slab {} is unused, Object sizeclass {}",
347+
start_of_slab.unsafe_ptr(),
348+
sizeclass);
347349
#else
348350
UNUSED(start_of_slab);
349351
#endif
@@ -412,7 +414,7 @@ namespace snmalloc
412414
size_t size = bits::one_at_bit(entry_sizeclass);
413415

414416
#ifdef SNMALLOC_TRACING
415-
std::cout << "Large deallocation: " << size << std::endl;
417+
message<1024>("Large deallocation: {}", size);
416418
#else
417419
UNUSED(size);
418420
#endif
@@ -437,7 +439,7 @@ namespace snmalloc
437439
alloc_classes[sizeclass].length++;
438440

439441
#ifdef SNMALLOC_TRACING
440-
std::cout << "Slab is woken up" << std::endl;
442+
message<1024>("Slab is woken up");
441443
#endif
442444

443445
ticker.check_tick();
@@ -483,7 +485,7 @@ namespace snmalloc
483485
auto cb = [this,
484486
&need_post](freelist::HeadPtr msg) SNMALLOC_FAST_PATH_LAMBDA {
485487
#ifdef SNMALLOC_TRACING
486-
std::cout << "Handling remote" << std::endl;
488+
message<1024>("Handling remote");
487489
#endif
488490

489491
auto& entry =
@@ -562,7 +564,7 @@ namespace snmalloc
562564
void init()
563565
{
564566
#ifdef SNMALLOC_TRACING
565-
std::cout << "Making an allocator." << std::endl;
567+
message<1024>("Making an allocator.");
566568
#endif
567569
// Entropy must be first, so that all data-structures can use the key
568570
// it generates.
@@ -776,8 +778,7 @@ namespace snmalloc
776778
size_t slab_size = sizeclass_to_slab_size(sizeclass);
777779

778780
#ifdef SNMALLOC_TRACING
779-
std::cout << "rsize " << rsize << std::endl;
780-
std::cout << "slab size " << slab_size << std::endl;
781+
message<1024>("small_alloc_slow rsize={} slab size={}", rsize, slab_size);
781782
#endif
782783

783784
auto [slab, meta] = SharedStateHandle::alloc_chunk(
@@ -872,7 +873,7 @@ namespace snmalloc
872873
void attach(LocalCache* c)
873874
{
874875
#ifdef SNMALLOC_TRACING
875-
std::cout << "Attach cache to " << this << std::endl;
876+
message<1024>("Attach cache to {}", this);
876877
#endif
877878
attached_cache = c;
878879

@@ -916,7 +917,7 @@ namespace snmalloc
916917
init_message_queue();
917918

918919
#ifdef SNMALLOC_TRACING
919-
std::cout << "debug_is_empty - done" << std::endl;
920+
message<1024>("debug_is_empty - done");
920921
#endif
921922
return sent_something;
922923
}
@@ -934,7 +935,7 @@ namespace snmalloc
934935
bool debug_is_empty(bool* result)
935936
{
936937
#ifdef SNMALLOC_TRACING
937-
std::cout << "debug_is_empty" << std::endl;
938+
message<1024>("debug_is_empty");
938939
#endif
939940
if (attached_cache == nullptr)
940941
{
@@ -943,7 +944,7 @@ namespace snmalloc
943944
LocalCache temp(public_state());
944945
attach(&temp);
945946
#ifdef SNMALLOC_TRACING
946-
std::cout << "debug_is_empty - attach a cache" << std::endl;
947+
message<1024>("debug_is_empty - attach a cache");
947948
#endif
948949
auto sent_something = debug_is_empty_impl(result);
949950

src/mem/globalalloc.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ namespace snmalloc
9494
auto* alloc = AllocPool<SharedStateHandle>::iterate();
9595

9696
# ifdef SNMALLOC_TRACING
97-
std::cout << "debug check empty: first " << alloc << std::endl;
97+
message<1024>("debug check empty: first {}", alloc);
9898
# endif
9999
bool done = false;
100100
bool okay = true;
101101

102102
while (!done)
103103
{
104104
# ifdef SNMALLOC_TRACING
105-
std::cout << "debug_check_empty: Check all allocators!" << std::endl;
105+
message<1024>("debug_check_empty: Check all allocators!");
106106
# endif
107107
done = true;
108108
alloc = AllocPool<SharedStateHandle>::iterate();
@@ -111,21 +111,20 @@ namespace snmalloc
111111
while (alloc != nullptr)
112112
{
113113
# ifdef SNMALLOC_TRACING
114-
std::cout << "debug check empty: " << alloc << std::endl;
114+
message<1024>("debug check empty: {}", alloc);
115115
# endif
116116
// Check that the allocator has freed all memory.
117117
// repeat the loop if empty caused message sends.
118118
if (alloc->debug_is_empty(&okay))
119119
{
120120
done = false;
121121
# ifdef SNMALLOC_TRACING
122-
std::cout << "debug check empty: sent messages " << alloc
123-
<< std::endl;
122+
message<1024>("debug check empty: sent messages {}", alloc);
124123
# endif
125124
}
126125

127126
# ifdef SNMALLOC_TRACING
128-
std::cout << "debug check empty: okay = " << okay << std::endl;
127+
message<1024>("debug check empty: okay = {}", okay);
129128
# endif
130129
alloc = AllocPool<SharedStateHandle>::iterate(alloc);
131130
}

src/mem/localalloc.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace snmalloc
151151
if (post_teardown)
152152
{
153153
#ifdef SNMALLOC_TRACING
154-
std::cout << "post_teardown flush()" << std::endl;
154+
message<1024>("post_teardown flush()");
155155
#endif
156156
// We didn't have an allocator because the thread is being torndown.
157157
// We need to return any local state, so we don't leak it.
@@ -188,8 +188,7 @@ namespace snmalloc
188188
// set up meta data so sizeclass is correct, and hence alloc size, and
189189
// external pointer.
190190
#ifdef SNMALLOC_TRACING
191-
std::cout << "size " << size << " pow2 size "
192-
<< bits::next_pow2_bits(size) << std::endl;
191+
message<1024>("size {} pow2size {}", size, bits::next_pow2_bits(size));
193192
#endif
194193

195194
// Initialise meta data for a successful large allocation.
@@ -263,8 +262,10 @@ namespace snmalloc
263262
if (core_alloc != nullptr)
264263
{
265264
#ifdef SNMALLOC_TRACING
266-
std::cout << "Remote dealloc post" << p.unsafe_ptr() << " size "
267-
<< alloc_size(p.unsafe_ptr()) << std::endl;
265+
message<1024>(
266+
"Remote dealloc post {} ({})",
267+
p.unsafe_ptr(),
268+
alloc_size(p.unsafe_ptr()));
268269
#endif
269270
const MetaslabMetaEntry& entry =
270271
SharedStateHandle::Pagemap::template get_metaentry<MetaslabMetaEntry>(
@@ -364,8 +365,7 @@ namespace snmalloc
364365
c->attach(&local_cache);
365366
core_alloc = c;
366367
#ifdef SNMALLOC_TRACING
367-
std::cout << "init(): core_alloc=" << core_alloc << "@" << &local_cache
368-
<< std::endl;
368+
message<1024>("init(): core_alloc={} @ {}", core_alloc, &local_cache);
369369
#endif
370370
// local_cache.stats.sta rt();
371371
}
@@ -407,7 +407,7 @@ namespace snmalloc
407407
// it is new to hit slow paths.
408408
core_alloc = nullptr;
409409
#ifdef SNMALLOC_TRACING
410-
std::cout << "flush(): core_alloc=" << core_alloc << std::endl;
410+
message<1024>("flush(): core_alloc={}", core_alloc);
411411
#endif
412412
local_cache.remote_allocator = &SharedStateHandle::unused_remote;
413413
local_cache.remote_dealloc_cache.capacity = 0;
@@ -651,8 +651,8 @@ namespace snmalloc
651651
local_cache.remote_dealloc_cache.template dealloc<sizeof(CoreAlloc)>(
652652
entry.get_remote()->trunc_id(), p_tame, key_global);
653653
# ifdef SNMALLOC_TRACING
654-
std::cout << "Remote dealloc fast" << p_raw << " size "
655-
<< alloc_size(p_raw) << std::endl;
654+
message<1024>(
655+
"Remote dealloc fast {} ({})", p_raw, alloc_size(p_raw));
656656
# endif
657657
return;
658658
}
@@ -667,7 +667,7 @@ namespace snmalloc
667667
snmalloc_check_client(p_tame == nullptr, "Not allocated by snmalloc.");
668668

669669
# ifdef SNMALLOC_TRACING
670-
std::cout << "nullptr deallocation" << std::endl;
670+
message<1024>("nullptr deallocation");
671671
# endif
672672
return;
673673
#endif
@@ -689,8 +689,7 @@ namespace snmalloc
689689
void teardown()
690690
{
691691
#ifdef SNMALLOC_TRACING
692-
std::cout << "Teardown: core_alloc=" << core_alloc << "@" << &local_cache
693-
<< std::endl;
692+
message<1024>("Teardown: core_alloc={} @ {}", core_alloc, &local_cache);
694693
#endif
695694
post_teardown = true;
696695
if (core_alloc != nullptr)

src/mem/threadalloc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ namespace snmalloc
139139
static char p_teardown_val = 1;
140140
pthread_setspecific(p_key.get(), &p_teardown_val);
141141
# ifdef SNMALLOC_TRACING
142-
std::cout << "Using pthread clean up" << std::endl;
142+
message<1024>("Using pthread clean up");
143143
# endif
144144
}
145145
# elif defined(SNMALLOC_USE_CXX_THREAD_DESTRUCTORS)
@@ -157,7 +157,7 @@ namespace snmalloc
157157
[]() { ThreadAlloc::get().teardown(); });
158158
UNUSED(dummy);
159159
# ifdef SNMALLOC_TRACING
160-
std::cout << "Using C++ destructor clean up" << std::endl;
160+
message<1024>("Using C++ destructor clean up");
161161
# endif
162162
}
163163
# endif

src/pal/pal_posix.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ namespace snmalloc
336336
if (p != MAP_FAILED)
337337
{
338338
#ifdef SNMALLOC_TRACING
339-
std::cout << "Pal_posix reserved: " << p << " (" << size << ")"
340-
<< std::endl;
339+
snmalloc::message<1024>("Pal_posix reserved: {} ({})", p, size);
341340
#endif
342341
return p;
343342
}

0 commit comments

Comments
 (0)