chromium/third_party/blink/renderer/controller/performance_manager/v8_worker_memory_reporter.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/controller/performance_manager/v8_worker_memory_reporter.h"

#include <memory>
#include <utility>

#include "base/check.h"
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "third_party/blink/renderer/core/timing/measure_memory/measure_memory_controller.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_or_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/scheduler/public/main_thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace WTF {
template <>
struct CrossThreadCopier<blink::V8WorkerMemoryReporter::WorkerMemoryUsage>
    : public CrossThreadCopierPassThrough<
          blink::V8WorkerMemoryReporter::WorkerMemoryUsage> {};
}  // namespace WTF

namespace blink {

const base::TimeDelta V8WorkerMemoryReporter::kTimeout =;

namespace {

// TODO(906991): Remove this once PlzDedicatedWorker ships. Until then
// the browser does not know URLs of dedicated workers, so we pass them
// together with the measurement result. We limit the max length of the
// URLs to reduce memory allocations and the traffic between the renderer
// and the browser processes.
constexpr size_t kMaxReportedUrlLength =;

// This delegate is provided to v8::Isolate::MeasureMemory API.
// V8 calls MeasurementComplete with the measurement result.
//
// All functions of this delegate are called on the worker thread.
class WorkerMeasurementDelegate : public v8::MeasureMemoryDelegate {};

WorkerMeasurementDelegate::~WorkerMeasurementDelegate() {}

void WorkerMeasurementDelegate::MeasurementComplete(
    v8::MeasureMemoryDelegate::Result result) {}

void WorkerMeasurementDelegate::NotifyMeasurementFailure() {}

void WorkerMeasurementDelegate::NotifyMeasurementSuccess(
    std::unique_ptr<V8WorkerMemoryReporter::WorkerMemoryUsage> memory_usage) {}

}  // anonymous namespace

// static
void V8WorkerMemoryReporter::GetMemoryUsage(ResultCallback callback,
                                            v8::MeasureMemoryExecution mode) {}

// static
void V8WorkerMemoryReporter::StartMeasurement(
    WorkerThread* worker_thread,
    scoped_refptr<base::SingleThreadTaskRunner> task_runner,
    base::WeakPtr<V8WorkerMemoryReporter> worker_memory_reporter,
    v8::MeasureMemoryExecution measurement_mode) {}

// static
void V8WorkerMemoryReporter::NotifyMeasurementSuccess(
    WorkerThread* worker_thread,
    scoped_refptr<base::SingleThreadTaskRunner> task_runner,
    base::WeakPtr<V8WorkerMemoryReporter> worker_memory_reporter,
    std::unique_ptr<WorkerMemoryUsage> memory_usage) {}

// static
void V8WorkerMemoryReporter::NotifyMeasurementFailure(
    WorkerThread* worker_thread,
    scoped_refptr<base::SingleThreadTaskRunner> task_runner,
    base::WeakPtr<V8WorkerMemoryReporter> worker_memory_reporter) {}

void V8WorkerMemoryReporter::OnMeasurementFailure() {}

void V8WorkerMemoryReporter::OnMeasurementSuccess(
    std::unique_ptr<WorkerMemoryUsage> memory_usage) {}

void V8WorkerMemoryReporter::SetWorkerCount(unsigned worker_count) {}

void V8WorkerMemoryReporter::OnTimeout() {}

void V8WorkerMemoryReporter::InvokeCallback() {}

}  // namespace blink