From 838a89f3368742974268a5729ec41e6d7a5f2d01 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 24 Jun 2020 14:16:58 -0700 Subject: [PATCH 1/2] Make Shell::NotifyLowMemoryWarning trace --- shell/common/shell.cc | 9 +++++++-- shell/common/shell.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 4acf8af36799c..71f0c3cd011a2 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -430,7 +430,9 @@ Shell::~Shell() { platform_latch.Wait(); } -void Shell::NotifyLowMemoryWarning() const { +void Shell::NotifyLowMemoryWarning() { + TRACE_EVENT_ASYNC_BEGIN0("flutter", "Shell::NotifyLowMemoryWarning", + notify_low_memory_trace_id_); // This does not require a current isolate but does require a running VM. // Since a valid shell will not be returned to the embedder without a valid // DartVMRef, we can be certain that this is a safe spot to assume a VM is @@ -438,10 +440,13 @@ void Shell::NotifyLowMemoryWarning() const { ::Dart_NotifyLowMemory(); task_runners_.GetRasterTaskRunner()->PostTask( - [rasterizer = rasterizer_->GetWeakPtr()]() { + [rasterizer = rasterizer_->GetWeakPtr(), + trace_id = notify_low_memory_trace_id_++]() { if (rasterizer) { rasterizer->NotifyLowMemoryWarning(); } + TRACE_EVENT_ASYNC_END0("flutter", "Shell::NotifyLowMemoryWarning", + trace_id); }); // The IO Manager uses resource cache limits of 0, so it is not necessary // to purge them. diff --git a/shell/common/shell.h b/shell/common/shell.h index fd1a30d3f4e35..afdfea2f74d6e 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -284,7 +284,7 @@ class Shell final : public PlatformView::Delegate, /// @brief Used by embedders to notify that there is a low memory /// warning. The shell will attempt to purge caches. Current, only /// the rasterizer cache is purged. - void NotifyLowMemoryWarning() const; + void NotifyLowMemoryWarning(); //---------------------------------------------------------------------------- /// @brief Used by embedders to check if all shell subcomponents are @@ -397,6 +397,7 @@ class Shell final : public PlatformView::Delegate, std::atomic waiting_for_first_frame_ = true; std::mutex waiting_for_first_frame_mutex_; std::condition_variable waiting_for_first_frame_condition_; + size_t notify_low_memory_trace_id_ = 0; // Written in the UI thread and read from the raster thread. Hence make it // atomic. From 8467ab59d63e1f983ad9690d7a8b6d8d470ec5b9 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 24 Jun 2020 14:53:23 -0700 Subject: [PATCH 2/2] TraceNonce --- shell/common/shell.cc | 8 ++++---- shell/common/shell.h | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 71f0c3cd011a2..976d1befb37b5 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -430,9 +430,10 @@ Shell::~Shell() { platform_latch.Wait(); } -void Shell::NotifyLowMemoryWarning() { +void Shell::NotifyLowMemoryWarning() const { + auto trace_id = fml::tracing::TraceNonce(); TRACE_EVENT_ASYNC_BEGIN0("flutter", "Shell::NotifyLowMemoryWarning", - notify_low_memory_trace_id_); + trace_id); // This does not require a current isolate but does require a running VM. // Since a valid shell will not be returned to the embedder without a valid // DartVMRef, we can be certain that this is a safe spot to assume a VM is @@ -440,8 +441,7 @@ void Shell::NotifyLowMemoryWarning() { ::Dart_NotifyLowMemory(); task_runners_.GetRasterTaskRunner()->PostTask( - [rasterizer = rasterizer_->GetWeakPtr(), - trace_id = notify_low_memory_trace_id_++]() { + [rasterizer = rasterizer_->GetWeakPtr(), trace_id = trace_id]() { if (rasterizer) { rasterizer->NotifyLowMemoryWarning(); } diff --git a/shell/common/shell.h b/shell/common/shell.h index afdfea2f74d6e..fd1a30d3f4e35 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -284,7 +284,7 @@ class Shell final : public PlatformView::Delegate, /// @brief Used by embedders to notify that there is a low memory /// warning. The shell will attempt to purge caches. Current, only /// the rasterizer cache is purged. - void NotifyLowMemoryWarning(); + void NotifyLowMemoryWarning() const; //---------------------------------------------------------------------------- /// @brief Used by embedders to check if all shell subcomponents are @@ -397,7 +397,6 @@ class Shell final : public PlatformView::Delegate, std::atomic waiting_for_first_frame_ = true; std::mutex waiting_for_first_frame_mutex_; std::condition_variable waiting_for_first_frame_condition_; - size_t notify_low_memory_trace_id_ = 0; // Written in the UI thread and read from the raster thread. Hence make it // atomic.