diff options
author | 2022-08-17 12:57:41 +0100 | |
---|---|---|
committer | 2022-09-01 16:22:10 +0100 | |
commit | 23457d0f835624f4b4985c8169f0ccedcab68287 (patch) | |
tree | bf68e4ecb77abbcab018d660c239e6062bf703e6 | |
parent | ec6c073aed281ce50cdd0f38b0f9f4e247109700 (diff) |
Trampoline atrace definitions through libbinder to libcutils
This avoids adding libcutils (additional) deps to aidls that
generate binder trace tags (the default for cpp backends now).
Others:
1. Added libbinder to libinputflinger_base_defaults to fix the
build
2. Fixed redefinition of ATRACE_TAG by redefining package manager
specific trace functions in a separate source
Test: Manual
Bug: 161393989
Change-Id: I7b83c0d11c3fa98bf31c29a880853566ad0909c3
-rw-r--r-- | cmds/installd/Android.bp | 1 | ||||
-rw-r--r-- | cmds/installd/InstalldNativeService.cpp | 123 | ||||
-rw-r--r-- | cmds/installd/SysTrace.cpp | 30 | ||||
-rw-r--r-- | cmds/installd/SysTrace.h | 22 | ||||
-rw-r--r-- | libs/binder/Android.bp | 1 | ||||
-rw-r--r-- | libs/binder/Trace.cpp | 32 | ||||
-rw-r--r-- | libs/binder/include/binder/Trace.h | 41 | ||||
-rw-r--r-- | services/inputflinger/Android.bp | 1 |
8 files changed, 189 insertions, 62 deletions
diff --git a/cmds/installd/Android.bp b/cmds/installd/Android.bp index 0f7c48964f..8e37ce91e6 100644 --- a/cmds/installd/Android.bp +++ b/cmds/installd/Android.bp @@ -25,6 +25,7 @@ cc_defaults { "CrateManager.cpp", "InstalldNativeService.cpp", "QuotaUtils.cpp", + "SysTrace.cpp", "dexopt.cpp", "execv_helper.cpp", "globals.cpp", diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp index 8f163b94d6..d26d301c1d 100644 --- a/cmds/installd/InstalldNativeService.cpp +++ b/cmds/installd/InstalldNativeService.cpp @@ -16,8 +16,6 @@ #include "InstalldNativeService.h" -#define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER - #include <errno.h> #include <fts.h> #include <inttypes.h> @@ -75,6 +73,7 @@ #include "CrateManager.h" #include "MatchExtensionGen.h" #include "QuotaUtils.h" +#include "SysTrace.h" #ifndef LOG_TAG #define LOG_TAG "installd" @@ -1327,7 +1326,7 @@ binder::Status InstalldNativeService::fixupAppData(const std::optional<std::stri const char* uuid_ = uuid ? uuid->c_str() : nullptr; for (auto userId : get_known_users(uuid_)) { LOCK_USER(); - ATRACE_BEGIN("fixup user"); + atrace_pm_begin("fixup user"); FTS* fts; FTSENT* p; auto ce_path = create_data_user_ce_path(uuid_, userId); @@ -1417,7 +1416,7 @@ binder::Status InstalldNativeService::fixupAppData(const std::optional<std::stri } } fts_close(fts); - ATRACE_END(); + atrace_pm_end(); } return ok(); } @@ -1970,7 +1969,7 @@ binder::Status InstalldNativeService::freeCache(const std::optional<std::string> // files from the UIDs which are most over their allocated quota // 1. Create trackers for every known UID - ATRACE_BEGIN("create"); + atrace_pm_begin("create"); const auto users = get_known_users(uuid_); #ifdef GRANULAR_LOCKS std::vector<UserLock> userLocks; @@ -2051,10 +2050,10 @@ binder::Status InstalldNativeService::freeCache(const std::optional<std::string> } fts_close(fts); } - ATRACE_END(); + atrace_pm_end(); // 2. Populate tracker stats and insert into priority queue - ATRACE_BEGIN("populate"); + atrace_pm_begin("populate"); auto cmp = [](std::shared_ptr<CacheTracker> left, std::shared_ptr<CacheTracker> right) { return (left->getCacheRatio() < right->getCacheRatio()); }; @@ -2064,11 +2063,11 @@ binder::Status InstalldNativeService::freeCache(const std::optional<std::string> it.second->loadStats(); queue.push(it.second); } - ATRACE_END(); + atrace_pm_end(); // 3. Bounce across the queue, freeing items from whichever tracker is // the most over their assigned quota - ATRACE_BEGIN("bounce"); + atrace_pm_begin("bounce"); std::shared_ptr<CacheTracker> active; while (active || !queue.empty()) { // Only look at apps under quota when explicitly requested @@ -2124,7 +2123,7 @@ binder::Status InstalldNativeService::freeCache(const std::optional<std::string> } } } - ATRACE_END(); + atrace_pm_end(); } else { return error("Legacy cache logic no longer supported"); @@ -2469,84 +2468,84 @@ binder::Status InstalldNativeService::getAppSize(const std::optional<std::string flags &= ~FLAG_USE_QUOTA; } - ATRACE_BEGIN("obb"); + atrace_pm_begin("obb"); for (const auto& packageName : packageNames) { auto obbCodePath = create_data_media_package_path(uuid_, userId, "obb", packageName.c_str()); calculate_tree_size(obbCodePath, &extStats.codeSize); } - ATRACE_END(); + atrace_pm_end(); // Calculating the app size of the external storage owning app in a manual way, since // calculating it through quota apis also includes external media storage in the app storage // numbers if (flags & FLAG_USE_QUOTA && appId >= AID_APP_START && !ownsExternalStorage(appId)) { - ATRACE_BEGIN("code"); + atrace_pm_begin("code"); for (const auto& codePath : codePaths) { calculate_tree_size(codePath, &stats.codeSize, -1, multiuser_get_shared_gid(0, appId)); } - ATRACE_END(); + atrace_pm_end(); - ATRACE_BEGIN("quota"); + atrace_pm_begin("quota"); collectQuotaStats(uuidString, userId, appId, &stats, &extStats); - ATRACE_END(); + atrace_pm_end(); } else { - ATRACE_BEGIN("code"); + atrace_pm_begin("code"); for (const auto& codePath : codePaths) { calculate_tree_size(codePath, &stats.codeSize); } - ATRACE_END(); + atrace_pm_end(); for (size_t i = 0; i < packageNames.size(); i++) { const char* pkgname = packageNames[i].c_str(); - ATRACE_BEGIN("data"); + atrace_pm_begin("data"); auto cePath = create_data_user_ce_package_path(uuid_, userId, pkgname, ceDataInodes[i]); collectManualStats(cePath, &stats); auto dePath = create_data_user_de_package_path(uuid_, userId, pkgname); collectManualStats(dePath, &stats); - ATRACE_END(); + atrace_pm_end(); // In case of sdk sandbox storage (e.g. /data/misc_ce/0/sdksandbox/<package-name>), // collect individual stats of each subdirectory (shared, storage of each sdk etc.) if (appId >= AID_APP_START && appId <= AID_APP_END) { - ATRACE_BEGIN("sdksandbox"); + atrace_pm_begin("sdksandbox"); auto sdkSandboxCePath = create_data_misc_sdk_sandbox_package_path(uuid_, true, userId, pkgname); collectManualStatsForSubDirectories(sdkSandboxCePath, &stats); auto sdkSandboxDePath = create_data_misc_sdk_sandbox_package_path(uuid_, false, userId, pkgname); collectManualStatsForSubDirectories(sdkSandboxDePath, &stats); - ATRACE_END(); + atrace_pm_end(); } if (!uuid) { - ATRACE_BEGIN("profiles"); + atrace_pm_begin("profiles"); calculate_tree_size( create_primary_current_profile_package_dir_path(userId, pkgname), &stats.dataSize); calculate_tree_size( create_primary_reference_profile_package_dir_path(pkgname), &stats.codeSize); - ATRACE_END(); + atrace_pm_end(); } - ATRACE_BEGIN("external"); + atrace_pm_begin("external"); auto extPath = create_data_media_package_path(uuid_, userId, "data", pkgname); collectManualStats(extPath, &extStats); auto mediaPath = create_data_media_package_path(uuid_, userId, "media", pkgname); calculate_tree_size(mediaPath, &extStats.dataSize); - ATRACE_END(); + atrace_pm_end(); } if (!uuid) { - ATRACE_BEGIN("dalvik"); + atrace_pm_begin("dalvik"); int32_t sharedGid = multiuser_get_shared_gid(0, appId); if (sharedGid != -1) { calculate_tree_size(create_data_dalvik_cache_path(), &stats.codeSize, sharedGid, -1); } - ATRACE_END(); + atrace_pm_end(); } } @@ -2692,41 +2691,41 @@ binder::Status InstalldNativeService::getUserSize(const std::optional<std::strin } if (flags & FLAG_USE_QUOTA) { - ATRACE_BEGIN("code"); + atrace_pm_begin("code"); calculate_tree_size(create_data_app_path(uuid_), &stats.codeSize, -1, -1, true); - ATRACE_END(); + atrace_pm_end(); - ATRACE_BEGIN("data"); + atrace_pm_begin("data"); auto cePath = create_data_user_ce_path(uuid_, userId); collectManualStatsForUser(cePath, &stats, true); auto dePath = create_data_user_de_path(uuid_, userId); collectManualStatsForUser(dePath, &stats, true); - ATRACE_END(); + atrace_pm_end(); if (!uuid) { - ATRACE_BEGIN("profile"); + atrace_pm_begin("profile"); auto userProfilePath = create_primary_cur_profile_dir_path(userId); calculate_tree_size(userProfilePath, &stats.dataSize, -1, -1, true); auto refProfilePath = create_primary_ref_profile_dir_path(); calculate_tree_size(refProfilePath, &stats.codeSize, -1, -1, true); - ATRACE_END(); + atrace_pm_end(); } - ATRACE_BEGIN("external"); + atrace_pm_begin("external"); auto sizes = getExternalSizesForUserWithQuota(uuidString, userId, appIds); extStats.dataSize += sizes.totalSize; extStats.codeSize += sizes.obbSize; - ATRACE_END(); + atrace_pm_end(); if (!uuid) { - ATRACE_BEGIN("dalvik"); + atrace_pm_begin("dalvik"); calculate_tree_size(create_data_dalvik_cache_path(), &stats.codeSize, -1, -1, true); calculate_tree_size(create_primary_cur_profile_dir_path(userId), &stats.dataSize, -1, -1, true); - ATRACE_END(); + atrace_pm_end(); } - ATRACE_BEGIN("quota"); + atrace_pm_begin("quota"); int64_t dataSize = extStats.dataSize; for (auto appId : appIds) { if (appId >= AID_APP_START) { @@ -2738,54 +2737,54 @@ binder::Status InstalldNativeService::getUserSize(const std::optional<std::strin } } extStats.dataSize = dataSize; - ATRACE_END(); + atrace_pm_end(); } else { - ATRACE_BEGIN("obb"); + atrace_pm_begin("obb"); auto obbPath = create_data_path(uuid_) + "/media/obb"; calculate_tree_size(obbPath, &extStats.codeSize); - ATRACE_END(); + atrace_pm_end(); - ATRACE_BEGIN("code"); + atrace_pm_begin("code"); calculate_tree_size(create_data_app_path(uuid_), &stats.codeSize); - ATRACE_END(); + atrace_pm_end(); - ATRACE_BEGIN("data"); + atrace_pm_begin("data"); auto cePath = create_data_user_ce_path(uuid_, userId); collectManualStatsForUser(cePath, &stats); auto dePath = create_data_user_de_path(uuid_, userId); collectManualStatsForUser(dePath, &stats); - ATRACE_END(); + atrace_pm_end(); - ATRACE_BEGIN("sdksandbox"); + atrace_pm_begin("sdksandbox"); auto sdkSandboxCePath = create_data_misc_sdk_sandbox_path(uuid_, true, userId); collectManualStatsForUser(sdkSandboxCePath, &stats, false, true); auto sdkSandboxDePath = create_data_misc_sdk_sandbox_path(uuid_, false, userId); collectManualStatsForUser(sdkSandboxDePath, &stats, false, true); - ATRACE_END(); + atrace_pm_end(); if (!uuid) { - ATRACE_BEGIN("profile"); + atrace_pm_begin("profile"); auto userProfilePath = create_primary_cur_profile_dir_path(userId); calculate_tree_size(userProfilePath, &stats.dataSize); auto refProfilePath = create_primary_ref_profile_dir_path(); calculate_tree_size(refProfilePath, &stats.codeSize); - ATRACE_END(); + atrace_pm_end(); } - ATRACE_BEGIN("external"); + atrace_pm_begin("external"); auto dataMediaPath = create_data_media_path(uuid_, userId); collectManualExternalStatsForUser(dataMediaPath, &extStats); #if MEASURE_DEBUG LOG(DEBUG) << "Measured external data " << extStats.dataSize << " cache " << extStats.cacheSize; #endif - ATRACE_END(); + atrace_pm_end(); if (!uuid) { - ATRACE_BEGIN("dalvik"); + atrace_pm_begin("dalvik"); calculate_tree_size(create_data_dalvik_cache_path(), &stats.codeSize); calculate_tree_size(create_primary_cur_profile_dir_path(userId), &stats.dataSize); - ATRACE_END(); + atrace_pm_end(); } } @@ -2833,16 +2832,16 @@ binder::Status InstalldNativeService::getExternalSize(const std::optional<std::s } if (flags & FLAG_USE_QUOTA) { - ATRACE_BEGIN("quota"); + atrace_pm_begin("quota"); auto sizes = getExternalSizesForUserWithQuota(uuidString, userId, appIds); totalSize = sizes.totalSize; audioSize = sizes.audioSize; videoSize = sizes.videoSize; imageSize = sizes.imageSize; obbSize = sizes.obbSize; - ATRACE_END(); + atrace_pm_end(); - ATRACE_BEGIN("apps"); + atrace_pm_begin("apps"); struct stats extStats; memset(&extStats, 0, sizeof(extStats)); for (auto appId : appIds) { @@ -2851,9 +2850,9 @@ binder::Status InstalldNativeService::getExternalSize(const std::optional<std::s } } appSize = extStats.dataSize; - ATRACE_END(); + atrace_pm_end(); } else { - ATRACE_BEGIN("manual"); + atrace_pm_begin("manual"); FTS *fts; FTSENT *p; auto path = create_data_media_path(uuid_, userId); @@ -2896,16 +2895,16 @@ binder::Status InstalldNativeService::getExternalSize(const std::optional<std::s } } fts_close(fts); - ATRACE_END(); + atrace_pm_end(); - ATRACE_BEGIN("obb"); + atrace_pm_begin("obb"); auto obbPath = StringPrintf("%s/Android/obb", create_data_media_path(uuid_, userId).c_str()); calculate_tree_size(obbPath, &obbSize); if (!(flags & FLAG_USE_QUOTA)) { totalSize -= obbSize; } - ATRACE_END(); + atrace_pm_end(); } std::vector<int64_t> ret; diff --git a/cmds/installd/SysTrace.cpp b/cmds/installd/SysTrace.cpp new file mode 100644 index 0000000000..fa65c77a2b --- /dev/null +++ b/cmds/installd/SysTrace.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER + +#include "SysTrace.h" +#include <utils/Trace.h> + +namespace android::installd { +void atrace_pm_begin(const char* name) { + ATRACE_BEGIN(name); +} + +void atrace_pm_end() { + ATRACE_END(); +} +} /* namespace android::installd */ diff --git a/cmds/installd/SysTrace.h b/cmds/installd/SysTrace.h new file mode 100644 index 0000000000..18506a9258 --- /dev/null +++ b/cmds/installd/SysTrace.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +namespace android::installd { +void atrace_pm_begin(const char*); +void atrace_pm_end(); +} /* namespace android::installd */ diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp index 5dca468f35..4ff629d3e5 100644 --- a/libs/binder/Android.bp +++ b/libs/binder/Android.bp @@ -89,6 +89,7 @@ cc_defaults { "Stability.cpp", "Status.cpp", "TextOutput.cpp", + "Trace.cpp", "Utils.cpp", ], diff --git a/libs/binder/Trace.cpp b/libs/binder/Trace.cpp new file mode 100644 index 0000000000..1ebfa1a165 --- /dev/null +++ b/libs/binder/Trace.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <binder/Trace.h> +#include <cutils/trace.h> + +namespace android { +namespace binder { + +void atrace_begin(uint64_t tag, const char* name) { + ::atrace_begin(tag, name); +} + +void atrace_end(uint64_t tag) { + ::atrace_end(tag); +} + +} // namespace binder +} // namespace android diff --git a/libs/binder/include/binder/Trace.h b/libs/binder/include/binder/Trace.h new file mode 100644 index 0000000000..99378428ad --- /dev/null +++ b/libs/binder/include/binder/Trace.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <cutils/trace.h> +#include <stdint.h> + +namespace android { +namespace binder { + +// Trampoline functions allowing generated aidls to trace binder transactions without depending on +// libcutils/libutils +void atrace_begin(uint64_t tag, const char* name); +void atrace_end(uint64_t tag); + +class ScopedTrace { +public: + inline ScopedTrace(uint64_t tag, const char* name) : mTag(tag) { atrace_begin(mTag, name); } + + inline ~ScopedTrace() { atrace_end(mTag); } + +private: + uint64_t mTag; +}; + +} // namespace binder +} // namespace android diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp index 41878e3487..18d670ae38 100644 --- a/services/inputflinger/Android.bp +++ b/services/inputflinger/Android.bp @@ -147,6 +147,7 @@ cc_defaults { srcs: [":libinputflinger_base_sources"], shared_libs: [ "libbase", + "libbinder", "libcutils", "libinput", "liblog", |