summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Hsu <robinhsu@google.com>2022-07-06 17:00:43 +0800
committerRobin Hsu <robinhsu@google.com>2022-08-26 02:59:15 +0000
commitfebb9696c61d14bc65c727b6fad3ef751c297386 (patch)
treeb15c0bde6b349d119194407666358f897afa4f92
parent36df9efa5c29ed920ae242dc165d5c4ac050a88b (diff)
pixelstat: MM metrics: direct reclaim metrics
Direct reclaim metrics: /sys/kernel/pixel_stat/mm/vmscan/direct_reclaim/<level>/latency_stat <level> could be native, top, visible, or other Sample output: (root) # cat /sys/kernel/pixel_stat/mm/vmscan/direct_reclaim/native/latency_stat 138 7888 70 35 31 2 Test: local test Bug: 234564667 Signed-off-by: Robin Hsu <robinhsu@google.com> Change-Id: If695ae5016037b6bd1e213981340f2b14bf756f2
-rw-r--r--pixelstats/MmMetricsReporter.cpp67
-rw-r--r--pixelstats/include/pixelstats/MmMetricsReporter.h6
2 files changed, 72 insertions, 1 deletions
diff --git a/pixelstats/MmMetricsReporter.cpp b/pixelstats/MmMetricsReporter.cpp
index b6498bf..ecf9598 100644
--- a/pixelstats/MmMetricsReporter.cpp
+++ b/pixelstats/MmMetricsReporter.cpp
@@ -159,7 +159,9 @@ MmMetricsReporter::MmMetricsReporter()
kIonTotalPoolsPath("/sys/kernel/dma_heap/total_pools_kb"),
kIonTotalPoolsPathForLegacy("/sys/kernel/ion/total_pools_kb"),
kGpuTotalPages("/sys/kernel/pixel_stat/gpu/mem/total_page_count"),
- kPixelStatMm("/sys/kernel/pixel_stat/mm") {
+ kDirectReclaimBasePath("/sys/kernel/pixel_stat/mm/vmscan/direct_reclaim"),
+ kPixelStatMm("/sys/kernel/pixel_stat/mm"),
+ prev_direct_reclaim_(kNumDirectReclaimPrevMetrics, 0) {
is_user_build_ = checkUserBuild();
ker_mm_metrics_support_ = checkKernelMMMetricSupport();
}
@@ -440,6 +442,9 @@ void MmMetricsReporter::logPixelMmMetricsPerDay(const std::shared_ptr<IStats> &s
if (vmstat.size() == 0)
return;
+ std::vector<long> direct_reclaim;
+ readDirectReclaimStat(&direct_reclaim);
+
bool is_first_atom = (prev_day_vmstat_.size() == 0) ? true : false;
// allocate enough values[] entries for the metrics.
@@ -458,6 +463,7 @@ void MmMetricsReporter::logPixelMmMetricsPerDay(const std::shared_ptr<IStats> &s
&prev_kswapd_stime_, &values);
fillProcessStime(PixelMmMetricsPerDay::kKcompactdStimeClksFieldNumber, "kcompactd0",
&kcompactd_pid_, &prev_kcompactd_stime_, &values);
+ fillDirectReclaimStatAtom(direct_reclaim, &values);
// Don't report the first atom to avoid big spike in accumulated values.
if (!is_first_atom) {
@@ -601,6 +607,65 @@ std::map<std::string, uint64_t> MmMetricsReporter::readCmaStat(
}
/**
+ * This function reads direct reclaim sysfs node (4 files:
+ * /sys/kernel/pixel_stat/mm/vmscan/direct_reclaim/<level>/latency_stat,
+ * where <level> = native, top, visible, other.), and save total time and
+ * 4 latency information per file. Total (1+4) x 4 = 20 metrics will be
+ * saved.
+ *
+ * store: vector to save direct reclaim info
+ */
+void MmMetricsReporter::readDirectReclaimStat(std::vector<long> *store) {
+ static const std::string base_path(kDirectReclaimBasePath);
+ static const std::vector<std::string> dr_levels{"native", "top", "visible", "other"};
+ static const std::string sysfs_name = "latency_stat";
+ constexpr int num_metrics_per_file = 5;
+ int num_file = dr_levels.size();
+ int num_metrics = num_metrics_per_file * num_file;
+
+ store->resize(num_metrics);
+ int pass = -1;
+ for (auto level : dr_levels) {
+ ++pass;
+ std::string path = base_path + '/' + level + '/' + sysfs_name;
+ int start_idx = pass * num_metrics_per_file;
+ int expected_num = num_metrics_per_file;
+ if (!ReadFileToLongsCheck(path, store, start_idx, " ", 1, expected_num, true)) {
+ ALOGI("Unable to read %s for the direct reclaim info.", path.c_str());
+ }
+ }
+}
+
+/**
+ * This function fills atom values (values) from acquired direct reclaim
+ * information from vector store
+ *
+ * store: the already collected (by readDirectReclaimStat()) direct reclaim
+ * information
+ * values: the atom value vector to be filled.
+ */
+void MmMetricsReporter::fillDirectReclaimStatAtom(const std::vector<long> &store,
+ std::vector<VendorAtomValue> *values) {
+ // first metric index
+ constexpr int start_idx = PixelMmMetricsPerDay::kDirectReclaimNativeLatencyTotalTimeFieldNumber;
+ constexpr int num_metrics = 20; /* num_metrics_per_file * num_file */
+
+ if (!MmMetricsSupported())
+ return;
+
+ int size = start_idx + num_metrics - kVendorAtomOffset;
+ if (values->size() < size)
+ values->resize(size);
+
+ for (int i = 0; i < num_metrics; i++) {
+ VendorAtomValue tmp;
+ tmp.set<VendorAtomValue::longValue>(store[i] - prev_direct_reclaim_[i]);
+ (*values)[start_idx + i] = tmp;
+ }
+ prev_direct_reclaim_ = store;
+}
+
+/**
* This function reads pressure (PSI) files (loop thru all 3 files: cpu, io, and
* memory) and calls the parser to parse and store the metric values.
* Note that each file have two lines (except cpu has one line only): one with
diff --git a/pixelstats/include/pixelstats/MmMetricsReporter.h b/pixelstats/include/pixelstats/MmMetricsReporter.h
index fc1cedc..2443d84 100644
--- a/pixelstats/include/pixelstats/MmMetricsReporter.h
+++ b/pixelstats/include/pixelstats/MmMetricsReporter.h
@@ -118,6 +118,9 @@ class MmMetricsReporter {
bool ReadFileToUint(const char *const path, uint64_t *val);
bool reportVendorAtom(const std::shared_ptr<IStats> &stats_client, int atom_id,
const std::vector<VendorAtomValue> &values, const std::string &atom_name);
+ void readDirectReclaimStat(std::vector<long> *store);
+ void fillDirectReclaimStatAtom(const std::vector<long> &store,
+ std::vector<VendorAtomValue> *values);
void readPressureStall(const char *basePath, std::vector<long> *store);
bool parsePressureStallFileContent(bool is_cpu, std::string lines, std::vector<long> *store,
int file_save_idx);
@@ -150,12 +153,15 @@ class MmMetricsReporter {
const char *const kIonTotalPoolsPath;
const char *const kIonTotalPoolsPathForLegacy;
const char *const kGpuTotalPages;
+ const char *const kDirectReclaimBasePath;
const char *const kPixelStatMm;
// Proto messages are 1-indexed and VendorAtom field numbers start at 2, so
// store everything in the values array at the index of the field number
// -2.
static constexpr int kVendorAtomOffset = 2;
+ static constexpr int kNumDirectReclaimPrevMetrics = 20;
+ std::vector<long> prev_direct_reclaim_;
long prev_psi_total_[kPsiNumAllTotals];
long psi_total_[kPsiNumAllTotals];
long psi_aggregated_[kPsiNumAllUploadAvgMetrics]; // min, max and avg of original avgXXX