// 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. #ifndef THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PERFORMANCE_MANAGER_V8_WORKER_MEMORY_REPORTER_H_ #define THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PERFORMANCE_MANAGER_V8_WORKER_MEMORY_REPORTER_H_ #include "base/functional/callback.h" #include "base/gtest_prod_util.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" #include "third_party/blink/public/common/tokens/tokens.h" #include "third_party/blink/renderer/controller/controller_export.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h" #include "third_party/blink/renderer/platform/wtf/vector.h" #include "v8/include/v8.h" namespace base { class SingleThreadTaskRunner; } namespace blink { class WorkerThread; // This class measures memory usage of all workers in the renderer process. // Memory measurement is performed by posting a task on each worker thread // and then combining the results. Unresponsive workers (workers that never // go back to the message loop to run tasks) are skipped after a timeout. // The entry point is `GetMemoryUsage` that internally works as follows: // 1. Create an instance of V8WorkerMemoryReporter. // 2. Post a memory measurement task on each worker thread using // WorkerThread::CallOnAllWorkerThreads. Each task has a weak reference // to V8WorkerMemoryReporter. // 3. Post a timeout task on the main thread and transfer the ownership of // V8WorkerMemoryReporter to the task. // 4. Each worker task starts memory measurement using V8's MeasureMemory. // 5. Once a measurement succeeds (or fails) a task is posted on the main // thread that records the result. // 6. Once results from all workers are collected, the callback is invoked. // 7. If there is an unresponsive worker, then the timeout task will eventually // run and invoke the callback with partial results. class CONTROLLER_EXPORT V8WorkerMemoryReporter { … }; } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PERFORMANCE_MANAGER_V8_WORKER_MEMORY_REPORTER_H_