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

Commit 6952b999 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add more tracing to pinpoint the perf regressions." am: 97d06963

parents 604a7bc6 97d06963
Loading
Loading
Loading
Loading
+24 −5
Original line number Original line 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,
static int restorecon_app_data_lazy(const std::string& path, const std::string& seInfo, uid_t uid,
        bool existing) {
        bool existing) {
    ScopedTrace tracer("restorecon-lazy");
    int res = 0;
    int res = 0;
    char* before = nullptr;
    char* before = nullptr;
    char* after = nullptr;
    char* after = nullptr;
    if (!existing) {
    if (!existing) {
        ScopedTrace tracer("new-path");
        if (selinux_android_restorecon_pkgdir(path.c_str(), seInfo.c_str(), uid,
        if (selinux_android_restorecon_pkgdir(path.c_str(), seInfo.c_str(), uid,
                SELINUX_ANDROID_RESTORECON_RECURSE) < 0) {
                SELINUX_ANDROID_RESTORECON_RECURSE) < 0) {
            PLOG(ERROR) << "Failed recursive restorecon for " << path;
            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
    // If the initial top-level restorecon above changed the label, then go
    // back and restorecon everything recursively
    // back and restorecon everything recursively
    if (strcmp(before, after)) {
    if (strcmp(before, after)) {
        ScopedTrace tracer("label-change");
        if (existing) {
        if (existing) {
            LOG(DEBUG) << "Detected label change from " << before << " to " << after << " at "
            LOG(DEBUG) << "Detected label change from " << before << " to " << after << " at "
                    << path << "; running recursive restorecon";
                    << 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,
static int prepare_app_dir(const std::string& path, mode_t target_mode, uid_t uid, gid_t gid,
                           long project_id) {
                           long project_id) {
    {
        ScopedTrace tracer("prepare-dir");
        if (fs_prepare_dir_strict(path.c_str(), target_mode, uid, gid) != 0) {
        if (fs_prepare_dir_strict(path.c_str(), target_mode, uid, gid) != 0) {
            PLOG(ERROR) << "Failed to prepare " << path;
            PLOG(ERROR) << "Failed to prepare " << path;
            return -1;
            return -1;
        }
        }
    }
    if (internal_storage_has_project_id()) {
    if (internal_storage_has_project_id()) {
        ScopedTrace tracer("set-quota");
        return set_quota_project_id(path, project_id, true);
        return set_quota_project_id(path, project_id, true);
    }
    }
    return 0;
    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,
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) {
                                 uid_t uid, gid_t gid, long project_id) {
    auto path = StringPrintf("%s/%s", parent.c_str(), name);
    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()) {
    if (ret == 0 && internal_storage_has_project_id()) {
        ScopedTrace tracer("set-quota-cache-dir");
        return set_quota_project_id(path, project_id, true);
        return set_quota_project_id(path, project_id, true);
    }
    }
    return ret;
    return ret;
}
}


static bool prepare_app_profile_dir(const std::string& packageName, int32_t appId, int32_t userId) {
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);
    int32_t uid = multiuser_get_uid(userId, appId);
    int shared_app_gid = multiuser_get_shared_gid(userId, appId);
    int shared_app_gid = multiuser_get_shared_gid(userId, appId);
    if (shared_app_gid == -1) {
    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,
                                        int32_t previousUid, int32_t cacheGid,
                                        const std::string& seInfo, mode_t targetMode,
                                        const std::string& seInfo, mode_t targetMode,
                                        long projectIdApp, long projectIdCache) {
                                        long projectIdApp, long projectIdCache) {
    ScopedTrace tracer("create-dirs");
    struct stat st{};
    struct stat st{};
    bool parent_dir_exists = (stat(path.c_str(), &st) == 0);
    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);
    long projectIdCache = get_project_id(uid, PROJECT_ID_APP_CACHE_START);


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


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


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


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

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


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

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