Skip to content

Commit 1a6f5b8

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

File tree

8 files changed

+43
-39
lines changed

8 files changed

+43
-39
lines changed

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
@@ -413,7 +415,7 @@ namespace snmalloc
413415
size_t size = bits::one_at_bit(entry_sizeclass);
414416

415417
#ifdef SNMALLOC_TRACING
416-
std::cout << "Large deallocation: " << size << std::endl;
418+
message<1024>("Large deallocation: {}", size);
417419
#else
418420
UNUSED(size);
419421
#endif
@@ -438,7 +440,7 @@ namespace snmalloc
438440
alloc_classes[sizeclass].length++;
439441

440442
#ifdef SNMALLOC_TRACING
441-
std::cout << "Slab is woken up" << std::endl;
443+
message<1024>("Slab is woken up");
442444
#endif
443445

444446
ticker.check_tick();
@@ -484,7 +486,7 @@ namespace snmalloc
484486
auto cb = [this,
485487
&need_post](freelist::HeadPtr msg) SNMALLOC_FAST_PATH_LAMBDA {
486488
#ifdef SNMALLOC_TRACING
487-
std::cout << "Handling remote" << std::endl;
489+
message<1024>("Handling remote");
488490
#endif
489491

490492
auto& entry =
@@ -563,7 +565,7 @@ namespace snmalloc
563565
void init()
564566
{
565567
#ifdef SNMALLOC_TRACING
566-
std::cout << "Making an allocator." << std::endl;
568+
message<1024>("Making an allocator.");
567569
#endif
568570
// Entropy must be first, so that all data-structures can use the key
569571
// it generates.
@@ -777,8 +779,7 @@ namespace snmalloc
777779
size_t slab_size = sizeclass_to_slab_size(sizeclass);
778780

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

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

@@ -917,7 +918,7 @@ namespace snmalloc
917918
init_message_queue();
918919

919920
#ifdef SNMALLOC_TRACING
920-
std::cout << "debug_is_empty - done" << std::endl;
921+
message<1024>("debug_is_empty - done");
921922
#endif
922923
return sent_something;
923924
}
@@ -935,7 +936,7 @@ namespace snmalloc
935936
bool debug_is_empty(bool* result)
936937
{
937938
#ifdef SNMALLOC_TRACING
938-
std::cout << "debug_is_empty" << std::endl;
939+
message<1024>("debug_is_empty");
939940
#endif
940941
if (attached_cache == nullptr)
941942
{
@@ -944,7 +945,7 @@ namespace snmalloc
944945
LocalCache temp(public_state());
945946
attach(&temp);
946947
#ifdef SNMALLOC_TRACING
947-
std::cout << "debug_is_empty - attach a cache" << std::endl;
948+
message<1024>("debug_is_empty - attach a cache");
948949
#endif
949950
auto sent_something = debug_is_empty_impl(result);
950951

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)