#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 {
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 = …;
}
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) { … }
}
ScriptPromise<MemoryMeasurement> MeasureMemoryController::StartMeasurement(
ScriptState* script_state,
ExceptionState& exception_state) { … }
namespace {
struct RandomBitGenerator { … };
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) { … }
}
void MeasureMemoryController::MeasurementComplete(
WebMemoryMeasurementPtr measurement) { … }
}