Refactor librank into libsmapinfo
This change refactors librank by moving core functions into libsmapinfo.
This is done with the eventual goal of being able to output
procrank+librank+showmap information with a single read of smaps during
bug reports, since these tools currently take a significant amount of
time.
This change reduces librank's duration by ~70% (4.47s -> 1.26s).
Functionality is generally unchanged for the librank tool, but some
modifications have been made during this refactor:
- Sort functions are created as-needed instead of unconditionally, since
the functions cannot be easily passed from librank.cpp to
smapinfo.cpp.
- The ability to sort processes by oomadj score has been added.
- librank's 'ProcessRecord' struct has been renamed to 'LibProcRecord',
since 'ProcessRecord' is already being used in smapinfo.
- LibProcRecords now just reuse information from ProcessRecords instead
of re-reading /proc/<pid>/cmdline/oom_score_adj.
- LibRecord's usage() function has been removed, since it is unused.
- A separate function has been created for printing processes to raw
text for parity with the functions for printing JSON and CSV.
- Existing usages of std::endl have been replaced with '\n'.
- Namespaces have been added for librank/procrank-specific functions.
Test: - Ran librank to verify that it still functions in the same way.
- Checked that librank -o sorts by oom score as expected.
Bug: 229147699
Change-Id: Id967298fae64bed68327eb6c9c22ab6801bdc618
5 files changed