Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a203d710 authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

Add more tracing to pinpoint the perf regressions.

Bug: 275468553
Test: presubmit
Change-Id: I26ff01846181f9750cd9e1963eb77c960fe96016
parent 8c49cc5e
Loading
Loading
Loading
Loading
+24 −5
Original line number Diff line number Diff line
@@ -416,10 +416,12 @@ status_t InstalldNativeService::dump(int fd, const Vector<String16>& /* args */)
 */
static int restorecon_app_data_lazy(const std::string& path, const std::string& seInfo, uid_t uid,
        bool existing) {
    ScopedTrace tracer("restorecon-lazy");
    int res = 0;
    char* before = nullptr;
    char* after = nullptr;
    if (!existing) {
        ScopedTrace tracer("new-path");
        if (selinux_android_restorecon_pkgdir(path.c_str(), seInfo.c_str(), uid,
                SELINUX_ANDROID_RESTORECON_RECURSE) < 0) {
            PLOG(ERROR) << "Failed recursive restorecon for " << path;
@@ -446,6 +448,7 @@ static int restorecon_app_data_lazy(const std::string& path, const std::string&
    // If the initial top-level restorecon above changed the label, then go
    // back and restorecon everything recursively
    if (strcmp(before, after)) {
        ScopedTrace tracer("label-change");
        if (existing) {
            LOG(DEBUG) << "Detected label change from " << before << " to " << after << " at "
                    << path << "; running recursive restorecon";
@@ -480,11 +483,15 @@ static bool internal_storage_has_project_id() {

static int prepare_app_dir(const std::string& path, mode_t target_mode, uid_t uid, gid_t gid,
                           long project_id) {
    {
        ScopedTrace tracer("prepare-dir");
        if (fs_prepare_dir_strict(path.c_str(), target_mode, uid, gid) != 0) {
            PLOG(ERROR) << "Failed to prepare " << path;
            return -1;
        }
    }
    if (internal_storage_has_project_id()) {
        ScopedTrace tracer("set-quota");
        return set_quota_project_id(path, project_id, true);
    }
    return 0;
@@ -493,14 +500,20 @@ static int prepare_app_dir(const std::string& path, mode_t target_mode, uid_t ui
static int prepare_app_cache_dir(const std::string& parent, const char* name, mode_t target_mode,
                                 uid_t uid, gid_t gid, long project_id) {
    auto path = StringPrintf("%s/%s", parent.c_str(), name);
    int ret = prepare_app_cache_dir(parent, name, target_mode, uid, gid);
    int ret;
    {
        ScopedTrace tracer("prepare-cache-dir");
        ret = prepare_app_cache_dir(parent, name, target_mode, uid, gid);
    }
    if (ret == 0 && internal_storage_has_project_id()) {
        ScopedTrace tracer("set-quota-cache-dir");
        return set_quota_project_id(path, project_id, true);
    }
    return ret;
}

static bool prepare_app_profile_dir(const std::string& packageName, int32_t appId, int32_t userId) {
    ScopedTrace tracer("prepare-app-profile");
    int32_t uid = multiuser_get_uid(userId, appId);
    int shared_app_gid = multiuser_get_shared_gid(userId, appId);
    if (shared_app_gid == -1) {
@@ -633,6 +646,7 @@ static binder::Status createAppDataDirs(const std::string& path, int32_t uid, in
                                        int32_t previousUid, int32_t cacheGid,
                                        const std::string& seInfo, mode_t targetMode,
                                        long projectIdApp, long projectIdCache) {
    ScopedTrace tracer("create-dirs");
    struct stat st{};
    bool parent_dir_exists = (stat(path.c_str(), &st) == 0);

@@ -709,6 +723,7 @@ binder::Status InstalldNativeService::createAppDataLocked(
    long projectIdCache = get_project_id(uid, PROJECT_ID_APP_CACHE_START);

    if (flags & FLAG_STORAGE_CE) {
        ScopedTrace tracer("ce");
        auto path = create_data_user_ce_package_path(uuid_, userId, pkgname);

        auto status = createAppDataDirs(path, uid, uid, previousUid, cacheGid, seInfo, targetMode,
@@ -735,6 +750,7 @@ binder::Status InstalldNativeService::createAppDataLocked(
        }
    }
    if (flags & FLAG_STORAGE_DE) {
        ScopedTrace tracer("de");
        auto path = create_data_user_de_package_path(uuid_, userId, pkgname);

        auto status = createAppDataDirs(path, uid, uid, previousUid, cacheGid, seInfo, targetMode,
@@ -752,13 +768,14 @@ binder::Status InstalldNativeService::createAppDataLocked(
    }

    if (flags & FLAG_STORAGE_SDK) {
        ScopedTrace tracer("sdk");
        // Safe to ignore status since we can retry creating this by calling reconcileSdkData
        auto ignore = createSdkSandboxDataPackageDirectory(uuid, packageName, userId, appId, flags);
        if (!ignore.isOk()) {
            PLOG(WARNING) << "Failed to create sdk data package directory for " << packageName;
        }

    } else {
        ScopedTrace tracer("destroy-sdk");
        // Package does not need sdk storage. Remove it.
        destroySdkSandboxDataPackageDirectory(uuid, packageName, userId, flags);
    }
@@ -1850,6 +1867,8 @@ binder::Status InstalldNativeService::createUserData(const std::optional<std::st
    CHECK_ARGUMENT_UUID(uuid);
    LOCK_USER();

    ScopedTrace tracer("create-user-data");

    const char* uuid_ = uuid ? uuid->c_str() : nullptr;
    if (flags & FLAG_STORAGE_DE) {
        if (uuid_ == nullptr) {
+12 −0
Original line number Diff line number Diff line
@@ -19,4 +19,16 @@
namespace android::installd {
void atrace_pm_begin(const char*);
void atrace_pm_end();

class ScopedTrace {
public:
    explicit ScopedTrace(const char* label) { atrace_pm_begin(label); }
    ~ScopedTrace() { atrace_pm_end(); }

private:
    ScopedTrace(const ScopedTrace&) = delete;
    ScopedTrace& operator=(const ScopedTrace&) = delete;
    ScopedTrace(ScopedTrace&&) = delete;
    ScopedTrace& operator=(ScopedTrace&&) = delete;
};
} /* namespace android::installd */