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

Commit 1315ca7b authored by Kelvin Zhang's avatar Kelvin Zhang
Browse files

Log lock time if it takes too long

Test: th
Bug: 352332753
Change-Id: Ie7397f7027a597cebb33206a6df845918bc3dab5
parent c36f4f05
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <sys/unistd.h>

#include <chrono>
#include <filesystem>
#include <optional>
#include <thread>
@@ -2892,6 +2893,7 @@ bool SnapshotManager::UnmapAllSnapshots(LockedFile* lock) {

auto SnapshotManager::OpenFile(const std::string& file,
                               int lock_flags) -> std::unique_ptr<LockedFile> {
    const auto start = std::chrono::system_clock::now();
    unique_fd fd(open(file.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
    if (fd < 0) {
        PLOG(ERROR) << "Open failed: " << file;
@@ -2904,6 +2906,11 @@ auto SnapshotManager::OpenFile(const std::string& file,
    // For simplicity, we want to CHECK that lock_mode == LOCK_EX, in some
    // calls, so strip extra flags.
    int lock_mode = lock_flags & (LOCK_EX | LOCK_SH);
    const auto end = std::chrono::system_clock::now();
    const auto duration_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
    if (duration_ms >= 1000ms) {
        LOG(INFO) << "Taking lock on " << file << " took " << duration_ms.count() << "ms";
    }
    return std::make_unique<LockedFile>(file, std::move(fd), lock_mode);
}