summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaineel <jaineelm@google.com>2021-12-06 18:43:16 -0800
committerJaineel Mehta <jaineelm@google.com>2021-12-08 21:40:45 +0000
commitf1d552e98affa00486588e8fb7e51579ce1dac54 (patch)
tree09939b23dda36b7c5f8aba84f93341f8b34ccabf
parent06d6a15a4f37316fa87c7c9c3b3974abf9ae29e3 (diff)
downloadplatform_testing-f1d552e98affa00486588e8fb7e51579ce1dac54.tar.gz
Add parent-child process mapping metric in showmap
new metric will be recorded as parent_process_<name>_child_process_<name> Test: atest ShowmapSnapshotHelperTest Bug: 198509220 Change-Id: I8729041a7594a6c00b0cd70cfa3ee1137933776f
-rw-r--r--libraries/collectors-helper/memory/src/com/android/helpers/ShowmapSnapshotHelper.java40
-rw-r--r--libraries/collectors-helper/memory/test/src/com/android/helpers/tests/ShowmapSnapshotHelperTest.java23
2 files changed, 58 insertions, 5 deletions
diff --git a/libraries/collectors-helper/memory/src/com/android/helpers/ShowmapSnapshotHelper.java b/libraries/collectors-helper/memory/src/com/android/helpers/ShowmapSnapshotHelper.java
index c23d652bf..4bc6d4182 100644
--- a/libraries/collectors-helper/memory/src/com/android/helpers/ShowmapSnapshotHelper.java
+++ b/libraries/collectors-helper/memory/src/com/android/helpers/ShowmapSnapshotHelper.java
@@ -32,8 +32,11 @@ import java.util.InputMismatchException;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@@ -55,6 +58,10 @@ public class ShowmapSnapshotHelper implements ICollectorHelper<String> {
public static final String OUTPUT_CHILD_PROCESS_COUNT_KEY = CHILD_PROCESS_COUNT_PREFIX + "_%s";
public static final String PROCESS_WITH_CHILD_PROCESS_COUNT =
"process_with_child_process_count";
+ private static final String CHILD_PROCESS_NAME_REGEX = "(\\S+)$";
+ private static final String METRIC_VALUE_SEPARATOR = "_";
+ public static final String PARENT_PROCESS_STRING = "parent_process";
+ public static final String CHILD_PROCESS_STRING = "child_process";
private String[] mProcessNames = null;
private String mTestOutputDir = null;
@@ -155,7 +162,7 @@ public class ShowmapSnapshotHelper implements ICollectorHelper<String> {
// Parse number of child processes for the given pid and update the
// total number of child process count for the process name that pid
// is associated with.
- updateChildProcessesCount(processName, pid);
+ updateChildProcessesDetails(processName, pid);
}
} catch (RuntimeException e) {
Log.e(TAG, e.getMessage(), e.getCause());
@@ -344,12 +351,16 @@ public class ShowmapSnapshotHelper implements ICollectorHelper<String> {
/**
* Retrieves the number of child processes for the given process id and updates the total
- * process count for the process name that pid is associated with.
+ * process count and adds a child process metric for the process name that pid is associated
+ * with.
*
* @param processName
* @param pid
*/
- private void updateChildProcessesCount(String processName, long pid) {
+ private void updateChildProcessesDetails(String processName, long pid) {
+ String childProcessName;
+ String completeChildProcessMetric;
+ Pattern childProcessPattern = Pattern.compile(CHILD_PROCESS_NAME_REGEX);
try {
Log.i(TAG,
String.format("Retrieving child processes count for process name: %s with"
@@ -368,8 +379,29 @@ public class ShowmapSnapshotHelper implements ICollectorHelper<String> {
Long.parseLong(mMemoryMap.getOrDefault(childCountMetricKey, "0"))
+ childProcessCount));
}
+ for (String line : childProcessStrSplit) {
+ // To discard the header line in the command output.
+ if (Objects.equals(line, childProcessStrSplit[0])) continue;
+ Matcher childProcessMatcher = childProcessPattern.matcher(line);
+ if (childProcessMatcher.find()) {
+ /**
+ * final metric will be of following format
+ * parent_process_<process>_child_process_<process>
+ * parent_process_zygote64_child_process_system_server
+ */
+ childProcessName = childProcessMatcher.group(1);
+ completeChildProcessMetric =
+ String.join(
+ METRIC_VALUE_SEPARATOR,
+ PARENT_PROCESS_STRING,
+ processName,
+ CHILD_PROCESS_STRING,
+ childProcessName);
+ mMemoryMap.put(completeChildProcessMetric, "1");
+ }
+ }
} catch (IOException e) {
- throw new RuntimeException("Unable to run child process count command.", e);
+ throw new RuntimeException("Unable to run child process command.", e);
}
}
diff --git a/libraries/collectors-helper/memory/test/src/com/android/helpers/tests/ShowmapSnapshotHelperTest.java b/libraries/collectors-helper/memory/test/src/com/android/helpers/tests/ShowmapSnapshotHelperTest.java
index eaca26b35..596323e6d 100644
--- a/libraries/collectors-helper/memory/test/src/com/android/helpers/tests/ShowmapSnapshotHelperTest.java
+++ b/libraries/collectors-helper/memory/test/src/com/android/helpers/tests/ShowmapSnapshotHelperTest.java
@@ -215,6 +215,26 @@ public class ShowmapSnapshotHelperTest {
assertTrue(metrics.containsKey(ShowmapSnapshotHelper.CHILD_PROCESS_COUNT_PREFIX + "_init"));
}
+ @Test
+ public void testGetMetrics_parent_process_child_processes_metrics() {
+ mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, NO_PROCESS_LIST);
+ mShowmapSnapshotHelper.setMetricNameIndex(METRIC_EMPTY_INDEX_STR);
+
+ mShowmapSnapshotHelper.setAllProcesses();
+ assertTrue(mShowmapSnapshotHelper.startCollecting());
+ Map<String, String> metrics = mShowmapSnapshotHelper.getMetrics();
+
+ assertTrue(metrics.size() != 0);
+
+ Set<String> parentWithChildProcessSet =
+ metrics.keySet().stream()
+ .filter(s -> s.startsWith(ShowmapSnapshotHelper.PARENT_PROCESS_STRING))
+ .collect(Collectors.toSet());
+
+ // At least one process (i.e init) will have child process
+ assertTrue(parentWithChildProcessSet.size() > 0);
+ }
+
private boolean verifyDefaultMetrics(Map<String, String> metrics) {
if(metrics.size() == 0) {
return false;
@@ -223,7 +243,8 @@ public class ShowmapSnapshotHelperTest {
if (!(key.equals(ShowmapSnapshotHelper.PROCESS_COUNT)
|| key.equals(ShowmapSnapshotHelper.OUTPUT_FILE_PATH_KEY)
|| key.equals(ShowmapSnapshotHelper.PROCESS_WITH_CHILD_PROCESS_COUNT)
- || key.startsWith(ShowmapSnapshotHelper.CHILD_PROCESS_COUNT_PREFIX))) {
+ || key.startsWith(ShowmapSnapshotHelper.CHILD_PROCESS_COUNT_PREFIX)
+ || key.startsWith(ShowmapSnapshotHelper.PARENT_PROCESS_STRING))) {
return false;
}
}