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

Commit e43650d2 authored by Wei Wang's avatar Wei Wang Committed by Android (Google) Code Review
Browse files

Merge "dumpstate: Kill vendor dumpstate HAL and grab partial dump in timeout" into pi-dev

parents 2c327ac2 587eac98
Loading
Loading
Loading
Loading
+62 −52
Original line number Diff line number Diff line
@@ -1237,7 +1237,6 @@ static void RunDumpsysNormal() {
}

static void DumpHals() {
    using android::sp;
    using android::hidl::manager::V1_0::IServiceManager;
    using android::hardware::defaultServiceManager;

@@ -1582,15 +1581,10 @@ void Dumpstate::DumpstateBoard() {
            paths[i])));
    }

    // Given that bugreport is required to diagnose failures, it's better to
    // drop the result of IDumpstateDevice than to block the rest of bugreport
    // for an arbitrary amount of time.
    std::packaged_task<std::unique_ptr<ssize_t[]>()>
        dumpstate_task([paths]() -> std::unique_ptr<ssize_t[]> {
            ::android::sp<IDumpstateDevice> dumpstate_device(IDumpstateDevice::getService());
    sp<IDumpstateDevice> dumpstate_device(IDumpstateDevice::getService());
    if (dumpstate_device == nullptr) {
        MYLOGE("No IDumpstateDevice implementation\n");
                return nullptr;
        return;
    }

    using ScopedNativeHandle =
@@ -1602,7 +1596,7 @@ void Dumpstate::DumpstateBoard() {
                              });
    if (handle == nullptr) {
        MYLOGE("Could not create native_handle\n");
                return nullptr;
        return;
    }

    for (size_t i = 0; i < paths.size(); i++) {
@@ -1613,16 +1607,44 @@ void Dumpstate::DumpstateBoard() {
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)));
        if (fd < 0) {
            MYLOGE("Could not open file %s: %s\n", paths[i].c_str(), strerror(errno));
                    return nullptr;
            return;
        }
        handle.get()->data[i] = fd.release();
    }

    // Given that bugreport is required to diagnose failures, it's better to
    // set an arbitrary amount of timeout for IDumpstateDevice than to block the
    // rest of bugreport. In the timeout case, we will kill dumpstate board HAL
    // and grab whatever dumped
    std::packaged_task<bool()>
            dumpstate_task([paths, dumpstate_device, &handle]() -> bool {
            android::hardware::Return<void> status = dumpstate_device->dumpstateBoard(handle.get());
            if (!status.isOk()) {
                MYLOGE("dumpstateBoard failed: %s\n", status.description().c_str());
                return nullptr;
                return false;
            }
            return true;
        });

    auto result = dumpstate_task.get_future();
    std::thread(std::move(dumpstate_task)).detach();

    constexpr size_t timeout_sec = 30;
    if (result.wait_for(std::chrono::seconds(timeout_sec)) != std::future_status::ready) {
        MYLOGE("dumpstateBoard timed out after %zus, killing dumpstate vendor HAL\n", timeout_sec);
        if (!android::base::SetProperty("ctl.interface_restart",
                                        android::base::StringPrintf("%s/default",
                                                                    IDumpstateDevice::descriptor))) {
            MYLOGE("Couldn't restart dumpstate HAL\n");
        }
    }
    // Wait some time for init to kill dumpstate vendor HAL
    constexpr size_t killing_timeout_sec = 10;
    if (result.wait_for(std::chrono::seconds(killing_timeout_sec)) != std::future_status::ready) {
        MYLOGE("killing dumpstateBoard timed out after %zus, continue and "
               "there might be racing in content\n", killing_timeout_sec);
    }

    auto file_sizes = std::make_unique<ssize_t[]>(paths.size());
    for (size_t i = 0; i < paths.size(); i++) {
        struct stat s;
@@ -1634,18 +1656,6 @@ void Dumpstate::DumpstateBoard() {
        }
        file_sizes[i] = s.st_size;
    }
            return file_sizes;
        });
    auto result = dumpstate_task.get_future();
    std::thread(std::move(dumpstate_task)).detach();
    if (result.wait_for(30s) != std::future_status::ready) {
        MYLOGE("dumpstateBoard timed out after 30s\n");
        return;
    }
    std::unique_ptr<ssize_t[]> file_sizes = result.get();
    if (file_sizes == nullptr) {
        return;
    }

    for (size_t i = 0; i < paths.size(); i++) {
        if (file_sizes[i] == -1) {