Commit graph

70 commits

Author SHA1 Message Date
Christopher Ferris
d1cb35bdef Merge "Add method to get usage stats for a single map." 2019-10-11 18:16:01 +00:00
Christopher Ferris
23f2a0b166 Add method to get usage stats for a single map.
The new scudo allocator creates a huge map in 64 bit address space. Some
tests would get the usage stats of all maps, but only really cared about
a small set of maps. In this case, provide a method to only get the usage
stats for the maps you care about.

Test: Unit tests pass.
Change-Id: Ie845e47a8c789a57bf689c9f0e5878a921640e30
2019-10-10 15:10:27 -07:00
Suren Baghdasaryan
e8f1468b14 libmeminfo: Report VMA flags in showmap report
Add VMA flags into showmap report so that we can distinguish different
sections of an executable or a library.

Bug: 138148041
Test: showmap -v <PID>
Change-Id: Ic1a13accbea447548c75a0c54d750280e40c6de8
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-10-09 16:18:18 -07:00
Suren Baghdasaryan
17e920dbe4 Merge "libmeminfo: Report VMA flags in procmem report" 2019-09-30 17:25:34 +00:00
nelsonli
745a306f71 [vts-core] Add vts_core_meminfo_test to vts-core
Add vts_core_meminfo_test to vts-core suite and transfer to test it
by using base GTest.

Bug: 132702215
Test: atest vts_core_meminfo_test
Change-Id: Ia7924179cde0b79a6787b3533259ea8e90594585
2019-09-27 09:43:51 +08:00
Suren Baghdasaryan
fc867c9cb1 libmeminfo: Report VMA flags in procmem report
Add VMA flags into procmem report so that we can distinguish different
sections of an executable or a library.

Bug: 138148041
Test: procmem -h <PID>
Change-Id: I062464aa1f1c508bcc8ef05a6d9cfad9a4318d95
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-09-26 14:51:40 -07:00
Christopher Ferris
5db009286d Add support for scudo native allocator.
Bug: 137795072

Test: All unit tests pass when using scudo or jemalloc.
Change-Id: I20c71811d9e43663c495a1e51988acfef9fc8584
2019-09-18 16:41:25 -07:00
Christopher Ferris
7fdc80f6ec Fix incorrect closing of fds.
Test: Ran unit tests without fdsan aborts.
Change-Id: I4a060739c61e93364b9aabe3ae1d6cbc3639d310
2019-08-09 14:03:30 -07:00
Tri Vo
ad986341a4 VtsKernelMemInfoTest: only enforce on Q+ launching devices
Bug: 135553509
Test: VtsKernelMemInfoTest
Change-Id: I299d24623c363238e46229f8d09865e3afd6f9c0
2019-07-23 17:06:54 -07:00
Colin Cross
3defd5237f Fix darwin build
Disable host libmeminfo and showmap when building on darwin.

Test: m on darwin
Change-Id: Ie9342eff8d9e33c706edbb068d4ec405b480e599
2019-07-18 16:25:15 -07:00
Mathieu Chartier
c0c28faa97 Re-make showmap host supported
Also fix bugs that made it not compile on host. Motivation is to be
able to analyze smaps files easily on the host.

Test: showmap -f maps.txt
Bug: 137034556

Change-Id: I7b8ca1237ce1ec17d02cd5217c73b62ee978cb05
2019-07-17 12:28:27 -07:00
Christopher Ferris
504d2cce64 Optimize code that only uses PageMap call.
Some code only wants to use PageMap to determine whether pages are
mapped in to memory. Modify the code to optimize this path.

Changes:
- Add a function that doesn't read all of usage stats data for every
  map. This operation is extremely expensive, and some code doesn't
  care about it.
- Optimize the PageMap call to do a single read instead of a single
  read per page.
- Add unit tests for these changes.

Bug: 136245508

Test: Ran new unit tests.
Test: Ran procrank and verified data looks good.
Test: Ran DexDiag art tests.
Change-Id: I37d03f2584551d26cb20be3abacdb958111d4eca
2019-07-12 16:28:09 -07:00
Christopher Ferris
b0c5cd27a1 Merge "Fix error printing code." 2019-07-08 21:46:44 +00:00
Christopher Ferris
d943301990 Fix error printing code.
Test: Induced error and verified the errors print properly in logcat.
Change-Id: Ie0e6e71671a8a3e26b4632f93bb2af089a20e2e0
2019-06-28 18:11:12 -07:00
Sandeep Patil
725e0a048b dmabuf_dump: Change the default view to per-process stats
Add '-a' commandline option to show the old complete table that shows
dmabuf x process grid.

Bug: 135668399
Test: dmabuf_dump
Test: dmabuf_dump -h
Test: dmabuf_dump -a
Test: dmabuf_dump -a 123
Test: dmabuf_dump 123 456
Test: dmabuf_dump <pid>

Change-Id: If228c97baa375c515d94baf3b5be674cfcc09919
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-06-28 14:05:42 +08:00
Sandeep Patil
3dc456ee57 dmabuf_dump: Fix aosp_x86-eng builds
Test: lunch aosp_x86-eng; mma -j
Test: lunch aosp_blueline-eng; mma -j
Bug: 136136199

Change-Id: Ie6f90c967b356a55db09acee7b3596661e001166
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-06-27 01:21:11 -07:00
Christopher Ferris
037d025aa5 Merge "Cache only a small portion of page map data." 2019-06-27 06:46:54 +00:00
Sandeep Patil
6347749ae9 dmabuf_dump: Make output more readable and debug friendly
- Get rid of the PSS number that didn't make sense.
- Fix double counting in per-process size when buffers had file
  descriptors and mmap'ed
- Make the output much more readable
- Print totals where they make sense.
- Dont print per-process fd and map refs separately, total ref count per
  process is sufficient.

Bug: 135668399
Test: dmabuf_dump (on AOSP blueline)

Change-Id: I10dc0a332d49110dd68f0eaa94a326679361deea
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-06-26 18:50:45 -07:00
Christopher Ferris
7f8915c76e Cache only a small portion of page map data.
The scudo memory allocator will allocate a large virtual memory address
that causes procrank to allocate a huge amount of data. Modify so it
caches the data a bit at a time.

Remove some allocations that are not necessary since the data is only used
in the first loop.

Fix a few pread64 checks against the actual bytes read, rather than the
read is < 0.

Fix sort by rss in procrank.

Bug: 135694447

Test: Ran unit tests (only one unit test actually runs the modified code).
Test: Ran the old version of procrank using a static libmeminfo and verified
Test: that the same data is found as the new version.

Change-Id: I8adc169b5607ec994ff13a9e161a479350d84c4d
2019-06-25 21:14:36 -07:00
Sandeep Patil
a42207e2e3 procrank: do not keep process maps around
procrank's usage in its output shows 20x increase from
last year. This is because it is keeping the process
maps around until termination. Fix that by getting rid
of ProcMemInfo objects when done parsing /proc/<pid>/maps,pagemap.

Note that the total allocations do not change and have not necessarily
regressed from Pie.

Bug: 130672819
Test: adb shell procrank | grep 'procrank\|cmdline'

Change-Id: Ib7bf960ed1d053347fcfc0c8aee9019607a1eb01
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-04-17 12:11:50 -07:00
Sandeep Patil
ba98e0e857 libmeminfo/procrank: Ignore failures when process disappears.
procrank currently fails if a process gets killed while it is reading
the stats. This behavior is a regression from the previous version of
procrank and is often undesired.

Change procrank to silently ignore the process if it detects that it had
been killed while reading the stats. If the process is still around,
then print a warning about it and continue to read stats for other
processes in the system.

Bug: 130177765
Test: Tested by deliberately killing specific process in ProcessRecord()
      constructor

Change-Id: I701808c3226bb9b3a350ccf8e67fb29b59b0d4e0
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-04-09 12:31:36 -07:00
Erick Reyes
5a744684c3 libmeminfo: librank optimization using maps instead of vectors
librank was calling std::vector::find_if in nested loops when iterating
through processes and maps.

Changed the implementation to use std::map::insert, this resulted in
a significant improvement to execution speed.

Test: time librank on crosshatch

Before:  1m22.57s real     1m15.87s user     0m05.79s system
After:   0m03.85s real     0m00.88s user     0m02.92s system

Bug: 124523194

Change-Id: I2b519d0bfd7f7929c6c4c6c2374794cb1a744585
Signed-off-by: Erick Reyes <erickreyes@google.com>
2019-03-01 16:17:20 -08:00
Treehugger Robot
81767b1d3d Merge "procinfo: Read inode number from /proc/<pid>/maps" 2019-02-15 23:03:00 +00:00
Erick Reyes
9bb8e0d704 libmeminfo: change dmabuf_dump from soc_specific to product_specific
The vendor partition does not give dmabuf_dump enough permissions to
retrieve shared buffer information for all processes. Move it to product
partition where it can be invoked from platform's dumpstate.

Bug: 63860998

Change-Id: I73957f59943d1e49fcb59abb723aad4eeeaa4172
Signed-off-by: Erick Reyes <erickreyes@google.com>
2019-02-11 19:16:58 -08:00
Sandeep Patil
f31c70989b procinfo: Read inode number from /proc/<pid>/maps
Adjust all callbacks to include the inode number as well.

Fixes: 123532375
Test: libprocinfo_test
Test: libdmabufinfo_test
Test: libmeminfo_test

Change-Id: I71fd75d90d5ee44585011c5ae654a1dd7e185458
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-02-11 01:38:08 +00:00
Treehugger Robot
38c143e8c0 Merge "meminfo: make dmabuf_dump dependency on debugfs optional" 2019-02-10 14:55:19 +00:00
Treehugger Robot
2d31b4b023 Merge "libmeminfo: make libdmabufinfo and dmabuf_dump vendor available" 2019-02-10 14:54:53 +00:00
Treehugger Robot
2dcb4160fa Merge "Fix 32-bit dmabuf_dump build" 2019-02-08 09:22:05 +00:00
Nicolas Geoffray
646c6d902d Don't abort the build if a repo doesn't have the test/vts/tools/build/.
Test: build with master-art manifest
Exempt-From-Owner-Approval: Required for unbreaking ART development.
Change-Id: I6afc0e5444dfa21532a4c802f8c463091cab2b11
2019-02-08 08:47:12 +00:00
Colin Cross
0a92453a14 Fix 32-bit dmabuf_dump build
Fixes:
system/core/libmeminfo/libdmabufinfo/tools/dmabuf_dump.cpp:109:39: error: format specifies type 'unsigned long' but the argument has type 'uint64_t' (aka 'unsigned long long') [-Werror,-Wformat]

Test: lunch aosp_arm-eng && m dmabuf_dump
Change-Id: Ie605d9b94f5eff888f6a64801512216253a6babb
2019-02-07 21:35:03 -08:00
Treehugger Robot
708d45979c Merge "meminfo: add tools/dmabufinfo_dump to dmabufinfo" 2019-02-08 02:53:54 +00:00
Treehugger Robot
a0b17a3d8b Merge "vts test for /proc/<pid>/smaps_rollup" 2019-02-08 02:05:55 +00:00
Erick Reyes
c4cac8f17f meminfo: make dmabuf_dump dependency on debugfs optional
dmabuf_dump had a hard dependency on debugfs to gather the initial list
of buffers for all proceses, make it optional.

Change-Id: I1d271297c0ad6124b321a1ee8aa01d3e88ca9fed
Signed-off-by: Erick Reyes <erickreyes@google.com>
2019-02-06 18:47:38 -08:00
Erick Reyes
2f6792e286 libmeminfo: make libdmabufinfo and dmabuf_dump vendor available
Removed dependency on libc++fs and changed liblog to shared linkage to
cope with build errors derived from the change.

Removed dmabuf_dump unnecessary dependencies and made it soc_specific.

Removed reference to std::filesystem::is_symlink to workaround the
following error when linking with the library:

ld.lld: error: undefined symbol:
std::__1::__fs::filesystem::__symlink_status(std::__1::__fs::filesystem::path
const&, std::__1::error_code*)
>>> referenced by filesystem:1743
(external/libcxx/include/filesystem:1743)
>>>
dmabufinfo.o:(android::dmabufinfo::AppendDmaBufInfo(int,
std::__1::vector<android::dmabufinfo::DmaBuffer,
std::__1::allocator<android::dmabufinfo::DmaBuffer> >*)) in archive

Bug: 63860998

Change-Id: Ieafdc87c64f153625df9e21fc8299292b2447aef
Signed-off-by: Erick Reyes <erickreyes@google.com>
2019-02-06 18:47:31 -08:00
Erick Reyes
fd79d4305a meminfo: add tools/dmabufinfo_dump to dmabufinfo
Adding tool to dump the dmabuf information using the dmabufinfo library.

Test: run "dmabuf_dump" and "dmabuf_dump <pid>" on crosshatch
Bug: 63860998

Change-Id: I16fe0a701deb5086ca0e1a8ceecb70dbc17934e6
Signed-off-by: Erick Reyes <erickreyes@google.com>
2019-02-06 15:26:05 -08:00
Erick Reyes
e3518d41d8 meminfo: Fix dmabufinfo total ref accounting
The number of references to a buffer total_refs was not accounting for
a process holding multiple references to the same buffer.

Also, clarify AppendDmaBufInfo functionality in comments

Change-Id: I044a18acad1570492a925d51b9464d5b0e60ca35
Signed-off-by: Erick Reyes <erickreyes@google.com>
2019-02-06 15:26:05 -08:00
Tri Vo
c57501384a vts test for /proc/<pid>/smaps_rollup
Bug: 122148371
Test: vts-tradefed run commandAndExit vts-kernel
--skip-all-system-status-check --primary-abi-only --skip-preconditions
--skip-device-info --module VtsKernelMemInfoTest
Change-Id: I855984a35a06c21e6e90ef3f8c33c3c0643090f1
2019-02-03 17:55:22 -08:00
Chenbo Feng
d45427725f Add more tests to libdmabufinfo
Add some test to verify the refcount and fd reference is correct when
the dma_buf is shared between processes.

Bug; 63860998
Test: libdmabufinfo_test

Change-Id: Id22e68e7a65820f19847b2faab11c78e6d942d92
2019-02-01 03:50:13 +00:00
Treehugger Robot
627a37cad9 Merge "meminfo: handle multiple buffer references in dmabufinfo" 2019-01-30 19:11:20 +00:00
Erick Reyes
302a259fa9 meminfo: handle multiple buffer references in dmabufinfo
Change the dmabufinfo library to handle multiple references to the same
buffer across PIDs by doing these changes:

- Add function AppendDmaBufInfo: appends the information for a specific
PID to an existing DmaBuffer vector
- Change the way fd/map references to a buffer belonging to a PID are
stored in DmaBuffer from vector<pid_t> to unorderedmap<pid_t, int>
- When parsing proc/%pid/{maps|fds}, look up the buffer by inode and
update the data if found

Test: builds
Bug: 63860998

Change-Id: If22feea772f182086ae3446b46d626a750674b1f
Signed-off-by: Erick Reyes <erickreyes@google.com>
2019-01-29 17:52:34 -08:00
Sandeep Patil
dfa00a7729 meminfo: Remove libpagemap dependency
Remove all tests that validated libmeminfo against the libpagemap
implementation and make libmeminfo_test self sufficient.

Bug: 111694435
Bug: 113035067
Test: libmeminfo_test
Change-Id: I21b9a0e2c71ef3f1f672a3b1de8080c0c36b4bfe
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-28 15:05:52 -08:00
Erick Reyes
d2918fe218 meminfo: Add memtrack dmabufinfo library
This is the userspace component for the improved shared memory buffer
tracking.

A new static library called libdmabufinfo will provide APIs to parse dmabuf
debugfs entries. The library can also map and read the file descriptors
per process to cross-reference the global data per process.

This change only adds a global API to read dmabuf stats from debugfs.

Bug: 63860998
Test: dmabufinfo_test
Change-Id: Ib0deedc73337a70875e03e07d3e9a692c4c33e63
Signed-off-by: Greg Hackmann <ghackmann@google.com>
Signed-off-by: Erick Reyes <erickreyes@google.com>
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-28 14:16:23 -08:00
Sandeep Patil
061b71339c meminfo: Add support to track working set with idle page tracking.
Also adds a tool to make use of this if it exists call 'wsstop'

Bug: 111694435
Test: wsstop -d 3 -n 100 1

Change-Id: I50415f0bdc09c09b5b414cf0e4fff8f2907c5823
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-23 22:53:46 -08:00
Sandeep Patil
62b80fa3ad Merge "meminfo: Pull ReadVmallocInfo() out of the SysMemInfo class." 2019-01-23 05:17:16 +00:00
Sandeep Patil
15a3a287f2 Merge "meminfo: Add API to read pagemap for a vma within a process." 2019-01-22 22:08:24 +00:00
Sandeep Patil
e04680d141 meminfo: Pull ReadVmallocInfo() out of the SysMemInfo class.
There is no need for the vmalloc reader to be in the sysmeminfo object.
The caller has to create the SysMemInfo object for no reason right now.

Bug: 111694435
Test: libmeminfo_test 1

Change-Id: I263c08c169ea6caf2221bfb915b26ef3c0b1c20c
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-22 14:06:01 -08:00
Sandeep Patil
cbc8f123d8 meminfo: Add API to read pagemap for a vma within a process.
.. and make sure we have some helper methods exposed to the clients
to do some basic checks for the pagemap values. For example, to check
if the page is present or swapped.

Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=ValidateProcMemInfo.TestPageMap
Test: libmeminfo_test 1

Change-Id: Ic6ae91f4214b42346f3d0b54164a43ac79d5ade1
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-21 17:24:54 -08:00
Sandeep Patil
d8e322c225 meminfo/tools: Enable all libmeminfo based tools
Enables procrank, procmem, librank and showmap.
Only showmap gets built into the default builds.

Bug: 111694435
Test: builds
Test: showmap exists in final builds

Change-Id: Ib5901aa2bd4ccc6aa3d02915fda92f8320651315
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-19 13:12:09 -08:00
Sandeep Patil
3fcb44b908 procmeminfo: use getline() instead of fgets() everywhere
Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=TestProcMemInfo.*

Change-Id: Idfc797aa65f45e0152765605c14622e2110dfdc1
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-14 18:11:53 -08:00
Sandeep Patil
d03244ab89 meminfo: test: delete SmapsOrRollupReturn test
The test has become invalid due to addition of IsSmapsRollupSupported()
and its internal usage by SmapsOrRollup() method. The method now returns
success and returns statistics even if 'smaps_rollup' doesn't exist. It
does that by internally checking for it's existence and falls back to
using /proc/<pid>/smaps

Bug: 111694435
Test: mma -j

Change-Id: I1983a23f1f617aee126bc66a4c1fbd4abb50f565
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-14 18:11:29 -08:00