chromium/components/performance_manager/v8_memory/web_memory_aggregator.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/web_memory_aggregator.h"

#include <utility>
#include <vector>

#include "base/check.h"
#include "base/containers/stack.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "components/performance_manager/public/graph/frame_node.h"
#include "components/performance_manager/public/graph/page_node.h"
#include "components/performance_manager/public/graph/worker_node.h"
#include "components/performance_manager/public/v8_memory/v8_detailed_memory.h"
#include "components/performance_manager/v8_memory/v8_context_tracker.h"
#include "url/gurl.h"

namespace performance_manager {

namespace v8_memory {

// A visitor that visits every node that can be aggregated into an aggregation
// point.
//
// TODO(joenotcharles): If we ever need to aggregate different data for each
// aggregation point, turn this into an interface and add a subclass for each
// type of data to aggregate.
class AggregationPointVisitor {};

namespace {

AttributionScope;

// The various ways a node can be treated during the aggregation.
enum class NodeAggregationType {};

NodeAggregationType GetNodeAggregationType(const url::Origin& requesting_origin,
                                           const url::Origin& enclosing_origin,
                                           const url::Origin& node_origin) {}

// Returns a mutable pointer to the WebMemoryAttribution structure in the given
// |breakdown|.
mojom::WebMemoryAttribution* GetAttributionFromBreakdown(
    mojom::WebMemoryBreakdownEntry* breakdown) {}

// Returns a const pointer to the WebMemoryAttribution structure in the given
// |breakdown|.
const mojom::WebMemoryAttribution* GetAttributionFromBreakdown(
    const mojom::WebMemoryBreakdownEntry* breakdown) {}

AttributionScope AttributionScopeFromWorkerType(
    WorkerNode::WorkerType worker_type) {}

void AddMemoryBytes(mojom::WebMemoryBreakdownEntry* aggregation_point,
                    const V8DetailedMemoryExecutionContextData* data,
                    bool is_same_process) {}

const FrameNode* GetTopFrame(const FrameNode* frame) {}

// Returns the process node of the main frame that is in the same browsing
// context group as the given frame.
const ProcessNode* GetMainProcess(const FrameNode* frame) {}

}  // anonymous namespace

////////////////////////////////////////////////////////////////////////////////
// AggregationPointVisitor

AggregationPointVisitor::AggregationPointVisitor(
    const url::Origin& requesting_origin,
    const ProcessNode* requesting_process_node,
    const url::Origin& main_origin)
    :{}

AggregationPointVisitor::~AggregationPointVisitor() {}

mojom::WebMemoryMeasurementPtr
AggregationPointVisitor::TakeAggregationResult() {}

void AggregationPointVisitor::OnRootEntered() {}

void AggregationPointVisitor::OnRootExited() {}

void AggregationPointVisitor::OnFrameEntered(const FrameNode* frame_node) {}

void AggregationPointVisitor::OnFrameExited(const FrameNode* frame_node) {}

void AggregationPointVisitor::OnWorkerEntered(const WorkerNode* worker_node) {}

void AggregationPointVisitor::OnWorkerExited(const WorkerNode* worker_node) {}

////////////////////////////////////////////////////////////////////////////////
// WebMemoryAggregator

WebMemoryAggregator::WebMemoryAggregator(const FrameNode* requesting_node)
    :{}

WebMemoryAggregator::~WebMemoryAggregator() = default;

namespace {

// Returns v8_browsing_memory / v8_process_memory where
// - v8_browsing_memory is the total V8 memory usage of all frames of the given
//   |browsing_instance_id| in the given |process_node|.
// - v8_process_memory is the total V8 memory usage of all frames in the given
//   |process_node|.
double GetBrowsingInstanceV8BytesFraction(
    const ProcessNode* process_node,
    content::BrowsingInstanceId browsing_instance_id) {}

}  // anonymous namespace

mojom::WebMemoryMeasurementPtr
WebMemoryAggregator::AggregateMeasureMemoryResult() {}

void WebMemoryAggregator::VisitFrame(AggregationPointVisitor* ap_visitor,
                                     const FrameNode* frame_node) {}

void WebMemoryAggregator::VisitWorker(AggregationPointVisitor* ap_visitor,
                                      const WorkerNode* worker_node) {}

// static
mojom::WebMemoryBreakdownEntry* WebMemoryAggregator::CreateBreakdownEntry(
    AttributionScope scope,
    std::optional<std::string> url,
    mojom::WebMemoryMeasurement* measurement) {}

// static
void WebMemoryAggregator::SetBreakdownAttributionFromFrame(
    const FrameNode* frame_node,
    mojom::WebMemoryBreakdownEntry* breakdown) {}

// static
void WebMemoryAggregator::CopyBreakdownAttribution(
    const mojom::WebMemoryBreakdownEntry* from,
    mojom::WebMemoryBreakdownEntry* to) {}

}  // namespace v8_memory

}  // namespace performance_manager