chromium/third_party/blink/renderer/core/timing/measure_memory/measure_memory_controller.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 "third_party/blink/renderer/core/timing/measure_memory/measure_memory_controller.h"

#include <algorithm>
#include "base/rand_util.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom-blink.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/to_v8_traits.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_memory_attribution.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_memory_attribution_container.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_memory_breakdown_entry.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_memory_measurement.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/timing/measure_memory/local_web_memory_measurer.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/document_resource_coordinator.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "v8/include/v8.h"

WebMemoryAttribution;
WebMemoryAttributionPtr;
WebMemoryBreakdownEntryPtr;
WebMemoryMeasurement;
WebMemoryMeasurementPtr;
WebMemoryUsagePtr;

namespace blink {

namespace {

// String constants used for building the result.
constexpr const char* kCrossOriginUrl =;
constexpr const char* kMemoryTypeCanvas =;
constexpr const char* kMemoryTypeDom =;
constexpr const char* kMemoryTypeJavaScript =;
constexpr const char* kMemoryTypeShared =;
constexpr const char* kScopeCrossOriginAggregated =;
constexpr const char* kScopeDedicatedWorker =;
constexpr const char* kScopeServiceWorker =;
constexpr const char* kScopeSharedWorker =;
constexpr const char* kScopeWindow =;

}  // anonymous namespace

MeasureMemoryController::MeasureMemoryController(
    base::PassKey<MeasureMemoryController>,
    v8::Isolate* isolate,
    v8::Local<v8::Context> context,
    ScriptPromiseResolver<MemoryMeasurement>* resolver)
    :{}

void MeasureMemoryController::Trace(Visitor* visitor) const {}

namespace {

enum class ApiStatus {};

ApiStatus CheckMeasureMemoryAvailability() {}

bool IsAttached(ExecutionContext* execution_context) {}

void StartMemoryMeasurement(LocalDOMWindow* window,
                            MeasureMemoryController* controller,
                            WebMemoryMeasurement::Mode mode) {}

void StartMemoryMeasurement(WorkerGlobalScope* worker,
                            MeasureMemoryController* controller,
                            WebMemoryMeasurement::Mode mode) {}

}  // anonymous namespace

ScriptPromise<MemoryMeasurement> MeasureMemoryController::StartMeasurement(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

namespace {

// Satisfies the requirements of UniformRandomBitGenerator from C++ standard.
// It is used in std::shuffle calls below.
struct RandomBitGenerator {};

// These functions convert WebMemory* mojo structs to IDL and JS values.
String ConvertScope(WebMemoryAttribution::Scope scope) {}

MemoryAttributionContainer* ConvertContainer(
    const WebMemoryAttributionPtr& attribution) {}

MemoryAttribution* ConvertAttribution(
    const WebMemoryAttributionPtr& attribution) {}

MemoryBreakdownEntry* ConvertJavaScriptBreakdown(
    const WebMemoryBreakdownEntryPtr& breakdown_entry) {}

MemoryBreakdownEntry* ConvertCanvasBreakdown(
    const WebMemoryBreakdownEntryPtr& breakdown_entry) {}

MemoryBreakdownEntry* CreateUnattributedBreakdown(
    const WebMemoryUsagePtr& memory,
    const WTF::String& memory_type) {}

MemoryBreakdownEntry* EmptyBreakdown() {}

MemoryMeasurement* ConvertResult(const WebMemoryMeasurementPtr& measurement) {}

bool IsDedicatedWorkerEntry(const WebMemoryBreakdownEntryPtr& breakdown_entry) {}

uint64_t GetDedicatedWorkerJavaScriptUkm(
    const WebMemoryMeasurementPtr& measurement) {}

uint64_t GetJavaScriptUkm(const WebMemoryMeasurementPtr& measurement) {}

uint64_t GetDomUkm(const WebMemoryMeasurementPtr& measurement) {}

uint64_t GetSharedUkm(const WebMemoryMeasurementPtr& measurement) {}

void RecordWebMemoryUkm(ExecutionContext* execution_context,
                        const WebMemoryMeasurementPtr& measurement) {}

}  // anonymous namespace

void MeasureMemoryController::MeasurementComplete(
    WebMemoryMeasurementPtr measurement) {}

}  // namespace blink