Commit 31048aaa authored by Carlos Knippschild's avatar Carlos Knippschild Committed by Commit Bot

Offline pages tracing instrumentation: new and improvements

This change adds new and improves existing code instrumentation for
tracing reports. They should help both with performance tracking and
memory usage investigation.

Bug: 806137, 793109
Change-Id: I45fd4ef567e83c174d09cf41424a961c13adaf23
Reviewed-on: https://chromium-review.googlesource.com/888087
Commit-Queue: Carlos Knippschild <carlosk@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarYafei Duan <romax@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533059}
parent 62ca7f7c
...@@ -22,6 +22,7 @@ import org.chromium.base.CollectionUtil; ...@@ -22,6 +22,7 @@ import org.chromium.base.CollectionUtil;
import org.chromium.base.DiscardableReferencePool; import org.chromium.base.DiscardableReferencePool;
import org.chromium.base.FileUtils; import org.chromium.base.FileUtils;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.TraceEvent;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
...@@ -212,6 +213,7 @@ public class DownloadManagerUi ...@@ -212,6 +213,7 @@ public class DownloadManagerUi
public DownloadManagerUi(Activity activity, boolean isOffTheRecord, public DownloadManagerUi(Activity activity, boolean isOffTheRecord,
ComponentName parentComponent, boolean isSeparateActivity, ComponentName parentComponent, boolean isSeparateActivity,
SnackbarManager snackbarManager) { SnackbarManager snackbarManager) {
TraceEvent.startAsync("DownloadManagerUi shown", hashCode());
mActivity = activity; mActivity = activity;
ChromeApplication application = (ChromeApplication) activity.getApplication(); ChromeApplication application = (ChromeApplication) activity.getApplication();
mBackendProvider = sProviderForTests == null mBackendProvider = sProviderForTests == null
...@@ -302,6 +304,7 @@ public class DownloadManagerUi ...@@ -302,6 +304,7 @@ public class DownloadManagerUi
mBackendProvider.destroy(); mBackendProvider.destroy();
mSelectableListLayout.onDestroyed(); mSelectableListLayout.onDestroyed();
TraceEvent.finishAsync("DownloadManagerUi shown", hashCode());
} }
/** /**
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/guid.h" #include "base/guid.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
#include "components/offline_pages/core/background/request_coordinator.h" #include "components/offline_pages/core/background/request_coordinator.h"
#include "components/offline_pages/core/background/save_page_request.h" #include "components/offline_pages/core/background/save_page_request.h"
#include "components/offline_pages/core/client_namespace_constants.h" #include "components/offline_pages/core/client_namespace_constants.h"
...@@ -386,6 +387,8 @@ void DownloadUIAdapter::ClearCache() { ...@@ -386,6 +387,8 @@ void DownloadUIAdapter::ClearCache() {
} }
items_.clear(); items_.clear();
state_ = State::NOT_LOADED; state_ = State::NOT_LOADED;
TRACE_EVENT_ASYNC_END0("offline_pages", "DownloadUIAdapter: items cached",
this);
} }
void DownloadUIAdapter::OnOfflinePagesLoaded( void DownloadUIAdapter::OnOfflinePagesLoaded(
...@@ -437,6 +440,8 @@ void DownloadUIAdapter::OnRequestsLoaded( ...@@ -437,6 +440,8 @@ void DownloadUIAdapter::OnRequestsLoaded(
request_coordinator_->AddObserver(this); request_coordinator_->AddObserver(this);
state_ = State::LOADED; state_ = State::LOADED;
TRACE_EVENT_ASYNC_BEGIN1("offline_pages", "DownloadUIAdapter: items cached",
this, "initial count", items_.size());
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnItemsAvailable(this); observer.OnItemsAvailable(this);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/trace_event/trace_event.h"
#include "components/offline_pages/core/client_policy_controller.h" #include "components/offline_pages/core/client_policy_controller.h"
#include "components/offline_pages/core/offline_page_metadata_store_sql.h" #include "components/offline_pages/core/offline_page_metadata_store_sql.h"
#include "components/offline_pages/core/offline_store_utils.h" #include "components/offline_pages/core/offline_store_utils.h"
...@@ -128,6 +129,8 @@ ClearLegacyTemporaryPagesTask::ClearLegacyTemporaryPagesTask( ...@@ -128,6 +129,8 @@ ClearLegacyTemporaryPagesTask::ClearLegacyTemporaryPagesTask(
ClearLegacyTemporaryPagesTask::~ClearLegacyTemporaryPagesTask() {} ClearLegacyTemporaryPagesTask::~ClearLegacyTemporaryPagesTask() {}
void ClearLegacyTemporaryPagesTask::Run() { void ClearLegacyTemporaryPagesTask::Run() {
TRACE_EVENT_ASYNC_BEGIN0("offline_pages",
"ClearLegacyTemporaryPagesTask running", this);
std::vector<std::string> temp_namespaces = std::vector<std::string> temp_namespaces =
policy_controller_->GetNamespacesRemovedOnCacheReset(); policy_controller_->GetNamespacesRemovedOnCacheReset();
store_->Execute( store_->Execute(
...@@ -145,6 +148,9 @@ void ClearLegacyTemporaryPagesTask::OnClearLegacyTemporaryPagesDone( ...@@ -145,6 +148,9 @@ void ClearLegacyTemporaryPagesTask::OnClearLegacyTemporaryPagesDone(
// indicating which part failed. // indicating which part failed.
DVLOG(1) << "ClearLegacyTemporaryPagesTask returns with result: " << result; DVLOG(1) << "ClearLegacyTemporaryPagesTask returns with result: " << result;
TaskComplete(); TaskComplete();
TRACE_EVENT_ASYNC_END1("offline_pages",
"ClearLegacyTemporaryPagesTask running", this,
"result", result);
} }
} // namespace offline_pages } // namespace offline_pages
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/time/clock.h" #include "base/time/clock.h"
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "components/offline_pages/core/client_policy_controller.h" #include "components/offline_pages/core/client_policy_controller.h"
#include "components/offline_pages/core/offline_page_client_policy.h" #include "components/offline_pages/core/offline_page_client_policy.h"
#include "components/offline_pages/core/offline_page_metadata_store_sql.h" #include "components/offline_pages/core/offline_page_metadata_store_sql.h"
...@@ -240,6 +241,7 @@ ClearStorageTask::ClearStorageTask(OfflinePageMetadataStoreSQL* store, ...@@ -240,6 +241,7 @@ ClearStorageTask::ClearStorageTask(OfflinePageMetadataStoreSQL* store,
ClearStorageTask::~ClearStorageTask() {} ClearStorageTask::~ClearStorageTask() {}
void ClearStorageTask::Run() { void ClearStorageTask::Run() {
TRACE_EVENT_ASYNC_BEGIN0("offline_pages", "ClearStorageTask running", this);
archive_manager_->GetStorageStats( archive_manager_->GetStorageStats(
base::Bind(&ClearStorageTask::OnGetStorageStatsDone, base::Bind(&ClearStorageTask::OnGetStorageStatsDone,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
...@@ -272,6 +274,9 @@ void ClearStorageTask::InformClearStorageDone(size_t pages_cleared, ...@@ -272,6 +274,9 @@ void ClearStorageTask::InformClearStorageDone(size_t pages_cleared,
ClearStorageResult result) { ClearStorageResult result) {
std::move(callback_).Run(pages_cleared, result); std::move(callback_).Run(pages_cleared, result);
TaskComplete(); TaskComplete();
TRACE_EVENT_ASYNC_END2("offline_pages", "ClearStorageTask running", this,
"result", static_cast<int>(result), "pages_cleared",
pages_cleared);
} }
} // namespace offline_pages } // namespace offline_pages
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/files/file_enumerator.h" #include "base/files/file_enumerator.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/trace_event/trace_event.h"
#include "components/offline_pages/core/client_policy_controller.h" #include "components/offline_pages/core/client_policy_controller.h"
#include "components/offline_pages/core/offline_page_metadata_store_sql.h" #include "components/offline_pages/core/offline_page_metadata_store_sql.h"
#include "components/offline_pages/core/offline_page_types.h" #include "components/offline_pages/core/offline_page_types.h"
...@@ -172,6 +173,8 @@ PersistentPagesConsistencyCheckTask::PersistentPagesConsistencyCheckTask( ...@@ -172,6 +173,8 @@ PersistentPagesConsistencyCheckTask::PersistentPagesConsistencyCheckTask(
PersistentPagesConsistencyCheckTask::~PersistentPagesConsistencyCheckTask() {} PersistentPagesConsistencyCheckTask::~PersistentPagesConsistencyCheckTask() {}
void PersistentPagesConsistencyCheckTask::Run() { void PersistentPagesConsistencyCheckTask::Run() {
TRACE_EVENT_ASYNC_BEGIN0("offline_pages",
"PersistentPagesConsistencyCheckTask running", this);
std::vector<std::string> namespaces = policy_controller_->GetAllNamespaces(); std::vector<std::string> namespaces = policy_controller_->GetAllNamespaces();
std::vector<std::string> persistent_namespace_names; std::vector<std::string> persistent_namespace_names;
for (const auto& name_space : namespaces) { for (const auto& name_space : namespaces) {
...@@ -191,6 +194,9 @@ void PersistentPagesConsistencyCheckTask::OnCheckConsistencyDone( ...@@ -191,6 +194,9 @@ void PersistentPagesConsistencyCheckTask::OnCheckConsistencyDone(
UMA_HISTOGRAM_ENUMERATION("OfflinePages.ConsistencyCheck.Persistent.Result", UMA_HISTOGRAM_ENUMERATION("OfflinePages.ConsistencyCheck.Persistent.Result",
result, SyncOperationResult::RESULT_COUNT); result, SyncOperationResult::RESULT_COUNT);
TaskComplete(); TaskComplete();
TRACE_EVENT_ASYNC_END1("offline_pages",
"PersistentPagesConsistencyCheckTask running", this,
"result", static_cast<int>(result));
} }
} // namespace offline_pages } // namespace offline_pages
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/files/file_enumerator.h" #include "base/files/file_enumerator.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/trace_event/trace_event.h"
#include "components/offline_pages/core/client_policy_controller.h" #include "components/offline_pages/core/client_policy_controller.h"
#include "components/offline_pages/core/offline_page_metadata_store_sql.h" #include "components/offline_pages/core/offline_page_metadata_store_sql.h"
#include "components/offline_pages/core/offline_page_types.h" #include "components/offline_pages/core/offline_page_types.h"
...@@ -171,6 +172,8 @@ TemporaryPagesConsistencyCheckTask::TemporaryPagesConsistencyCheckTask( ...@@ -171,6 +172,8 @@ TemporaryPagesConsistencyCheckTask::TemporaryPagesConsistencyCheckTask(
TemporaryPagesConsistencyCheckTask::~TemporaryPagesConsistencyCheckTask() {} TemporaryPagesConsistencyCheckTask::~TemporaryPagesConsistencyCheckTask() {}
void TemporaryPagesConsistencyCheckTask::Run() { void TemporaryPagesConsistencyCheckTask::Run() {
TRACE_EVENT_ASYNC_BEGIN0("offline_pages",
"TemporaryPagesConsistencyCheckTask running", this);
std::vector<std::string> temp_namespaces = std::vector<std::string> temp_namespaces =
policy_controller_->GetNamespacesRemovedOnCacheReset(); policy_controller_->GetNamespacesRemovedOnCacheReset();
store_->Execute( store_->Execute(
...@@ -185,6 +188,9 @@ void TemporaryPagesConsistencyCheckTask::OnCheckConsistencyDone( ...@@ -185,6 +188,9 @@ void TemporaryPagesConsistencyCheckTask::OnCheckConsistencyDone(
UMA_HISTOGRAM_ENUMERATION("OfflinePages.ConsistencyCheck.Temporary.Result", UMA_HISTOGRAM_ENUMERATION("OfflinePages.ConsistencyCheck.Temporary.Result",
result, SyncOperationResult::RESULT_COUNT); result, SyncOperationResult::RESULT_COUNT);
TaskComplete(); TaskComplete();
TRACE_EVENT_ASYNC_END1("offline_pages",
"TemporaryPagesConsistencyCheckTask running", this,
"result", static_cast<int>(result));
} }
} // namespace offline_pages } // namespace offline_pages
...@@ -123,9 +123,9 @@ class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { ...@@ -123,9 +123,9 @@ class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore {
return; return;
} }
TRACE_EVENT_ASYNC_BEGIN1("offline_pages", TRACE_EVENT_ASYNC_BEGIN1("offline_pages", "Metadata Store: task execution",
"Metadata Store: Command execution", this, this, "is store loaded",
"is store loaded", state_ == StoreState::LOADED); state_ == StoreState::LOADED);
// This if allows to run commands later, after store was given a chance to // This if allows to run commands later, after store was given a chance to
// initialize. They would be failing immediately otherwise. // initialize. They would be failing immediately otherwise.
if (state_ == StoreState::INITIALIZING) { if (state_ == StoreState::INITIALIZING) {
...@@ -133,9 +133,8 @@ class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { ...@@ -133,9 +133,8 @@ class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore {
base::BindOnce(&OfflinePageMetadataStoreSQL::Execute<T>, base::BindOnce(&OfflinePageMetadataStoreSQL::Execute<T>,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
std::move(run_callback), std::move(result_callback))); std::move(run_callback), std::move(result_callback)));
TRACE_EVENT_ASYNC_END1("offline_pages", TRACE_EVENT_ASYNC_END1("offline_pages", "Metadata Store: task execution",
"Metadata Store: Command execution", this, this, "postponed", true);
"postponed", true);
return; return;
} }
...@@ -172,10 +171,16 @@ class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { ...@@ -172,10 +171,16 @@ class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore {
base::BindOnce(&OfflinePageMetadataStoreSQL::CloseInternal, base::BindOnce(&OfflinePageMetadataStoreSQL::CloseInternal,
closing_weak_ptr_factory_.GetWeakPtr()), closing_weak_ptr_factory_.GetWeakPtr()),
kClosingDelay); kClosingDelay);
TRACE_EVENT_ASYNC_END0("offline_pages", "Metadata Store: Command execution",
this);
// Note: the time recorded for this trace step will include thread hop wait
// times to the background thread and back.
TRACE_EVENT_ASYNC_STEP_PAST0(
"offline_pages", "Metadata Store: task execution", this, "Task");
std::move(result_callback).Run(std::move(result)); std::move(result_callback).Run(std::move(result));
TRACE_EVENT_ASYNC_STEP_PAST0(
"offline_pages", "Metadata Store: task execution", this, "Callback");
TRACE_EVENT_ASYNC_END0("offline_pages", "Metadata Store: task execution",
this);
} }
// Internal function initiating the closing. // Internal function initiating the closing.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "components/download/public/background_service/download_params.h" #include "components/download/public/background_service/download_params.h"
#include "components/download/public/background_service/download_service.h" #include "components/download/public/background_service/download_service.h"
#include "components/offline_pages/core/offline_event_logger.h" #include "components/offline_pages/core/offline_event_logger.h"
...@@ -146,6 +147,15 @@ void PrefetchDownloaderImpl::OnDownloadServiceReady( ...@@ -146,6 +147,15 @@ void PrefetchDownloaderImpl::OnDownloadServiceReady(
success_downloads) { success_downloads) {
DCHECK_EQ(DownloadServiceStatus::INITIALIZING, download_service_status_); DCHECK_EQ(DownloadServiceStatus::INITIALIZING, download_service_status_);
download_service_status_ = DownloadServiceStatus::STARTED; download_service_status_ = DownloadServiceStatus::STARTED;
// Given the imposed simultaneous downloads limits, outstanding_download_ids
// will only ever contain a handful of elements and so only a negligible
// performance impact is expected from the trace-only loop below.
for (const std::string& outstanding_download_id : outstanding_download_ids) {
TRACE_EVENT_ASYNC_BEGIN2(
"offline_pages", "PrefetchDownloaderImpl: downloading article",
std::hash<std::string>{}(outstanding_download_id), "download_id",
outstanding_download_id, "resumed after restart", "true");
}
prefetch_service_->GetLogger()->RecordActivity("Downloader: Service ready."); prefetch_service_->GetLogger()->RecordActivity("Downloader: Service ready.");
...@@ -177,6 +187,9 @@ void PrefetchDownloaderImpl::OnDownloadSucceeded( ...@@ -177,6 +187,9 @@ void PrefetchDownloaderImpl::OnDownloadSucceeded(
const std::string& download_id, const std::string& download_id,
const base::FilePath& file_path, const base::FilePath& file_path,
int64_t file_size) { int64_t file_size) {
TRACE_EVENT_ASYNC_END1(
"offline_pages", "PrefetchDownloaderImpl: downloading article",
std::hash<std::string>{}(download_id), "succeeded", "true");
prefetch_service_->GetLogger()->RecordActivity( prefetch_service_->GetLogger()->RecordActivity(
"Downloader: Download succeeded, download_id=" + download_id); "Downloader: Download succeeded, download_id=" + download_id);
NotifyDispatcher(prefetch_service_, NotifyDispatcher(prefetch_service_,
...@@ -184,6 +197,9 @@ void PrefetchDownloaderImpl::OnDownloadSucceeded( ...@@ -184,6 +197,9 @@ void PrefetchDownloaderImpl::OnDownloadSucceeded(
} }
void PrefetchDownloaderImpl::OnDownloadFailed(const std::string& download_id) { void PrefetchDownloaderImpl::OnDownloadFailed(const std::string& download_id) {
TRACE_EVENT_ASYNC_END1(
"offline_pages", "PrefetchDownloaderImpl: downloading article",
std::hash<std::string>{}(download_id), "succeeded", "false");
PrefetchDownloadResult result; PrefetchDownloadResult result;
result.download_id = download_id; result.download_id = download_id;
prefetch_service_->GetLogger()->RecordActivity( prefetch_service_->GetLogger()->RecordActivity(
...@@ -206,8 +222,13 @@ void PrefetchDownloaderImpl::OnStartDownload( ...@@ -206,8 +222,13 @@ void PrefetchDownloaderImpl::OnStartDownload(
// to simplify the control flow since this situation should rarely happen. The // to simplify the control flow since this situation should rarely happen. The
// Download.Service.Request.StartResult.OfflinePage histogram tracks these // Download.Service.Request.StartResult.OfflinePage histogram tracks these
// cases and would signal the need to revisit this decision. // cases and would signal the need to revisit this decision.
if (result != download::DownloadParams::StartResult::ACCEPTED) if (result != download::DownloadParams::StartResult::ACCEPTED) {
OnDownloadFailed(download_id); OnDownloadFailed(download_id);
} else {
TRACE_EVENT_ASYNC_BEGIN1(
"offline_pages", "PrefetchDownloaderImpl: downloading article",
std::hash<std::string>{}(download_id), "download_id", download_id);
}
} }
void PrefetchDownloaderImpl::CleanupDownloads( void PrefetchDownloaderImpl::CleanupDownloads(
......
...@@ -86,7 +86,7 @@ class PrefetchStore { ...@@ -86,7 +86,7 @@ class PrefetchStore {
} }
TRACE_EVENT_ASYNC_BEGIN1( TRACE_EVENT_ASYNC_BEGIN1(
"offline_pages", "Prefetch Store: Command execution", this, "offline_pages", "Prefetch Store: task execution", this,
"is store loaded", "is store loaded",
initialization_status_ == InitializationStatus::SUCCESS); initialization_status_ == InitializationStatus::SUCCESS);
// Ensure that any scheduled close operations are canceled. // Ensure that any scheduled close operations are canceled.
...@@ -128,10 +128,16 @@ class PrefetchStore { ...@@ -128,10 +128,16 @@ class PrefetchStore {
base::BindOnce(&PrefetchStore::CloseInternal, base::BindOnce(&PrefetchStore::CloseInternal,
closing_weak_ptr_factory_.GetWeakPtr()), closing_weak_ptr_factory_.GetWeakPtr()),
kClosingDelay); kClosingDelay);
TRACE_EVENT_ASYNC_END0("offline_pages", "Prefetch Store: Command execution",
this);
// Note: the time recorded for this trace step will include thread hop wait
// times to the background thread and back.
TRACE_EVENT_ASYNC_STEP_PAST0(
"offline_pages", "Prefetch Store: task execution", this, "Task");
std::move(result_callback).Run(std::move(result)); std::move(result_callback).Run(std::move(result));
TRACE_EVENT_ASYNC_STEP_PAST0(
"offline_pages", "Prefetch Store: task execution", this, "Callback");
TRACE_EVENT_ASYNC_END0("offline_pages", "Prefetch Store: task execution",
this);
} }
// Internal function initiating the closing. // Internal function initiating the closing.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment