Commit graph

13 commits

Author SHA1 Message Date
Sandeep Patil
7b20fb677e meminfo: Use getprogname(3) in all tools.
Test: procrank2 -h;librank2 -h;procmem2 -h
Bug: none

Change-Id: Ieccd943b7140a7866694eea047969500bb3bb972
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-30 13:42:20 -08:00
Sandeep Patil
2aeaaebc49 Add librank2
Identical with librank, but written using libmeminfo.

Bug: 114325007
Bug: 111694435
Test: librank2
Test: librank2 -m rx
Test: librank2 -m rx -P /system/lib64
Test: librank2 -u -P /system/lib
Test: librank2 -R -m rx

Change-Id: Ib6ecb601a0b6ecb5b4b75285f772586e05ae388a
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-20 09:01:40 -08:00
Sandeep Patil
2f0b6ebfbe libmeminfo: Add ReadSysMemInfo variants
The new variant is primarily used in framework. See: go/ag/5780400
for usage. Also add tests, benchmarks and fix several issues found in SysMemInfo
class.

New benchmark results are:
--------------------------------------------------------------
Benchmark                       Time           CPU Iterations
--------------------------------------------------------------
BM_ReadMemInfo_old           7726 ns       7696 ns      90201
BM_ReadMemInfo_new           7554 ns       7525 ns      90358
BM_ZramTotal_old             6446 ns       6406 ns     108361
BM_ZramTotal_new             6529 ns       6488 ns     106545
BM_MemInfoWithZram_old      14485 ns      14412 ns      48492
BM_MemInfoWithZram_new      20572 ns      20459 ns      33438
--------------------------------------------------------------

The reason for BM_MemInfoWithZram_new shows worse numbers is because
the new API also tries to find more than 1 zram device (if it exists).
The old implementation hard coded everything to "/sys/block/zram0/"

Test: libmeminfo_test 1
Bug: 114325007
Bug: 111694435

Change-Id: I246d9e9a54986ee9b2542d1eaac79ecf7310b23a
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-11 10:38:33 -08:00
Sandeep Patil
44a4c0fdae Add OWNERS file
Change-Id: Id8421b9d7fb391615232a8a8e75ad8a68e20dfbc
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-07 09:29:03 -08:00
Sandeep Patil
99ed4a0b4e procmem2: Finish implementing all options
In the same time replace iomanipulators with
::android::base::StringPrintf which makes the output much more readable
and the overall program simpler.

Bug: 114325007
Bug: 111694435
Test: procmem 1
Test: procmem -W 1
Test: procmem -u 1
Test: procmem -p 1
Test: procmem -w 1
Test: procmem -w -u 1
Test: procmem -w -p 1

Change-Id: Ibf7ef59b24dfcb851c78a3b2fad672d96a708b98
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-07 09:16:35 -08:00
Sandeep Patil
a14119d069 Add procrank2
Implement procrank using new libmeminfo APIs. procrank2 is functionally
equivalent to procrank except for the part where the old procrank would
print processes under each oomadj level if called with 'procrank -c -o'.

The output format of 'procrank2' is identical to that of 'procrank'.
'procrank2' also gives significant performance boost over 'procrank' but
does cost a more memory as the library is written to 99% use case where
callers almost always want to read the memory usage of hte process.

Bug: 114325007
Bug: 111694435
Test:
     # adb push /google/data/ro/users/ss/sspatil/test-memutils.sh /data/local/tmp/
     # adb push procmem2 /data/local/tmp && adb push procrank2 /data/local/tmp
     # adb root && adb shell
     $ cd /data/local/tmp/
     $ chmod +x test-memutils.sh
     $ ./test-memutils.sh 2>&1 | tee test.log
Test:
  procrank:
    0m00.43s real     0m00.11s user     0m00.32s system
  procrank2:
    0m00.42s real     0m00.05s user     0m00.36s system

Change-Id: I37b71a4625248e333ba01801c0d8d7ef348e4cfa
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-07 09:15:16 -08:00
Sandeep Patil
c6497eb1dc libmeminfo: defer maps reading only when required for procmeminfo
This restores the original behavior. The main reason it should be this
way is to make the class generic for all things memory under
/proc/<pid>/. For example, with the current behavior, a program that
only needs to read /proc/<pid>/smaps_rollup will end up wasting time and
memory by parsing /proc/<pid>/maps when the object is being constructed.
Same goes for a program that only wants to reset the working set.

The 'ProcMemInfo' object still retains the property that it can only be
used once to read maps and the object must be destroyed + recreated to
update the stats.

Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1
Test:
 # adb push /google/data/ro/users/ss/sspatil/test-memutils.sh /data/local/tmp/
 # adb push procmem2 /data/local/tmp && adb push procrank2 /data/local/tmp
 # adb root && adb shell
 $ cd /data/local/tmp/
 $ chmod +x test-memutils.sh
 $ ./test-memutils.sh 2>&1 | tee test.log

Change-Id: I856d3b78a0088cff02cbd010b29ffbe0e35f5ee2
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-05 09:31:10 -08:00
Sandeep Patil
f129199350 libmeminfo: Add support to reset workingset without procmeminfo objects
Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1

Change-Id: I816809cda13983e47294a956347a27085397cbcf
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-05 09:13:20 -08:00
Sandeep Patil
549feab631 libmeminfo: Add support to fiter accounting based on page flags
Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=ValidateProcMemInfoFlags.*

Change-Id: Ifa7006de78dd909b5b4db282a8c9931ebf97a68a
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-04 15:59:42 -08:00
Sandeep Patil
70fa72dd01 libmeminfo: Add support to read zram memory consumption
Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=SysMemInfoParse.TestZramTotal
Benchmark: libmeminfo_benchmark --benchmark_filter=BM_.*ZramTotal
Benchmark Result on Blueline:
-----------------------------------------------------------
Benchmark                    Time           CPU Iterations
-----------------------------------------------------------
BM_OldReadZramTotal       3857 ns       3839 ns     134096
BM_NewReadZramTotal       4461 ns       4440 ns     157341

Change-Id: I5220fa17b101981ef859179960fe78fe68e84852
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-04 15:59:39 -08:00
Sandeep Patil
2259fdf7df libmeminfo: Add support for counting swap pages
Adds procmeminfo API to get the vector of swap_offsets
if SWAP is enabled on the device.

Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1
Change-Id: If0b52d042749a5bcb2c87aa2cb1595190d4769b1
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-04 14:02:28 -08:00
Mark Salyzyn
9f1cf25332 switch to using android-base/file.h instead of android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I4f7ad84743e974b4b4d1d7256088f6c8b749a237
2018-11-14 09:35:34 -08:00
Sandeep Patil
54d8721374 libmeminfo: Add libmeminfo to gather global and per-process memory stats
The library is expected to be a unified place for all components to read
both global and per-process memory accounting form kernel including
getting the working set. This change adds the PageInfo, MemInfo and
ProcMemInfo classes and verifies the implementation against libpagemap
for correctness.

Adds a procmem2 tool show the usage.

TODO: Plumbing in os_debug, add vmastats, zoneinfo etc parsing.

Test: libmeminfo_test 1
Test: procmem2 1
Test: procmem2 -h -W 1
Test: procmem2 -h -w 1
Test: libmeminfo_benchmark
Bug: 111694435
Bug: 114325007

Change-Id: I280440b1dc26a498170686d10fcf63f953a0dcbd
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-11-05 10:42:46 -08:00