xref: /aosp_15_r20/external/cronet/base/allocator/partition_allocator/src/partition_alloc/starscan/logging.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PARTITION_ALLOC_STARSCAN_LOGGING_H_
6 #define PARTITION_ALLOC_STARSCAN_LOGGING_H_
7 
8 #include "partition_alloc/allocation_guard.h"
9 #include "partition_alloc/partition_alloc_base/logging.h"
10 
11 namespace partition_alloc::internal {
12 
13 // Logging requires allocations. This logger allows reentrant allocations to
14 // happen within the allocator context.
15 struct LoggerWithAllowedAllocations : ScopedAllowAllocations,
16                                       logging::LogMessage {
17   using logging::LogMessage::LogMessage;
18 };
19 
20 #define PA_PCSCAN_VLOG_STREAM(verbose_level)                 \
21   ::partition_alloc::internal::LoggerWithAllowedAllocations( \
22       __FILE__, __LINE__, -(verbose_level))                  \
23       .stream()
24 
25 // Logging macro that is meant to be used inside *Scan. Generally, reentrancy
26 // may be an issue if the macro is called from malloc()/free(). Currently, it's
27 // only called at the end of *Scan and when scheduling a new *Scan task.
28 // Allocating from these paths should not be an issue, since we make sure that
29 // no infinite recursion can occur (e.g. we can't schedule two *Scan tasks and
30 // the inner free() call must be non-reentrant).  However, these sorts of things
31 // are tricky to enforce and easy to mess up with. Since verbose *Scan logging
32 // is essential for debugging, we choose to provide support for it inside *Scan.
33 #define PA_PCSCAN_VLOG(verbose_level)                  \
34   PA_LAZY_STREAM(PA_PCSCAN_VLOG_STREAM(verbose_level), \
35                  PA_VLOG_IS_ON(verbose_level))
36 
37 }  // namespace partition_alloc::internal
38 
39 #endif  // PARTITION_ALLOC_STARSCAN_LOGGING_H_
40