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

Commit 10401090 authored by Sandeep Patil's avatar Sandeep Patil Committed by Android (Google) Code Review
Browse files

Merge "procrank: do not keep process maps around" into qt-dev

parents 37e2653b 151a06c2
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ struct ProcessRecord {
  public:
    ProcessRecord(pid_t pid, bool get_wss = false, uint64_t pgflags = 0, uint64_t pgflags_mask = 0)
        : pid_(-1),
          procmem_(nullptr),
          oomadj_(OOM_SCORE_ADJ_MAX + 1),
          cmdline_(""),
          proportional_swap_(0),
@@ -79,15 +78,15 @@ struct ProcessRecord {
        // The .c_str() assignment below then takes care of trimming the cmdline at the first
        // 0x00. This is how original procrank worked (luckily)
        cmdline_.resize(strlen(cmdline_.c_str()));
        procmem_ = std::move(procmem);
        usage_or_wss_ = get_wss ? procmem->Wss() : procmem->Usage();
        swap_offsets_ = procmem->SwapOffsets();
        pid_ = pid;
    }

    bool valid() const { return pid_ != -1; }

    void CalculateSwap(const uint16_t* swap_offset_array, float zram_compression_ratio) {
        const std::vector<uint16_t>& swp_offs = procmem_->SwapOffsets();
        for (auto& off : swp_offs) {
        for (auto& off : swap_offsets_) {
            proportional_swap_ += getpagesize() / swap_offset_array[off];
            unique_swap_ += swap_offset_array[off] == 1 ? getpagesize() : 0;
            zswap_ = proportional_swap_ * zram_compression_ratio;
@@ -103,18 +102,19 @@ struct ProcessRecord {
    uint64_t zswap() const { return zswap_; }

    // Wrappers to ProcMemInfo
    const std::vector<uint16_t>& SwapOffsets() const { return procmem_->SwapOffsets(); }
    const MemUsage& Usage() const { return procmem_->Usage(); }
    const MemUsage& Wss() const { return procmem_->Wss(); }
    const std::vector<uint16_t>& SwapOffsets() const { return swap_offsets_; }
    const MemUsage& Usage() const { return usage_or_wss_; }
    const MemUsage& Wss() const { return usage_or_wss_; }

  private:
    pid_t pid_;
    std::unique_ptr<ProcMemInfo> procmem_;
    int32_t oomadj_;
    std::string cmdline_;
    uint64_t proportional_swap_;
    uint64_t unique_swap_;
    uint64_t zswap_;
    MemUsage usage_or_wss_;
    std::vector<uint16_t> swap_offsets_;
};

// Show working set instead of memory consumption
@@ -171,7 +171,7 @@ static bool read_all_pids(std::vector<pid_t>* pids, std::function<bool(pid_t pid
    while ((dir = readdir(procdir.get()))) {
        if (!::android::base::ParseInt(dir->d_name, &pid)) continue;
        if (!for_each_pid(pid)) return false;
        pids->push_back(pid);
        pids->emplace_back(pid);
    }

    return true;
@@ -471,7 +471,7 @@ int main(int argc, char* argv[]) {
        }

        // Skip processes with no memory mappings
        uint64_t vss = proc.Usage().vss;
        uint64_t vss = show_wss ? proc.Wss().vss : proc.Usage().vss;
        if (vss == 0) return true;

        // collect swap_offset counts from all processes in 1st pass
@@ -481,7 +481,7 @@ int main(int argc, char* argv[]) {
            return false;
        }

        procs.push_back(std::move(proc));
        procs.emplace_back(std::move(proc));
        return true;
    };