From 3c74da9ede3a50335ea1a5237d5565bb472e3141 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Fri, 28 Jun 2019 10:16:49 -0700 Subject: GpuStats: move the stats send at Activity launch off UI thread Prevously when App Activity launches, we send GpuStats on the main UI thread. The async binder to send the stats only takes 30us. However, to get the gpuservice, the sync binder takes around 1.5ms because of the massive binders on CPU at Activity launch. Thus we just move the stats sending to a separate thread off the main UI thread. Now it's just 50us cost on the main UI thread. Bug: 136228448 Test: systrace and check Change-Id: Iff47dbc6a26a9d62ad33e92f93c079ac74fb3ea2 --- libs/graphicsenv/GraphicsEnv.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 1c5fa52855..24b6c2d6de 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -37,6 +37,7 @@ #include #include +#include // TODO(b/37049319) Get this from a header once one exists extern "C" { @@ -163,17 +164,20 @@ void GraphicsEnv::setDriverPathAndSphalLibraries(const std::string path, void GraphicsEnv::hintActivityLaunch() { ATRACE_CALL(); - // If there's already graphics driver preloaded in the process, just send - // the stats info to GpuStats directly through async binder. - std::lock_guard lock(mStatsLock); - if (mGpuStats.glDriverToSend) { - mGpuStats.glDriverToSend = false; - sendGpuStatsLocked(GraphicsEnv::Api::API_GL, true, mGpuStats.glDriverLoadingTime); - } - if (mGpuStats.vkDriverToSend) { - mGpuStats.vkDriverToSend = false; - sendGpuStatsLocked(GraphicsEnv::Api::API_VK, true, mGpuStats.vkDriverLoadingTime); - } + std::thread trySendGpuStatsThread([this]() { + // If there's already graphics driver preloaded in the process, just send + // the stats info to GpuStats directly through async binder. + std::lock_guard lock(mStatsLock); + if (mGpuStats.glDriverToSend) { + mGpuStats.glDriverToSend = false; + sendGpuStatsLocked(GraphicsEnv::Api::API_GL, true, mGpuStats.glDriverLoadingTime); + } + if (mGpuStats.vkDriverToSend) { + mGpuStats.vkDriverToSend = false; + sendGpuStatsLocked(GraphicsEnv::Api::API_VK, true, mGpuStats.vkDriverLoadingTime); + } + }); + trySendGpuStatsThread.detach(); } void GraphicsEnv::setGpuStats(const std::string& driverPackageName, -- cgit v1.2.3-59-g8ed1b