summaryrefslogtreecommitdiff
path: root/pixelstats/MmMetricsReporter.cpp
diff options
context:
space:
mode:
authorChiawei Wang <chiaweiwang@google.com>2021-07-19 22:24:48 +0800
committerChiawei Wang <chiaweiwang@google.com>2021-08-19 00:21:50 +0000
commitb354a05cc5f1ed3281adf39994eae1a5148f0f0e (patch)
tree21dd4d657685b38914533a889a627b8da9ae57b9 /pixelstats/MmMetricsReporter.cpp
parenta8d614557584d12895477e48a4496836c4f143c1 (diff)
pixelstats: add the new field cma_heap_name
Since CMA heap names can be changed during the project development, we would like to store the CMA heap name directly instead of the enum value in order to avoid the maintenance effort. Bug: 194049685 Bug: 194077502 Test: adb shell cmd stats print-stats | grep 10502[45] Test: adb shell cmd stats print-logs adb logcat | grep 10502[45] Change-Id: Icfa9ffb45c6b14bdfb2c0364c55fe3e94056aa31
Diffstat (limited to 'pixelstats/MmMetricsReporter.cpp')
-rw-r--r--pixelstats/MmMetricsReporter.cpp48
1 files changed, 27 insertions, 21 deletions
diff --git a/pixelstats/MmMetricsReporter.cpp b/pixelstats/MmMetricsReporter.cpp
index 29d3dfe..502a251 100644
--- a/pixelstats/MmMetricsReporter.cpp
+++ b/pixelstats/MmMetricsReporter.cpp
@@ -91,12 +91,6 @@ const std::vector<MmMetricsReporter::MmMetricsInfo> MmMetricsReporter::kCmaStatu
{"latency_high", CmaStatusExt::kCmaAllocLatencyHighFieldNumber, false},
};
-const std::map<std::string, MmMetricsReporter::CmaType> MmMetricsReporter::kCmaTypeInfo = {
- {"farawimg", MmMetricsReporter::FARAWIMG}, {"faimg", MmMetricsReporter::FAIMG},
- {"faceauth_tpu", MmMetricsReporter::FATPU}, {"faprev", MmMetricsReporter::FAPREV},
- {"vframe", MmMetricsReporter::VFRAME}, {"vstream", MmMetricsReporter::VSTREAM},
-};
-
MmMetricsReporter::MmMetricsReporter()
: kVmstatPath("/proc/vmstat"),
kIonTotalPoolsPath("/sys/kernel/dma_heap/total_pools_kb"),
@@ -108,7 +102,10 @@ bool MmMetricsReporter::ReadFileToUint(const char *const path, uint64_t *val) {
std::string file_contents;
if (!ReadFileToString(path, &file_contents)) {
- ALOGI("Unable to read %s - %s", path, strerror(errno));
+ // Don't print this log if the file doesn't exist, since logs will be printed repeatedly.
+ if (errno != ENOENT) {
+ ALOGI("Unable to read %s - %s", path, strerror(errno));
+ }
return false;
} else {
file_contents = android::base::Trim(file_contents);
@@ -462,8 +459,8 @@ std::map<std::string, uint64_t> MmMetricsReporter::readCmaStat(
*
* stats_client: The Stats service
* atom_id: The id of atom. It can be PixelAtoms::Atom::kCmaStatus or kCmaStatusExt
- * cma_type: The name of CMA heap. We only collect metrics from CMA heaps defined
- * in kCmaTypeInfo.
+ * cma_type: The name of CMA heap.
+ * cma_name_offset: The offset of the field cma_heap_name in CmaStatus or CmaStatusExt
* type_idx: The id of the CMA heap. We add this id in atom values to identify
* the CMA status data.
* metrics_info: This is a vector of MmMetricsInfo {metric, atom_key, update_diff}.
@@ -476,23 +473,34 @@ std::map<std::string, uint64_t> MmMetricsReporter::readCmaStat(
*/
void MmMetricsReporter::reportCmaStatusAtom(
const std::shared_ptr<IStats> &stats_client, int atom_id, const std::string &cma_type,
- CmaType type_idx, const std::vector<MmMetricsInfo> &metrics_info,
- std::map<CmaType, std::map<std::string, uint64_t>> *all_prev_cma_stat) {
+ int cma_name_offset, const std::vector<MmMetricsInfo> &metrics_info,
+ std::map<std::string, std::map<std::string, uint64_t>> *all_prev_cma_stat) {
std::map<std::string, uint64_t> cma_stat = readCmaStat(cma_type, metrics_info);
if (!cma_stat.empty()) {
std::vector<VendorAtomValue> values;
VendorAtomValue tmp;
- tmp.set<VendorAtomValue::intValue>(type_idx);
+ // type is an enum value corresponding to the CMA heap name. Since CMA heap name
+ // can be added/removed/modified, it would take effort to maintain the mapping table.
+ // We would like to store CMA heap name directly, so just set type to 0.
+ tmp.set<VendorAtomValue::intValue>(0);
values.push_back(tmp);
std::map<std::string, uint64_t> prev_cma_stat;
- auto entry = all_prev_cma_stat->find(type_idx);
+ auto entry = all_prev_cma_stat->find(cma_type);
if (entry != all_prev_cma_stat->end())
prev_cma_stat = entry->second;
bool is_first_atom = (prev_cma_stat.size() == 0) ? true : false;
fillAtomValues(metrics_info, cma_stat, &prev_cma_stat, &values);
- (*all_prev_cma_stat)[type_idx] = prev_cma_stat;
+
+ int size = cma_name_offset - kVendorAtomOffset + 1;
+ if (values.size() < size) {
+ values.resize(size, tmp);
+ }
+ tmp.set<VendorAtomValue::stringValue>(cma_type);
+ values[cma_name_offset - kVendorAtomOffset] = tmp;
+
+ (*all_prev_cma_stat)[cma_type] = prev_cma_stat;
if (!is_first_atom)
reportVendorAtom(stats_client, atom_id, values, "CmaStatus");
}
@@ -513,14 +521,12 @@ void MmMetricsReporter::logCmaStatus(const std::shared_ptr<IStats> &stats_client
continue;
std::string cma_type(dp->d_name);
- auto type = kCmaTypeInfo.find(cma_type);
- if (type == kCmaTypeInfo.end())
- continue;
- reportCmaStatusAtom(stats_client, PixelAtoms::Atom::kCmaStatus, cma_type, type->second,
- kCmaStatusInfo, &prev_cma_stat_);
- reportCmaStatusAtom(stats_client, PixelAtoms::Atom::kCmaStatusExt, cma_type, type->second,
- kCmaStatusExtInfo, &prev_cma_stat_ext_);
+ reportCmaStatusAtom(stats_client, PixelAtoms::Atom::kCmaStatus, cma_type,
+ CmaStatus::kCmaHeapNameFieldNumber, kCmaStatusInfo, &prev_cma_stat_);
+ reportCmaStatusAtom(stats_client, PixelAtoms::Atom::kCmaStatusExt, cma_type,
+ CmaStatusExt::kCmaHeapNameFieldNumber, kCmaStatusExtInfo,
+ &prev_cma_stat_ext_);
}
}