#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 { … };
class V8DetailedMemoryDecorator::ObserverNotifier { … };
namespace {
MeasurementMode;
void BindReceiverOnUIThread(
mojo::PendingReceiver<blink::mojom::V8DetailedMemoryReporter>
pending_receiver,
RenderProcessHostProxy proxy) { … }
bool IsMeasurementBounded(MeasurementMode mode) { … }
const V8DetailedMemoryRequest* ChooseHigherPriorityRequest(
const V8DetailedMemoryRequest* a,
const V8DetailedMemoryRequest* b) { … }
internal::BindV8DetailedMemoryReporterCallback* g_test_bind_callback = …;
class ExecutionContextAttachedData
: public execution_context::ExecutionContextAttachedData<
ExecutionContextAttachedData> { … };
V8DetailedMemoryExecutionContextData*
ExecutionContextAttachedData::GetOrCreateForTesting(
const execution_context::ExecutionContext* ec) { … }
class NodeAttachedProcessData
: public ExternalNodeAttachedDataImpl<NodeAttachedProcessData> { … };
NodeAttachedProcessData::NodeAttachedProcessData(
const ProcessNode* process_node)
: … { … }
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() { … }
V8DetailedMemoryProcessData* NodeAttachedProcessData::GetOrCreateForTesting(
const ProcessNode* process_node) { … }
}
namespace internal {
void SetBindV8DetailedMemoryReporterCallbackForTesting(
BindV8DetailedMemoryReporterCallback* callback) { … }
void DestroyV8DetailedMemoryDecoratorForTesting(Graph* graph) { … }
}
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 { … }
const V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::GetExecutionContextData(const FrameNode* node) { … }
const V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::GetExecutionContextData(const WorkerNode* node) { … }
const V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::GetExecutionContextData(
const execution_context::ExecutionContext* ec) { … }
V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::CreateExecutionContextDataForTesting(
const FrameNode* node) { … }
V8DetailedMemoryExecutionContextData*
V8DetailedMemoryDecorator::CreateExecutionContextDataForTesting(
const WorkerNode* node) { … }
const V8DetailedMemoryProcessData* V8DetailedMemoryDecorator::GetProcessData(
const ProcessNode* node) { … }
V8DetailedMemoryProcessData*
V8DetailedMemoryDecorator::CreateProcessDataForTesting(
const ProcessNode* node) { … }
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 { … }
}
}