chromium/components/performance_manager/v8_memory/v8_detailed_memory_decorator.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/performance_manager/v8_memory/v8_detailed_memory_decorator.h"

#include <utility>
#include <vector>

#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/function_ref.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "components/performance_manager/public/execution_context/execution_context.h"
#include "components/performance_manager/public/execution_context/execution_context_attached_data.h"
#include "components/performance_manager/public/graph/frame_node.h"
#include "components/performance_manager/public/graph/graph.h"
#include "components/performance_manager/public/graph/node_attached_data.h"
#include "components/performance_manager/public/graph/node_data_describer_registry.h"
#include "components/performance_manager/public/graph/worker_node.h"
#include "components/performance_manager/public/render_process_host_proxy.h"
#include "components/performance_manager/public/v8_memory/v8_detailed_memory.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/process_type.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/common/tokens/tokens.h"

ExecutionContextToken;
PerContextCanvasMemoryUsagePtr;
PerContextV8MemoryUsagePtr;

namespace performance_manager {

namespace v8_memory {

class V8DetailedMemoryRequestQueue {};

// This class is allowed to access
// V8DetailedMemoryDecorator::NotifyObserversOnMeasurementAvailable.
class V8DetailedMemoryDecorator::ObserverNotifier {};

namespace {

MeasurementMode;

// Forwards the pending receiver to the RenderProcessHost and binds it on the
// UI thread.
void BindReceiverOnUIThread(
    mojo::PendingReceiver<blink::mojom::V8DetailedMemoryReporter>
        pending_receiver,
    RenderProcessHostProxy proxy) {}

bool IsMeasurementBounded(MeasurementMode mode) {}

// Returns the higher priority request of |a| and |b|, either of which can be
// null, or nullptr if both are null.
const V8DetailedMemoryRequest* ChooseHigherPriorityRequest(
    const V8DetailedMemoryRequest* a,
    const V8DetailedMemoryRequest* b) {}

// May only be used from the performance manager sequence.
internal::BindV8DetailedMemoryReporterCallback* g_test_bind_callback =;

// Per-frame memory measurement involves the following classes that live on the
// PM sequence:
//
// V8DetailedMemoryDecorator: Central rendezvous point. Coordinates
//     V8DetailedMemoryRequest and V8DetailedMemoryObserver objects. Owned by
//     the graph; created the first time
//     V8DetailedMemoryRequest::StartMeasurement is called.
//     TODO(b/1080672): Currently this lives forever; should be cleaned up when
//     there are no more measurements scheduled.
//
// V8DetailedMemoryRequest: Indicates that a caller wants memory to be measured
//     at a specific interval. Owned by the caller but must live on the PM
//     sequence. V8DetailedMemoryRequest objects register themselves with
//     V8DetailedMemoryDecorator on creation and unregister themselves on
//     deletion, which cancels the corresponding measurement.
//
// V8DetailedMemoryRequestQueue: A priority queue of memory requests. The
//     decorator will hold a global queue of requests that measure every
//     process, and each ProcessNode will have a queue of requests that measure
//     only that process.
//
// NodeAttachedProcessData: Private class that schedules measurements and holds
//     the results for an individual process. Owned by the ProcessNode; created
//     when measurements start.
//     TODO(b/1080672): Currently this lives forever; should be cleaned up when
//     there are no more measurements scheduled.
//
// V8DetailedMemoryProcessData: Public accessor to the measurement results held
//     in a NodeAttachedProcessData, which owns it.
//
// ExecutionContextAttachedData: Private class that holds the measurement
//     results for an execution context. Owned by the ExecutionContext; created
//     when a measurement result arrives.
//     TODO(b/1080672): Currently this lives forever; should be cleaned up when
//     there are no more measurements scheduled.
//
// V8DetailedMemoryExecutionContextData: Public accessor to the measurement
//     results held in a ExecutionContextAttachedData, which owns it.
//
// V8DetailedMemoryObserver: Callers can implement this and register with
//     V8DetailedMemoryDecorator::AddObserver() to be notified when
//     measurements are available for a process. Owned by the caller but must
//     live on the PM sequence.
//
// Additional wrapper classes can access these classes from other sequences:
//
// V8DetailedMemoryRequestAnySeq: Wraps V8DetailedMemoryRequest. Owned by the
//     caller and lives on any sequence.
//
// V8DetailedMemoryObserverAnySeq: Callers can implement this and register it
//     with V8DetailedMemoryRequestAnySeq::AddObserver() to be notified when
//     measurements are available for a process. Owned by the caller and lives
//     on the same sequence as the V8DetailedMemoryRequestAnySeq.

////////////////////////////////////////////////////////////////////////////////
// ExecutionContextAttachedData

class ExecutionContextAttachedData
    : public execution_context::ExecutionContextAttachedData<
          ExecutionContextAttachedData> {};

// static
V8DetailedMemoryExecutionContextData*
ExecutionContextAttachedData::GetOrCreateForTesting(
    const execution_context::ExecutionContext* ec) {}

////////////////////////////////////////////////////////////////////////////////
// NodeAttachedProcessData

class NodeAttachedProcessData
    : public ExternalNodeAttachedDataImpl<NodeAttachedProcessData> {};

NodeAttachedProcessData::NodeAttachedProcessData(
    const ProcessNode* process_node)
    :{}

// static
void NodeAttachedProcessData::ApplyToAllRenderers(
    Graph* graph,
    base::FunctionRef<void(NodeAttachedProcessData*)> func) {}

void NodeAttachedProcessData::ScheduleNextMeasurement() {}

void NodeAttachedProcessData::StartMeasurement(MeasurementMode mode) {}

void NodeAttachedProcessData::ScheduleUpgradeToBoundedMeasurement() {}

void NodeAttachedProcessData::UpgradeToBoundedMeasurementIfNeeded(
    MeasurementMode bounded_mode) {}

void NodeAttachedProcessData::OnV8MemoryUsage(
    blink::mojom::PerProcessV8MemoryUsagePtr result) {}

void NodeAttachedProcessData::EnsureRemote() {}

// static
V8DetailedMemoryProcessData* NodeAttachedProcessData::GetOrCreateForTesting(
    const ProcessNode* process_node) {}

}  // namespace

namespace internal {

void SetBindV8DetailedMemoryReporterCallbackForTesting(  // IN-TEST
    BindV8DetailedMemoryReporterCallback* callback) {}

void DestroyV8DetailedMemoryDecoratorForTesting(Graph* graph) {}

}  // namespace internal

////////////////////////////////////////////////////////////////////////////////
// V8DetailedMemoryDecorator

V8DetailedMemoryDecorator::V8DetailedMemoryDecorator()
    :{}

V8DetailedMemoryDecorator::~V8DetailedMemoryDecorator() = default;

void V8DetailedMemoryDecorator::OnPassedToGraph(Graph* graph) {}

void V8DetailedMemoryDecorator::OnTakenFromGraph(Graph* graph) {}

void V8DetailedMemoryDecorator::OnProcessNodeAdded(
    const ProcessNode* process_node) {}

void V8DetailedMemoryDecorator::OnBeforeProcessNodeRemoved(
    const ProcessNode* process_node) {}

base::Value::Dict V8DetailedMemoryDecorator::DescribeFrameNodeData(
    const FrameNode* frame_node) const {}

base::Value::Dict V8DetailedMemoryDecorator::DescribeProcessNodeData(
    const ProcessNode* process_node) const {}

const V8DetailedMemoryRequest* V8DetailedMemoryDecorator::GetNextRequest()
    const {}

const V8DetailedMemoryRequest*
V8DetailedMemoryDecorator::GetNextBoundedRequest() const {}

void V8DetailedMemoryDecorator::AddMeasurementRequest(
    base::PassKey<V8DetailedMemoryRequest> key,
    V8DetailedMemoryRequest* request,
    const ProcessNode* process_node) {}

void V8DetailedMemoryDecorator::RemoveMeasurementRequest(
    base::PassKey<V8DetailedMemoryRequest> key,
    V8DetailedMemoryRequest* request) {}

void V8DetailedMemoryDecorator::ApplyToAllRequestQueues(
    base::FunctionRef<void(V8DetailedMemoryRequestQueue*)> func) const {}

void V8DetailedMemoryDecorator::UpdateProcessMeasurementSchedules() const {}

void V8DetailedMemoryDecorator::NotifyObserversOnMeasurementAvailable(
    base::PassKey<ObserverNotifier> key,
    const ProcessNode* process_node) const {}

// static
const V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::GetExecutionContextData(const FrameNode* node) {}

// static
const V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::GetExecutionContextData(const WorkerNode* node) {}

// static
const V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::GetExecutionContextData(
    const execution_context::ExecutionContext* ec) {}

// static
V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::CreateExecutionContextDataForTesting(
    const FrameNode* node) {}

// static
V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::CreateExecutionContextDataForTesting(
    const WorkerNode* node) {}

// static
const V8DetailedMemoryProcessData* V8DetailedMemoryDecorator::GetProcessData(
    const ProcessNode* node) {}

// static
V8DetailedMemoryProcessData*
V8DetailedMemoryDecorator::CreateProcessDataForTesting(
    const ProcessNode* node) {}

////////////////////////////////////////////////////////////////////////////////
// V8DetailedMemoryRequestQueue

V8DetailedMemoryRequestQueue::~V8DetailedMemoryRequestQueue() {}

const V8DetailedMemoryRequest* V8DetailedMemoryRequestQueue::GetNextRequest()
    const {}

const V8DetailedMemoryRequest*
V8DetailedMemoryRequestQueue::GetNextBoundedRequest() const {}

void V8DetailedMemoryRequestQueue::AddMeasurementRequest(
    V8DetailedMemoryRequest* request) {}

size_t V8DetailedMemoryRequestQueue::RemoveMeasurementRequest(
    V8DetailedMemoryRequest* request) {}

void V8DetailedMemoryRequestQueue::NotifyObserversOnMeasurementAvailable(
    const ProcessNode* process_node) const {}

void V8DetailedMemoryRequestQueue::OnOwnerUnregistered() {}

void V8DetailedMemoryRequestQueue::Validate() {}

void V8DetailedMemoryRequestQueue::ApplyToAllRequests(
    base::FunctionRef<void(V8DetailedMemoryRequest*)> func) const {}

}  // namespace v8_memory

}  // namespace performance_manager