Skip to content

Commit

Permalink
Android: Code residency: Measure success rate of the measurements
Browse files Browse the repository at this point in the history
Introduce a histogram reporting successes and failures at pulling code
residency data from /proc/self/pagemap.

Opening and reading /proc/self/pagemap can fail at fopen(3), fseek(3)
and fread(3). We think that we can potentially mitigate errors at fopen,
see the bug for details.

The current code distinguishes two error kinds:
1. at fopen
2. at fseek or fread

The histogram mirrors this separation. In the future the fopen errors
can also be broken down into several errno values. At this point the
extra detail seems unnecessary.

Bug: 1070618
Change-Id: I2b88c24c0861b46845707dbf88b16b2e4817ae22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2215856
Commit-Queue: Egor Pasko <pasko@chromium.org>
Reviewed-by: Benoit L <lizeb@chromium.org>
Reviewed-by: Primiano Tucci <primiano@chromium.org>
Reviewed-by: Alex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772314}
  • Loading branch information
pasko authored and Commit Bot committed May 27, 2020
1 parent 782ec0f commit ba6226b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,32 @@ class COMPONENT_EXPORT(
#endif

#if defined(OS_LINUX) || defined(OS_ANDROID)
// Provides information on the dump state of resident pages.
// Provides information on the dump state of resident pages. These values are
// written to logs. New enum values can be added, but existing enums must
// never be renumbered or deleted and reused.
enum class MappedAndResidentPagesDumpState {
// Access to /proc/<pid>/pagemap can be denied for android devices running
// a kernel version < 4.4.
kAccessPagemapDenied,
kFailure,
kSuccess
kAccessPagemapDenied = 0,
kFailure = 1,
kSuccess = 2,

// Must be equal to the greatest among enumeraiton values.
kMaxValue = kSuccess
};

// Depends on /proc/self/pagemap to determine mapped and resident pages
// within bounds (start_address inclusive and end_address exclusive).
// It does not use mincore() because it only checks to see
// if the page is in the cache and up to date.
// mincore() has no guarantee a page has been mapped by the current process.
// Guaranteed to work on Android.
// Fills out a bitmap of memory pages accessed by the current process that are
// still in pagecache.
//
// Depends on /proc/self/pagemap to determine the mapped and resident pages
// within bounds (|start_address| inclusive and |end_address| exclusive).
//
// Does not use mincore() because the latter only reports resident pages. The
// mincore() would report a page as resident if that page was accessed from a
// different process (such as the commonly used prefetch of the native
// library).
//
// Tested only on Android.
static MappedAndResidentPagesDumpState GetMappedAndResidentPages(
const size_t start_address,
const size_t end_address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/format_macros.h"
#include "base/metrics/histogram_macros.h"
#include "base/process/process_metrics.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
Expand Down Expand Up @@ -280,9 +281,13 @@ bool OSMetrics::FillOSMemoryDump(base::ProcessId pid,
OSMetrics::GetMappedAndResidentPages(base::android::kStartOfText,
base::android::kEndOfText,
&accessed_pages_bitmap);
UMA_HISTOGRAM_ENUMERATION(
"Memory.NativeLibrary.MappedAndResidentMemoryFootprintCollectionStatus",
state);

// MappedAndResidentPagesDumpState |state| can be |kAccessPagemapDenied|
// for Android devices running a kernel version < 4.4.
// for Android devices running a kernel version < 4.4 or because the process
// is not "dumpable", as described in proc(5).
if (state != OSMetrics::MappedAndResidentPagesDumpState::kSuccess)
return state != OSMetrics::MappedAndResidentPagesDumpState::kFailure;

Expand Down
6 changes: 6 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42955,6 +42955,12 @@ from previous Chrome versions.
<int value="12" label="Bad Update specification"/>
</enum>

<enum name="MappedAndResidentPagesDumpState">
<int value="0" label="kAccessPagemapDenied"/>
<int value="1" label="kFailure"/>
<int value="2" label="kSuccess"/>
</enum>

<enum name="MappedCSSProperties">
<!-- Generated from third_party/blink/public/mojom/use_counter/css_property_id.mojom.
Called by update_use_counter_css.py.-->
Expand Down
14 changes: 14 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82163,6 +82163,20 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>

<histogram
name="Memory.NativeLibrary.MappedAndResidentMemoryFootprintCollectionStatus"
enum="MappedAndResidentPagesDumpState" expires_after="2020-10-11">
<owner>lizeb@chromium.org</owner>
<owner>pasko@chromium.org</owner>
<summary>
Result of an attempt to read /proc/self/pagemap when determining the amount
of resident memory mapped by the current process. Reading the file is
performed as part of computing the
Memory.NativeLibrary.MappedAndResidentMemoryFootprint2 histogram. Recorded
once per UMA ping. Available only on Android.
</summary>
</histogram>

<histogram name="Memory.NativeLibrary.NotResidentOrderedCodeMemoryFootprint"
units="KB" expires_after="2020-10-11">
<owner>lizeb@chromium.org</owner>
Expand Down

0 comments on commit ba6226b

Please sign in to comment.