meminfo: Remove unnecessary working set stats
The Vma and ProcMemInfo objects do not need separate stats objects for storing working set. The Vma either has working set or memory usage information and never both. Bug: 111694435 Test: libmeminfo_test 1 Change-Id: I2df05f7e750bbba4325474633e705d6d68dd2ccb Merged-In: I2df05f7e750bbba4325474633e705d6d68dd2ccb Signed-off-by: Sandeep Patil <sspatil@google.com>
This commit is contained in:
parent
002f02ea49
commit
56c414e872
5 changed files with 22 additions and 43 deletions
|
@ -72,15 +72,10 @@ struct Vma {
|
|||
: start(s), end(e), offset(off), flags(f), name(n) {}
|
||||
~Vma() = default;
|
||||
|
||||
void clear() {
|
||||
memset(&usage, 0, sizeof(usage));
|
||||
memset(&wss, 0, sizeof(wss));
|
||||
}
|
||||
void clear() { memset(&usage, 0, sizeof(usage)); }
|
||||
|
||||
// Memory usage of this mapping.
|
||||
MemUsage usage;
|
||||
// Working set within this mapping.
|
||||
MemUsage wss;
|
||||
};
|
||||
|
||||
} // namespace meminfo
|
||||
|
|
|
@ -82,7 +82,6 @@ class ProcMemInfo final {
|
|||
std::vector<Vma> maps_;
|
||||
|
||||
MemUsage usage_;
|
||||
MemUsage wss_;
|
||||
std::vector<uint16_t> swap_offsets_;
|
||||
};
|
||||
|
||||
|
|
|
@ -157,14 +157,14 @@ const MemUsage& ProcMemInfo::Wss() {
|
|||
if (!get_wss_) {
|
||||
LOG(WARNING) << "Trying to read process working set for " << pid_
|
||||
<< " using invalid object";
|
||||
return wss_;
|
||||
return usage_;
|
||||
}
|
||||
|
||||
if (maps_.empty() && !ReadMaps(get_wss_)) {
|
||||
LOG(ERROR) << "Failed to get working set for Process " << pid_;
|
||||
}
|
||||
|
||||
return wss_;
|
||||
return usage_;
|
||||
}
|
||||
|
||||
bool ProcMemInfo::ForEachVma(const VmaCallback& callback) {
|
||||
|
@ -228,11 +228,7 @@ bool ProcMemInfo::ReadMaps(bool get_wss) {
|
|||
maps_.clear();
|
||||
return false;
|
||||
}
|
||||
if (get_wss) {
|
||||
add_mem_usage(&wss_, vma.wss);
|
||||
} else {
|
||||
add_mem_usage(&usage_, vma.usage);
|
||||
}
|
||||
add_mem_usage(&usage_, vma.usage);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -300,31 +296,20 @@ bool ProcMemInfo::ReadVmaStats(int pagemap_fd, Vma& vma, bool get_wss) {
|
|||
// This effectively makes vss = rss for the working set is requested.
|
||||
// The libpagemap implementation returns vss > rss for
|
||||
// working set, which doesn't make sense.
|
||||
vma.wss.vss += pagesz;
|
||||
vma.wss.rss += pagesz;
|
||||
vma.wss.uss += is_private ? pagesz : 0;
|
||||
vma.wss.pss += pagesz / pg_counts[i];
|
||||
if (is_private) {
|
||||
vma.wss.private_dirty += is_dirty ? pagesz : 0;
|
||||
vma.wss.private_clean += is_dirty ? 0 : pagesz;
|
||||
} else {
|
||||
vma.wss.shared_dirty += is_dirty ? pagesz : 0;
|
||||
vma.wss.shared_clean += is_dirty ? 0 : pagesz;
|
||||
}
|
||||
vma.usage.vss += pagesz;
|
||||
}
|
||||
|
||||
vma.usage.rss += pagesz;
|
||||
vma.usage.uss += is_private ? pagesz : 0;
|
||||
vma.usage.pss += pagesz / pg_counts[i];
|
||||
if (is_private) {
|
||||
vma.usage.private_dirty += is_dirty ? pagesz : 0;
|
||||
vma.usage.private_clean += is_dirty ? 0 : pagesz;
|
||||
} else {
|
||||
vma.usage.rss += pagesz;
|
||||
vma.usage.uss += is_private ? pagesz : 0;
|
||||
vma.usage.pss += pagesz / pg_counts[i];
|
||||
if (is_private) {
|
||||
vma.usage.private_dirty += is_dirty ? pagesz : 0;
|
||||
vma.usage.private_clean += is_dirty ? 0 : pagesz;
|
||||
} else {
|
||||
vma.usage.shared_dirty += is_dirty ? pagesz : 0;
|
||||
vma.usage.shared_clean += is_dirty ? 0 : pagesz;
|
||||
}
|
||||
vma.usage.shared_dirty += is_dirty ? pagesz : 0;
|
||||
vma.usage.shared_clean += is_dirty ? 0 : pagesz;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ static int show(const MemUsage& proc_stats, const std::vector<Vma>& maps) {
|
|||
std::stringstream ss;
|
||||
print_header(ss);
|
||||
for (auto& vma : maps) {
|
||||
const MemUsage& vma_stats = show_wss ? vma.wss : vma.usage;
|
||||
const MemUsage& vma_stats = vma.usage;
|
||||
if (hide_zeroes && vma_stats.rss == 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -116,14 +116,14 @@ static int show(const MemUsage& proc_stats, const std::vector<Vma>& maps) {
|
|||
int main(int argc, char* argv[]) {
|
||||
int opt;
|
||||
auto pss_sort = [](const Vma& a, const Vma& b) {
|
||||
uint64_t pss_a = show_wss ? a.wss.pss : a.usage.pss;
|
||||
uint64_t pss_b = show_wss ? b.wss.pss : b.usage.pss;
|
||||
uint64_t pss_a = a.usage.pss;
|
||||
uint64_t pss_b = b.usage.pss;
|
||||
return pss_a > pss_b;
|
||||
};
|
||||
|
||||
auto uss_sort = [](const Vma& a, const Vma& b) {
|
||||
uint64_t uss_a = show_wss ? a.wss.uss : a.usage.uss;
|
||||
uint64_t uss_b = show_wss ? b.wss.uss : b.usage.uss;
|
||||
uint64_t uss_a = a.usage.uss;
|
||||
uint64_t uss_b = b.usage.uss;
|
||||
return uss_a > uss_b;
|
||||
};
|
||||
|
||||
|
@ -182,7 +182,7 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
|
||||
ProcMemInfo proc(pid, show_wss);
|
||||
const MemUsage& proc_stats = show_wss ? proc.Wss() : proc.Usage();
|
||||
const MemUsage& proc_stats = proc.Usage();
|
||||
std::vector<Vma> maps(proc.Maps());
|
||||
if (sort_func != nullptr) {
|
||||
std::sort(maps.begin(), maps.end(), sort_func);
|
||||
|
|
|
@ -465,7 +465,7 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
|
||||
// Skip processes with no memory mappings
|
||||
uint64_t vss = show_wss ? proc.Wss().vss : proc.Usage().vss;
|
||||
uint64_t vss = proc.Usage().vss;
|
||||
if (vss == 0) return true;
|
||||
|
||||
// collect swap_offset counts from all processes in 1st pass
|
||||
|
|
Loading…
Reference in a new issue