0

Inline |CallOnUI| function calls in PeakGpuMemoryTrackerImpl.

Cleans up GpuProcessHost::CallOnUI by inlining these calls since these
are done on the UI thread. Since
https://chromium-review.googlesource.com/c/chromium/src/+/3178241,
|CallOnUI| only calls functions on the UI thread.

Bug: b:343965215
Change-Id: I8799dafc03bed669afa6e533c36a3f25d49aba3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5588670
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Aman Verma <amanvr@google.com>
Cr-Commit-Position: refs/heads/main@{#1313398}
This commit is contained in:
Aman Verma
2024-06-11 14:32:40 +00:00
committed by Chromium LUCI CQ
parent e574c54125
commit 1a2afd7511
4 changed files with 40 additions and 56 deletions

@ -26,71 +26,55 @@ uint32_t PeakGpuMemoryTrackerImpl::next_sequence_number_ = 0;
PeakGpuMemoryTrackerImpl::PeakGpuMemoryTrackerImpl(
PeakGpuMemoryTracker::Usage usage)
: usage_(usage) {
// TODO(thiabaud): Do this call inline, since this happens on the UI thread.
//
// Actually performs request to GPU service to begin memory tracking for
// |sequence_number_|. This will normally be created from the UI thread, so
// repost to the IO thread.
GpuProcessHost::CallOnUI(
FROM_HERE, GPU_PROCESS_KIND_SANDBOXED, /* force_create=*/false,
base::BindOnce(
[](uint32_t sequence_num, GpuProcessHost* host) {
// There may be no host nor service available. This may occur during
// shutdown, when the service is fully disabled, and in some tests.
// In those cases do nothing.
if (!host)
return;
if (auto* gpu_service = host->gpu_service()) {
gpu_service->StartPeakMemoryMonitor(sequence_num);
}
},
sequence_num_));
// |sequence_number_|.
auto* host =
GpuProcessHost::Get(GPU_PROCESS_KIND_SANDBOXED, /*force_create*/ false);
// There may be no host nor service available. This may occur during
// shutdown, when the service is fully disabled, and in some tests.
// In those cases do nothing.
if (!host) {
return;
}
if (auto* gpu_service = host->gpu_service()) {
gpu_service->StartPeakMemoryMonitor(sequence_num_);
}
}
PeakGpuMemoryTrackerImpl::~PeakGpuMemoryTrackerImpl() {
if (canceled_)
return;
// TODO(thiabaud): Do this call inline, since this happens on the UI thread.
GpuProcessHost::CallOnUI(
FROM_HERE, GPU_PROCESS_KIND_SANDBOXED, /* force_create=*/false,
base::BindOnce(
[](uint32_t sequence_num, PeakGpuMemoryTracker::Usage usage,
base::OnceClosure testing_callback, GpuProcessHost* host) {
// There may be no host nor service available. This may occur during
// shutdown, when the service is fully disabled, and in some tests.
// In those cases there is nothing to report to UMA. However we
// still run the optional testing callback.
if (!host) {
std::move(testing_callback).Run();
return;
}
if (auto* gpu_service = host->gpu_service()) {
gpu_service->GetPeakMemoryUsage(
sequence_num, base::BindOnce(&PeakGpuMemoryCallback, usage,
std::move(testing_callback)));
}
},
sequence_num_, usage_,
std::move(post_gpu_service_callback_for_testing_)));
auto* host =
GpuProcessHost::Get(GPU_PROCESS_KIND_SANDBOXED, /*force_create*/ false);
// There may be no host nor service available. This may occur during
// shutdown, when the service is fully disabled, and in some tests.
// In those cases there is nothing to report to UMA. However we
// still run the optional testing callback.
if (!host) {
std::move(post_gpu_service_callback_for_testing_).Run();
return;
}
if (auto* gpu_service = host->gpu_service()) {
gpu_service->GetPeakMemoryUsage(
sequence_num_,
base::BindOnce(&PeakGpuMemoryCallback, usage_,
std::move(post_gpu_service_callback_for_testing_)));
}
}
void PeakGpuMemoryTrackerImpl::Cancel() {
canceled_ = true;
// TODO(thiabaud): Do this call inline, since this happens on the UI thread.
//
auto* host =
GpuProcessHost::Get(GPU_PROCESS_KIND_SANDBOXED, /*force_create*/ false);
if (!host) {
return;
}
// Notify the GpuProcessHost that we are done observing this sequence.
GpuProcessHost::CallOnUI(FROM_HERE, GPU_PROCESS_KIND_SANDBOXED,
/* force_create=*/false,
base::BindOnce(
[](uint32_t sequence_num, GpuProcessHost* host) {
if (!host)
return;
if (auto* gpu_service = host->gpu_service())
gpu_service->GetPeakMemoryUsage(
sequence_num, base::DoNothing());
},
sequence_num_));
if (auto* gpu_service = host->gpu_service()) {
gpu_service->GetPeakMemoryUsage(sequence_num_, base::DoNothing());
}
}
} // namespace content

@ -38,7 +38,7 @@ class PeakGpuMemoryTrackerImpl : public PeakGpuMemoryTracker {
friend class PeakGpuMemoryTrackerImplTest;
// A callback which will be run after receiving a callback from the
// GpuService. For use by tests to synchronize work done on the IO thread.
// GpuService. For use by tests to synchronize work done on the UI thread.
base::OnceClosure post_gpu_service_callback_for_testing_ = base::DoNothing();
// Provides the unique identifier for each PeakGpuMemoryTrackerImpl.

@ -288,7 +288,7 @@ IN_PROC_BROWSER_TEST_F(PeakGpuMemoryTrackerImplTest, PeakGpuMemoryCallback) {
// the callback being a posted task.
tracker.reset();
FlushRemoteForTesting();
// Wait for callback to be ran on the IO thread, which will call the
// Wait for callback to be ran on the UI thread, which will call the
// QuitClosure.
run_loop.Run();
histogram.ExpectUniqueSample("Memory.GPU.PeakMemoryUsage2.PageLoad",

@ -21,7 +21,7 @@ namespace content {
// Parameters:
// - |usage|: Indicates the category of GPU memory usage being tracked.
// - |testing_callback|: (Optional) Closure used by some tests to synchronize
// with the work done here on the IO thread.
// with the work done here on the UI thread.
// - |peak_memory|: The total peak GPU memory usage in bytes.
// - |allocation_per_source|: A breakdown of the peak memory usage, showing how
// much was allocated by each source.