Skip to content

Commit

Permalink
[PA] Namespace migration (28 of N)
Browse files Browse the repository at this point in the history
This CL moves *Scan's `StatsReporter` class into the `partition_alloc`
namespace.

No alias within the `base` namespace is provided, since that appears to
conflict with the various forward declarations of `StatsReporter` used
throughout *Scan. Instead, this CL elects to rewrite all users of
`StatsReporter` to reflect its new place under `::partition_alloc`.

Bug: 1288247
Change-Id: I502b34bf8868d543c197da5d96583b5c64153288
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3559049
Reviewed-by: Bartek Nowierski <bartekn@chromium.org>
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Commit-Queue: Kalvin Lee <kdlee@chromium.org>
Cr-Commit-Position: refs/heads/main@{#988998}
  • Loading branch information
Kalvin Lee authored and Chromium LUCI CQ committed Apr 5, 2022
1 parent 9dc7257 commit e513158
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 45 deletions.
2 changes: 1 addition & 1 deletion base/allocator/partition_alloc_support.cc
Expand Up @@ -79,7 +79,7 @@ constexpr const char* MutatorIdToTracingString(
}

// Inject TRACE_EVENT_BEGIN/END, TRACE_COUNTER1, and UmaHistogramTimes.
class StatsReporterImpl final : public StatsReporter {
class StatsReporterImpl final : public partition_alloc::StatsReporter {
public:
void ReportTraceEvent(internal::StatsCollector::ScannerId id,
[[maybe_unused]] const PlatformThreadId tid,
Expand Down
2 changes: 1 addition & 1 deletion base/allocator/partition_allocator/starscan/pcscan.cc
Expand Up @@ -104,7 +104,7 @@ void PCScan::FinishScanForTesting() {
PCScanInternal::Instance().FinishScanForTesting(); // IN-TEST
}

void PCScan::RegisterStatsReporter(StatsReporter* reporter) {
void PCScan::RegisterStatsReporter(partition_alloc::StatsReporter* reporter) {
PCScanInternal::Instance().RegisterStatsReporter(reporter);
}

Expand Down
11 changes: 6 additions & 5 deletions base/allocator/partition_allocator/starscan/pcscan.h
Expand Up @@ -20,11 +20,13 @@
// We currently disable it to improve the runtime.
#define PA_STARSCAN_EAGER_DOUBLE_FREE_DETECTION_ENABLED 0

namespace base {
namespace partition_alloc {

class StatsReporter;

namespace internal {
} // namespace partition_alloc

namespace base::internal {

[[noreturn]] BASE_EXPORT NOINLINE NOT_TAIL_CALLED void DoubleFreeAttempt();

Expand Down Expand Up @@ -141,7 +143,7 @@ class BASE_EXPORT PCScan final {
inline static PCScanScheduler& scheduler();

// Registers reporting class.
static void RegisterStatsReporter(StatsReporter* reporter);
static void RegisterStatsReporter(partition_alloc::StatsReporter* reporter);

private:
class PCScanThread;
Expand Down Expand Up @@ -277,7 +279,6 @@ inline PCScanScheduler& PCScan::scheduler() {
return instance.scheduler_;
}

} // namespace internal
} // namespace base
} // namespace base::internal

#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_STARSCAN_PCSCAN_H_
Expand Up @@ -1306,7 +1306,7 @@ void PCScanInternal::Initialize(PCScan::InitConfig config) {
scannable_roots_ = RootsMap();
nonscannable_roots_ = RootsMap();

static StatsReporter s_no_op_reporter;
static partition_alloc::StatsReporter s_no_op_reporter;
PCScan::Instance().RegisterStatsReporter(&s_no_op_reporter);

// Don't initialize PCScanThread::Instance() as otherwise sandbox complains
Expand Down Expand Up @@ -1606,12 +1606,13 @@ void PCScanInternal::FinishScanForTesting() {
current_task->RunFromScanner();
}

void PCScanInternal::RegisterStatsReporter(StatsReporter* reporter) {
void PCScanInternal::RegisterStatsReporter(
partition_alloc::StatsReporter* reporter) {
PA_DCHECK(reporter);
stats_reporter_ = reporter;
}

StatsReporter& PCScanInternal::GetReporter() {
partition_alloc::StatsReporter& PCScanInternal::GetReporter() {
PA_DCHECK(stats_reporter_);
return *stats_reporter_;
}
Expand Down
16 changes: 5 additions & 11 deletions base/allocator/partition_allocator/starscan/pcscan_internal.h
Expand Up @@ -27,11 +27,7 @@ class StarScanSnapshot;

} // namespace partition_alloc::internal

namespace base {

class StatsReporter;

namespace internal {
namespace base::internal {

class PCScanTask;

Expand Down Expand Up @@ -114,8 +110,8 @@ class PCScanInternal final {
void ReinitForTesting(PCScan::InitConfig); // IN-TEST
void FinishScanForTesting(); // IN-TEST

void RegisterStatsReporter(StatsReporter* reporter);
StatsReporter& GetReporter();
void RegisterStatsReporter(partition_alloc::StatsReporter* reporter);
partition_alloc::StatsReporter& GetReporter();

private:
friend base::NoDestructor<PCScanInternal>;
Expand Down Expand Up @@ -149,14 +145,12 @@ class PCScanInternal final {
const SimdSupport simd_support_;

std::unique_ptr<WriteProtector> write_protector_;
StatsReporter* stats_reporter_ = nullptr;
partition_alloc::StatsReporter* stats_reporter_ = nullptr;

bool is_initialized_ = false;
};

} // namespace internal

} // namespace base
} // namespace base::internal

// TODO(crbug.com/1288247): Remove this when migration is complete.
namespace partition_alloc::internal {
Expand Down
12 changes: 7 additions & 5 deletions base/allocator/partition_allocator/starscan/stats_collector.cc
Expand Up @@ -25,7 +25,8 @@ base::TimeDelta StatsCollector::GetOverallTime() const {
ScannerId::kOverall);
}

void StatsCollector::ReportTracesAndHists(StatsReporter& reporter) const {
void StatsCollector::ReportTracesAndHists(
partition_alloc::StatsReporter& reporter) const {
ReportTracesAndHistsImpl<Context::kMutator>(reporter, mutator_trace_events_);
ReportTracesAndHistsImpl<Context::kScanner>(reporter, scanner_trace_events_);
ReportSurvivalRate(reporter);
Expand All @@ -46,7 +47,7 @@ base::TimeDelta StatsCollector::GetTimeImpl(

template <Context context>
void StatsCollector::ReportTracesAndHistsImpl(
StatsReporter& reporter,
partition_alloc::StatsReporter& reporter,
const DeferredTraceEventMap<context>& event_map) const {
std::array<base::TimeDelta, static_cast<size_t>(IdType<context>::kNumIds)>
accumulated_events{};
Expand Down Expand Up @@ -79,7 +80,8 @@ void StatsCollector::ReportTracesAndHistsImpl(
}
}

void StatsCollector::ReportSurvivalRate(StatsReporter& reporter) const {
void StatsCollector::ReportSurvivalRate(
partition_alloc::StatsReporter& reporter) const {
const double survived_rate =
static_cast<double>(survived_quarantine_size()) / quarantine_last_size_;
reporter.ReportSurvivedQuarantineSize(survived_quarantine_size());
Expand All @@ -101,10 +103,10 @@ template base::TimeDelta StatsCollector::GetTimeImpl(
IdType<Context::kScanner>) const;

template void StatsCollector::ReportTracesAndHistsImpl(
StatsReporter& reporter,
partition_alloc::StatsReporter& reporter,
const DeferredTraceEventMap<Context::kMutator>&) const;
template void StatsCollector::ReportTracesAndHistsImpl(
StatsReporter& reporter,
partition_alloc::StatsReporter& reporter,
const DeferredTraceEventMap<Context::kScanner>&) const;

} // namespace internal
Expand Down
15 changes: 7 additions & 8 deletions base/allocator/partition_allocator/starscan/stats_collector.h
Expand Up @@ -19,11 +19,11 @@
#include "base/threading/platform_thread.h"
#include "base/time/time.h"

namespace base {

namespace partition_alloc {
class StatsReporter;
} // namespace partition_alloc

namespace internal {
namespace base::internal {

#define FOR_ALL_PCSCAN_SCANNER_SCOPES(V) \
V(Clear) \
Expand Down Expand Up @@ -133,7 +133,7 @@ class StatsCollector final {
}

base::TimeDelta GetOverallTime() const;
void ReportTracesAndHists(StatsReporter& reporter) const;
void ReportTracesAndHists(partition_alloc::StatsReporter& reporter) const;

private:
using MetadataString =
Expand Down Expand Up @@ -161,10 +161,10 @@ class StatsCollector final {

template <Context context>
void ReportTracesAndHistsImpl(
StatsReporter& reporter,
partition_alloc::StatsReporter& reporter,
const DeferredTraceEventMap<context>& event_map) const;

void ReportSurvivalRate(StatsReporter& reporter) const;
void ReportSurvivalRate(partition_alloc::StatsReporter& reporter) const;

DeferredTraceEventMap<Context::kMutator> mutator_trace_events_;
DeferredTraceEventMap<Context::kScanner> scanner_trace_events_;
Expand Down Expand Up @@ -241,7 +241,6 @@ inline StatsCollector::MetadataString StatsCollector::ToUMAString(
#undef FOR_ALL_PCSCAN_MUTATOR_SCOPES
#undef FOR_ALL_PCSCAN_SCANNER_SCOPES

} // namespace internal
} // namespace base
} // namespace base::internal

#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_STARSCAN_STATS_COLLECTOR_H_
22 changes: 11 additions & 11 deletions base/allocator/partition_allocator/starscan/stats_reporter.h
Expand Up @@ -9,29 +9,29 @@
#include "base/threading/platform_thread.h"
#include "base/time/time.h"

namespace base {
namespace partition_alloc {

// StatsReporter is a wrapper to invoke TRACE_EVENT_BEGIN/END, TRACE_COUNTER1,
// and UmaHistogramTimes. It is used to just remove trace_log and uma
// dependencies from partition allocator.
class StatsReporter {
public:
virtual void ReportTraceEvent(internal::StatsCollector::ScannerId id,
const PlatformThreadId tid,
TimeTicks start_time,
TimeTicks end_time) {}
virtual void ReportTraceEvent(internal::StatsCollector::MutatorId id,
const PlatformThreadId tid,
TimeTicks start_time,
TimeTicks end_time) {}
virtual void ReportTraceEvent(base::internal::StatsCollector::ScannerId id,
const base::PlatformThreadId tid,
base::TimeTicks start_time,
base::TimeTicks end_time) {}
virtual void ReportTraceEvent(base::internal::StatsCollector::MutatorId id,
const base::PlatformThreadId tid,
base::TimeTicks start_time,
base::TimeTicks end_time) {}

virtual void ReportSurvivedQuarantineSize(size_t survived_size) {}

virtual void ReportSurvivedQuarantinePercent(double survivied_rate) {}

virtual void ReportStats(const char* stats_name, TimeDelta sample) {}
virtual void ReportStats(const char* stats_name, base::TimeDelta sample) {}
};

} // namespace base
} // namespace partition_alloc

#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_STARSCAN_STATS_REPORTER_H_

0 comments on commit e513158

Please sign in to comment.