• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <sys/types.h>
20 
21 #include <cstdint>
22 #include <functional>
23 #include <ostream>
24 #include <string>
25 #include <vector>
26 
27 #include <meminfo/meminfo.h>
28 #include <meminfo/procmeminfo.h>
29 
30 namespace android {
31 namespace smapinfo {
32 
33 class ProcessRecord final {
34   public:
35     ProcessRecord(pid_t pid, bool get_wss, uint64_t pgflags, uint64_t pgflags_mask,
36                   bool get_cmdline, bool get_oomadj, std::ostream& err);
37 
38     bool valid() const;
39     void CalculateSwap(const std::vector<uint16_t>& swap_offset_array,
40                        float zram_compression_ratio);
41 
42     // Getters
pid()43     pid_t pid() const { return pid_; }
cmdline()44     const std::string& cmdline() const { return cmdline_; }
oomadj()45     int32_t oomadj() const { return oomadj_; }
proportional_swap()46     uint64_t proportional_swap() const { return proportional_swap_; }
unique_swap()47     uint64_t unique_swap() const { return unique_swap_; }
zswap()48     uint64_t zswap() const { return zswap_; }
49 
50     // Wrappers to ProcMemInfo
SwapOffsets()51     const std::vector<uint64_t>& SwapOffsets() const { return swap_offsets_; }
52     // show_wss may be used to return differentiated output in the future.
Usage(bool show_wss)53     const ::android::meminfo::MemUsage& Usage([[maybe_unused]] bool show_wss) const {
54         return usage_or_wss_;
55     }
Smaps()56     const std::vector<::android::meminfo::Vma>& Smaps() { return procmem_.Smaps(); }
ForEachExistingVma(const::android::meminfo::VmaCallback & callback)57     bool ForEachExistingVma(const ::android::meminfo::VmaCallback& callback) {
58         return procmem_.ForEachExistingVma(callback);
59     }
60 
61   private:
62     ::android::meminfo::ProcMemInfo procmem_;
63     pid_t pid_;
64     std::string cmdline_;
65     int32_t oomadj_;
66     uint64_t proportional_swap_;
67     uint64_t unique_swap_;
68     uint64_t zswap_;
69     ::android::meminfo::MemUsage usage_or_wss_;
70     std::vector<uint64_t> swap_offsets_;
71 };
72 
73 }  // namespace smapinfo
74 }  // namespace android
75