Fix formatting in ShowmapSnapshotHelper.

Bug: b/176130590

Test: ShowmapSnapshotHelperTest
Change-Id: I9b4a7a897589687b876a635d4ac81073662b0018
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 fba95b0..2dece36 100644
--- a/libraries/collectors-helper/memory/src/com/android/helpers/ShowmapSnapshotHelper.java
+++ b/libraries/collectors-helper/memory/src/com/android/helpers/ShowmapSnapshotHelper.java
@@ -37,322 +37,328 @@
  * Helper to collect memory information for a list of processes from showmap.
  */
 public class ShowmapSnapshotHelper implements ICollectorHelper<String> {
-  private static final String TAG = ShowmapSnapshotHelper.class.getSimpleName();
+    private static final String TAG = ShowmapSnapshotHelper.class.getSimpleName();
 
-  private static final String DROP_CACHES_CMD = "echo %d > /proc/sys/vm/drop_caches";
-  private static final String PIDOF_CMD = "pidof %s";
-  public static final String ALL_PROCESSES_CMD = "ps -A";
-  private static final String SHOWMAP_CMD = "showmap -v %d";
+    private static final String DROP_CACHES_CMD = "echo %d > /proc/sys/vm/drop_caches";
+    private static final String PIDOF_CMD = "pidof %s";
+    public static final String ALL_PROCESSES_CMD = "ps -A";
+    private static final String SHOWMAP_CMD = "showmap -v %d";
 
-  public static final String OUTPUT_METRIC_PATTERN = "showmap_%s_bytes";
-  public static final String OUTPUT_FILE_PATH_KEY = "showmap_output_file";
-  public static final String PROCESS_COUNT = "process_count";
+    public static final String OUTPUT_METRIC_PATTERN = "showmap_%s_bytes";
+    public static final String OUTPUT_FILE_PATH_KEY = "showmap_output_file";
+    public static final String PROCESS_COUNT = "process_count";
 
-  private String[] mProcessNames = null;
-  private String mTestOutputDir = null;
-  private String mTestOutputFile = null;
+    private String[] mProcessNames = null;
+    private String mTestOutputDir = null;
+    private String mTestOutputFile = null;
 
-  private int mDropCacheOption;
-  private boolean mCollectForAllProcesses = false;
-  private UiDevice mUiDevice;
+    private int mDropCacheOption;
+    private boolean mCollectForAllProcesses = false;
+    private UiDevice mUiDevice;
 
-  // Map to maintain per-process memory info
-  private Map<String, String> mMemoryMap = new HashMap<>();
-  
-  // Maintain metric name and the index it corresponds to in the showmap output
-  // summary
-  private Map<Integer, String> mMetricNameIndexMap = new HashMap<>();
+    // Map to maintain per-process memory info
+    private Map<String, String> mMemoryMap = new HashMap<>();
 
-  public void setUp(String testOutputDir, String... processNames) {
-    mProcessNames = processNames;
-    mTestOutputDir = testOutputDir;
-    mDropCacheOption = 0;
-    mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
-  }
+    // Maintain metric name and the index it corresponds to in the showmap output
+    // summary
+    private Map<Integer, String> mMetricNameIndexMap = new HashMap<>();
 
-  @Override
-  public boolean startCollecting() {
-    if (mTestOutputDir == null) {
-      Log.e(TAG, String.format("Invalid test setup"));
-      return false;
+    public void setUp(String testOutputDir, String... processNames) {
+        mProcessNames = processNames;
+        mTestOutputDir = testOutputDir;
+        mDropCacheOption = 0;
+        mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
     }
 
-    File directory = new File(mTestOutputDir);
-    String filePath =
-        String.format("%s/showmap_snapshot%d.txt", mTestOutputDir, UUID.randomUUID().hashCode());
-    File file = new File(filePath);
+    @Override
+    public boolean startCollecting() {
+        if (mTestOutputDir == null) {
+            Log.e(TAG, String.format("Invalid test setup"));
+            return false;
+        }
 
-    // Make sure directory exists and file does not
-    if (directory.exists()) {
-      if (file.exists() && !file.delete()) {
-        Log.e(TAG, String.format("Failed to delete result output file %s", filePath));
-        return false;
-      }
-    } else {
-      if (!directory.mkdirs()) {
-        Log.e(TAG, String.format("Failed to create result output directory %s", mTestOutputDir));
-        return false;
-      }
-    }
+        File directory = new File(mTestOutputDir);
+        String filePath = String.format("%s/showmap_snapshot%d.txt", mTestOutputDir,
+                UUID.randomUUID().hashCode());
+        File file = new File(filePath);
 
-    // Create an empty file to fail early in case there are no write permissions
-    try {
-      if (!file.createNewFile()) {
-        // This should not happen unless someone created the file right after we deleted it
-        Log.e(TAG, String.format("Race with another user of result output file %s", filePath));
-        return false;
-      }
-    } catch (IOException e) {
-      Log.e(TAG, String.format("Failed to create result output file %s", filePath), e);
-      return false;
-    }
+        // Make sure directory exists and file does not
+        if (directory.exists()) {
+            if (file.exists() && !file.delete()) {
+                Log.e(TAG, String.format("Failed to delete result output file %s", filePath));
+                return false;
+            }
+        } else {
+            if (!directory.mkdirs()) {
+                Log.e(TAG, String.format("Failed to create result output directory %s",
+                        mTestOutputDir));
+                return false;
+            }
+        }
 
-    mTestOutputFile = filePath;
-    return true;
-  }
-
-  @Override
-  public Map<String, String> getMetrics() {
-    try {
-      // Drop cache if requested
-      if (mDropCacheOption > 0) {
-        dropCache(mDropCacheOption);
-      }
-
-      if (mCollectForAllProcesses) {
-         Log.i(TAG, "Collecting memory metrics for all processes.");
-         mProcessNames = getAllProcessNames();
-      } else if (mProcessNames.length > 0) {
-         Log.i(TAG, "Collecting memory only for given list of process");
-      } else if (mProcessNames.length == 0) {
-        // No processes specified, just return empty map
-        return mMemoryMap;
-      }
-
-      FileWriter writer = new FileWriter(new File(mTestOutputFile), true);
-      for (String processName : mProcessNames) {
-        List<Integer> pids = new ArrayList<>();
-
-        // Collect required data
+        // Create an empty file to fail early in case there are no write permissions
         try {
-          pids = getPids(processName);
-          for (Integer pid: pids) {
-            String showmapOutput = execShowMap(processName, pid);
-            parseAndUpdateMemoryInfo(processName, showmapOutput);
-            // Store showmap output into file. If there are more than one process
-            // with same name write the individual showmap associated with pid.
-            storeToFile(mTestOutputFile, processName, pid, showmapOutput, writer);
-          }
+            if (!file.createNewFile()) {
+                // This should not happen unless someone created the file right after we deleted it
+                Log.e(TAG,
+                        String.format("Race with another user of result output file %s", filePath));
+                return false;
+            }
+        } catch (IOException e) {
+            Log.e(TAG, String.format("Failed to create result output file %s", filePath), e);
+            return false;
+        }
+
+        mTestOutputFile = filePath;
+        return true;
+    }
+
+    @Override
+    public Map<String, String> getMetrics() {
+        try {
+            // Drop cache if requested
+            if (mDropCacheOption > 0) {
+                dropCache(mDropCacheOption);
+            }
+
+            if (mCollectForAllProcesses) {
+                Log.i(TAG, "Collecting memory metrics for all processes.");
+                mProcessNames = getAllProcessNames();
+            } else if (mProcessNames.length > 0) {
+                Log.i(TAG, "Collecting memory only for given list of process");
+            } else if (mProcessNames.length == 0) {
+                // No processes specified, just return empty map
+                return mMemoryMap;
+            }
+
+            FileWriter writer = new FileWriter(new File(mTestOutputFile), true);
+            for (String processName : mProcessNames) {
+                List<Integer> pids = new ArrayList<>();
+
+                // Collect required data
+                try {
+                    pids = getPids(processName);
+                    for (Integer pid : pids) {
+                        String showmapOutput = execShowMap(processName, pid);
+                        parseAndUpdateMemoryInfo(processName, showmapOutput);
+                        // Store showmap output into file. If there are more than one process
+                        // with same name write the individual showmap associated with pid.
+                        storeToFile(mTestOutputFile, processName, pid, showmapOutput, writer);
+                    }
+                } catch (RuntimeException e) {
+                    Log.e(TAG, e.getMessage(), e.getCause());
+                    // Skip this process and continue with the next one
+                    continue;
+                }
+            }
+            // Store the unique process count. -1 to exclude the "ps" process name.
+            mMemoryMap.put(PROCESS_COUNT, Integer.toString(mProcessNames.length - 1));
+            writer.close();
+            mMemoryMap.put(OUTPUT_FILE_PATH_KEY, mTestOutputFile);
         } catch (RuntimeException e) {
-          Log.e(TAG, e.getMessage(), e.getCause());
-          // Skip this process and continue with the next one
-          continue;
-        }   
-      }
-      // Store the unique process count. -1 to exclude the "ps" process name.
-      mMemoryMap.put(PROCESS_COUNT, Integer.toString(mProcessNames.length - 1));
-      writer.close();
-      mMemoryMap.put(OUTPUT_FILE_PATH_KEY, mTestOutputFile);
-    } catch (RuntimeException e) {
-      Log.e(TAG, e.getMessage(), e.getCause());
-    } catch (IOException e) {
-      Log.e(TAG, String.format("Failed to write output file %s", mTestOutputFile), e);
+            Log.e(TAG, e.getMessage(), e.getCause());
+        } catch (IOException e) {
+            Log.e(TAG, String.format("Failed to write output file %s", mTestOutputFile), e);
+        }
+
+        return mMemoryMap;
     }
 
-    return mMemoryMap;
-  }
-
-  @Override
-  public boolean stopCollecting() {
-    return true;
-  }
-
-  /**
-   * Set drop cache option.
-   *
-   * @param dropCacheOption drop pagecache (1), slab (2) or all (3) cache
-   * @return true on success, false if input option is invalid
-   */
-  public boolean setDropCacheOption(int dropCacheOption) {
-    // Valid values are 1..3
-    if (dropCacheOption < 1 || dropCacheOption > 3) {
-      return false;
+    @Override
+    public boolean stopCollecting() {
+        return true;
     }
 
-    mDropCacheOption = dropCacheOption;
-    return true;
-  }
+    /**
+     * Set drop cache option.
+     *
+     * @param dropCacheOption drop pagecache (1), slab (2) or all (3) cache
+     * @return true on success, false if input option is invalid
+     */
+    public boolean setDropCacheOption(int dropCacheOption) {
+        // Valid values are 1..3
+        if (dropCacheOption < 1 || dropCacheOption > 3) {
+            return false;
+        }
 
-  /**
-   * Drops kernel memory cache.
-   *
-   * @param cacheOption drop pagecache (1), slab (2) or all (3) caches
-   */
-  private void dropCache(int cacheOption) throws RuntimeException {
-    try {
-      mUiDevice.executeShellCommand(String.format(DROP_CACHES_CMD, cacheOption));
-    } catch (IOException e) {
-      throw new RuntimeException("Unable to drop caches", e);
+        mDropCacheOption = dropCacheOption;
+        return true;
     }
-  }
 
-  /**
-   * Get pid's of the process with {@code processName} name.
-   *
-   * @param processName name of the process to get pid
-   * @return pid's of the specified process
-   */
-  private List<Integer> getPids(String processName) throws RuntimeException {
-    try {
-      String pidofOutput = mUiDevice.executeShellCommand(String.format(PIDOF_CMD, processName));
-
-      // Sample output for the process with more than 1 pid.
-      // Sample command : "pidof init"
-      // Sample output : 1 559
-      String[] pids = pidofOutput.split("\\s+");
-      List<Integer> pidList = new ArrayList<>();
-      for (String pid: pids) {
-          pidList.add(Integer.parseInt(pid.trim()));
-      }
-      return pidList;
-    } catch (IOException e) {
-      throw new RuntimeException(String.format("Unable to get pid of %s ", processName), e);
+    /**
+     * Drops kernel memory cache.
+     *
+     * @param cacheOption drop pagecache (1), slab (2) or all (3) caches
+     */
+    private void dropCache(int cacheOption) throws RuntimeException {
+        try {
+            mUiDevice.executeShellCommand(String.format(DROP_CACHES_CMD, cacheOption));
+        } catch (IOException e) {
+            throw new RuntimeException("Unable to drop caches", e);
+        }
     }
-  }
 
-  /**
-   * Executes showmap command for the process with {@code processName} name and {@code pid} pid.
-   *
-   * @param processName name of the process to run showmap for
-   * @param pid pid of the process to run showmap for
-   * @return the output of showmap command
-   */
-  private String execShowMap(String processName, long pid) throws IOException {
-    try {
-      return mUiDevice.executeShellCommand(String.format(SHOWMAP_CMD, pid));
-    } catch (IOException e) {
-      throw new RuntimeException(
-          String.format("Unable to execute showmap command for %s ", processName), e);
+    /**
+     * Get pid's of the process with {@code processName} name.
+     *
+     * @param processName name of the process to get pid
+     * @return pid's of the specified process
+     */
+    private List<Integer> getPids(String processName) throws RuntimeException {
+        try {
+            String pidofOutput = mUiDevice
+                    .executeShellCommand(String.format(PIDOF_CMD, processName));
+
+            // Sample output for the process with more than 1 pid.
+            // Sample command : "pidof init"
+            // Sample output : 1 559
+            String[] pids = pidofOutput.split("\\s+");
+            List<Integer> pidList = new ArrayList<>();
+            for (String pid : pids) {
+                pidList.add(Integer.parseInt(pid.trim()));
+            }
+            return pidList;
+        } catch (IOException e) {
+            throw new RuntimeException(String.format("Unable to get pid of %s ", processName), e);
+        }
     }
-  }
 
-  /**
-   * Extract memory metrics from showmap command output for the process with {@code processName}
-   * name.
-   *
-   * @param processName name of the process to extract memory info for
-   * @param showmapOutput showmap command output
-   */
-  private void parseAndUpdateMemoryInfo(String processName, String showmapOutput)
-          throws RuntimeException {
-    try {
-      
-      // -------- -------- -------- -------- -------- -------- -------- -------- ----- ------ ----
-      // virtual                     shared   shared  private  private
-      //  size      RSS      PSS    clean    dirty    clean    dirty     swap  swapPSS flags object
-      // ------- -------- -------- -------- -------- -------- -------- -------- ------ -----  ----
-      //10810272     5400     1585     3800      168      264     1168        0        0      TOTAL
-      
-      int pos = showmapOutput.lastIndexOf("----");
-      String summarySplit[] = showmapOutput.substring(pos).trim().split("\\s+");
-
-      for (Map.Entry<Integer, String> entry : mMetricNameIndexMap.entrySet()) {
-          String metricKey = constructKey(String.format(OUTPUT_METRIC_PATTERN, entry.getValue()),
-                  processName);
-          // If there are multiple pids associated with the process name then update the
-          // existing entry in the map otherwise add new entry in the map.
-          if(mMemoryMap.containsKey(metricKey)) {
-              long currValue = Long.parseLong(mMemoryMap.get(metricKey));
-              mMemoryMap.put(metricKey, Long.toString(currValue +
-                      (Long.parseLong(summarySplit[entry.getKey() + 1]) * 1024)));
-          } else {
-              mMemoryMap.put(metricKey, Long.toString(Long.parseLong(
-                      summarySplit[entry.getKey() + 1]) * 1024));
-          }   
-      } 
-    } catch (IndexOutOfBoundsException | InputMismatchException e) {
-      throw new RuntimeException(
-          String.format("Unexpected showmap format for %s ", processName), e);
+    /**
+     * Executes showmap command for the process with {@code processName} name and {@code pid} pid.
+     *
+     * @param processName name of the process to run showmap for
+     * @param pid pid of the process to run showmap for
+     * @return the output of showmap command
+     */
+    private String execShowMap(String processName, long pid) throws IOException {
+        try {
+            return mUiDevice.executeShellCommand(String.format(SHOWMAP_CMD, pid));
+        } catch (IOException e) {
+            throw new RuntimeException(
+                    String.format("Unable to execute showmap command for %s ", processName), e);
+        }
     }
-  }
 
-  /**
-   * Store test results for one process into file.
-   *
-   * @param fileName name of the file being written
-   * @param processName name of the process
-   * @param pid pid of the process
-   * @param showmapOutput showmap command output
-   * @param writer file writer to write the data
-   */
-  private void storeToFile(String fileName, String processName, long pid, String showmapOutput,
-      FileWriter writer) throws RuntimeException {
-    try {
-      writer.write(String.format(">>> %s (%d) <<<\n", processName, pid));
-      writer.write(showmapOutput);
-      writer.write('\n');
-    } catch (IOException e) {
-      throw new RuntimeException(String.format("Unable to write file %s ", fileName), e);
+    /**
+     * Extract memory metrics from showmap command output for the process with {@code processName}
+     * name.
+     *
+     * @param processName name of the process to extract memory info for
+     * @param showmapOutput showmap command output
+     */
+    private void parseAndUpdateMemoryInfo(String processName, String showmapOutput)
+            throws RuntimeException {
+        try {
+
+            // -------- -------- -------- -------- -------- -------- -------- -------- ----- ------
+            // ----
+            // virtual shared shared private private
+            // size RSS PSS clean dirty clean dirty swap swapPSS flags object
+            // ------- -------- -------- -------- -------- -------- -------- -------- ------ -----
+            // ----
+            // 10810272 5400 1585 3800 168 264 1168 0 0 TOTAL
+
+            int pos = showmapOutput.lastIndexOf("----");
+            String summarySplit[] = showmapOutput.substring(pos).trim().split("\\s+");
+
+            for (Map.Entry<Integer, String> entry : mMetricNameIndexMap.entrySet()) {
+                String metricKey = constructKey(
+                        String.format(OUTPUT_METRIC_PATTERN, entry.getValue()),
+                        processName);
+                // If there are multiple pids associated with the process name then update the
+                // existing entry in the map otherwise add new entry in the map.
+                if (mMemoryMap.containsKey(metricKey)) {
+                    long currValue = Long.parseLong(mMemoryMap.get(metricKey));
+                    mMemoryMap.put(metricKey, Long.toString(currValue +
+                            (Long.parseLong(summarySplit[entry.getKey() + 1]) * 1024)));
+                } else {
+                    mMemoryMap.put(metricKey, Long.toString(Long.parseLong(
+                            summarySplit[entry.getKey() + 1]) * 1024));
+                }
+            }
+        } catch (IndexOutOfBoundsException | InputMismatchException e) {
+            throw new RuntimeException(
+                    String.format("Unexpected showmap format for %s ", processName), e);
+        }
     }
-  }
 
-  /**
-   * Set the memory metric name and corresponding index to parse from the showmap output summary.
-   * @param metricNameIndexStr comma separated metric_name:index
-   *
-   * TODO: Pre-process the string into map and pass the map to this method.
-   */
-  public void setMetricNameIndex(String metricNameIndexStr) {
-      Log.i(TAG, String.format("Metric Name index %s", metricNameIndexStr));
-      String metricDetails[] = metricNameIndexStr.split(",");
-      for (String metricDetail : metricDetails) {
-          String metricDetailsSplit[] = metricDetail.split(":");
-          if (metricDetailsSplit.length == 2) {
-              mMetricNameIndexMap.put(Integer.parseInt(
-                      metricDetailsSplit[1]), metricDetailsSplit[0]);
-          }
-      }
-      Log.i(TAG, String.format("Metric Name index map size %s", mMetricNameIndexMap.size()));
-  }
+    /**
+     * Store test results for one process into file.
+     *
+     * @param fileName name of the file being written
+     * @param processName name of the process
+     * @param pid pid of the process
+     * @param showmapOutput showmap command output
+     * @param writer file writer to write the data
+     */
+    private void storeToFile(String fileName, String processName, long pid, String showmapOutput,
+            FileWriter writer) throws RuntimeException {
+        try {
+            writer.write(String.format(">>> %s (%d) <<<\n", processName, pid));
+            writer.write(showmapOutput);
+            writer.write('\n');
+        } catch (IOException e) {
+            throw new RuntimeException(String.format("Unable to write file %s ", fileName), e);
+        }
+    }
 
-  /**
-   * Enables memory collection for all processes.
-   */
-  public void setAllProcesses() {
-      mCollectForAllProcesses = true;
-  }
+    /**
+     * Set the memory metric name and corresponding index to parse from the showmap output summary.
+     *
+     * @param metricNameIndexStr comma separated metric_name:index TODO: Pre-process the string into
+     *            map and pass the map to this method.
+     */
+    public void setMetricNameIndex(String metricNameIndexStr) {
+        Log.i(TAG, String.format("Metric Name index %s", metricNameIndexStr));
+        String metricDetails[] = metricNameIndexStr.split(",");
+        for (String metricDetail : metricDetails) {
+            String metricDetailsSplit[] = metricDetail.split(":");
+            if (metricDetailsSplit.length == 2) {
+                mMetricNameIndexMap.put(Integer.parseInt(
+                        metricDetailsSplit[1]), metricDetailsSplit[0]);
+            }
+        }
+        Log.i(TAG, String.format("Metric Name index map size %s", mMetricNameIndexMap.size()));
+    }
 
-  /**
-   * Get all process names running in the system.
-   */
-  private String[] getAllProcessNames() {
-      Set<String> allProcessNames = new LinkedHashSet<>();
-      try {
-          String psOutput = mUiDevice.executeShellCommand(ALL_PROCESSES_CMD);
-          // Split the lines
-          String allProcesses[] = psOutput.split("\\n");
-          for (String invidualProcessDetails : allProcesses) {
-              Log.i(TAG, String.format("Process detail: %s", invidualProcessDetails));
-              // Sample process detail line
-              // system         603     1   41532   5396 SyS_epoll+          0 S servicemanager
-              String processSplit[] = invidualProcessDetails.split("\\s+");
-              // Parse process name
-              String processName = processSplit[processSplit.length - 1].trim();
-              // Include the process name which are not enclosed in [].
-              if (!processName.startsWith("[") && !processName.endsWith("]")) {
-                  // Skip the first (i.e header) line from "ps -A" output.
-                  if (processName.equalsIgnoreCase("NAME")) {
-                      continue;
-                  }
-                  Log.i(TAG, String.format("Including the process %s", processName));
-                  allProcessNames.add(processName);
-              }
-          }
-      } catch (IOException ioe) {
-          throw new RuntimeException(
-                  String.format("Unable execute all processes command %s ", ALL_PROCESSES_CMD),
-                  ioe);
-      }
-      return allProcessNames.toArray(new String[0]);
-  }
+    /**
+     * Enables memory collection for all processes.
+     */
+    public void setAllProcesses() {
+        mCollectForAllProcesses = true;
+    }
+
+    /**
+     * Get all process names running in the system.
+     */
+    private String[] getAllProcessNames() {
+        Set<String> allProcessNames = new LinkedHashSet<>();
+        try {
+            String psOutput = mUiDevice.executeShellCommand(ALL_PROCESSES_CMD);
+            // Split the lines
+            String allProcesses[] = psOutput.split("\\n");
+            for (String invidualProcessDetails : allProcesses) {
+                Log.i(TAG, String.format("Process detail: %s", invidualProcessDetails));
+                // Sample process detail line
+                // system 603 1 41532 5396 SyS_epoll+ 0 S servicemanager
+                String processSplit[] = invidualProcessDetails.split("\\s+");
+                // Parse process name
+                String processName = processSplit[processSplit.length - 1].trim();
+                // Include the process name which are not enclosed in [].
+                if (!processName.startsWith("[") && !processName.endsWith("]")) {
+                    // Skip the first (i.e header) line from "ps -A" output.
+                    if (processName.equalsIgnoreCase("NAME")) {
+                        continue;
+                    }
+                    Log.i(TAG, String.format("Including the process %s", processName));
+                    allProcessNames.add(processName);
+                }
+            }
+        } catch (IOException ioe) {
+            throw new RuntimeException(
+                    String.format("Unable execute all processes command %s ", ALL_PROCESSES_CMD),
+                    ioe);
+        }
+        return allProcessNames.toArray(new String[0]);
+    }
 }
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 ca1218a..4743026 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
@@ -37,163 +37,168 @@
  */
 @RunWith(AndroidJUnit4.class)
 public class ShowmapSnapshotHelperTest {
-  private static final String TAG = ShowmapSnapshotHelperTest.class.getSimpleName();
+    private static final String TAG = ShowmapSnapshotHelperTest.class.getSimpleName();
 
-  // Valid output file
-  private static final String VALID_OUTPUT_DIR = "/sdcard/test_results";
-  // Invalid output file (no permissions to write)
-  private static final String INVALID_OUTPUT_DIR = "/data/local/tmp";
-  // Valid metric index string.
-  private static final String METRIC_INDEX_STR = "rss:1,pss:2";
-  // Invalid metric index string. Reverse order.
-  private static final String METRIC_INVALID_INDEX_STR = "1:pss";
-  // Empty metric index string.
-  private static final String METRIC_EMPTY_INDEX_STR = "";
+    // Valid output file
+    private static final String VALID_OUTPUT_DIR = "/sdcard/test_results";
+    // Invalid output file (no permissions to write)
+    private static final String INVALID_OUTPUT_DIR = "/data/local/tmp";
+    // Valid metric index string.
+    private static final String METRIC_INDEX_STR = "rss:1,pss:2";
+    // Invalid metric index string. Reverse order.
+    private static final String METRIC_INVALID_INDEX_STR = "1:pss";
+    // Empty metric index string.
+    private static final String METRIC_EMPTY_INDEX_STR = "";
 
-  // Lists of process names
-  private static final String[] EMPTY_PROCESS_LIST = {};
-  private static final String[] ONE_PROCESS_LIST = {"com.android.systemui"};
-  private static final String[] TWO_PROCESS_LIST = {"com.android.systemui", "system_server"};
-  private static final String[] NO_PROCESS_LIST = {null};
+    // Lists of process names
+    private static final String[] EMPTY_PROCESS_LIST = {};
+    private static final String[] ONE_PROCESS_LIST = {
+            "com.android.systemui"
+    };
+    private static final String[] TWO_PROCESS_LIST = {
+            "com.android.systemui", "system_server"
+    };
+    private static final String[] NO_PROCESS_LIST = {
+            null
+    };
 
-  private ShowmapSnapshotHelper mShowmapSnapshotHelper;
+    private ShowmapSnapshotHelper mShowmapSnapshotHelper;
 
-  @Before
-  public void setUp() {
-    mShowmapSnapshotHelper = new ShowmapSnapshotHelper();
-  }
-
-  /**
-   * Test start collecting returns false if the helper has not been properly set up.
-   */
-  @Test
-  public void testSetUpNotCalled() {
-    assertFalse(mShowmapSnapshotHelper.startCollecting());
-  }
-
-  /**
-   * Test invalid options for drop cache flag.
-   */
-  @Test
-  public void testInvalidDropCacheOptions() {
-    assertFalse(mShowmapSnapshotHelper.setDropCacheOption(-1));
-    assertFalse(mShowmapSnapshotHelper.setDropCacheOption(0));
-    assertFalse(mShowmapSnapshotHelper.setDropCacheOption(4));
-  }
-
-  /**
-   * Test invalid options for drop cache flag.
-   */
-  @Test
-  public void testValidDropCacheOptions() {
-    assertTrue(mShowmapSnapshotHelper.setDropCacheOption(1));
-    assertTrue(mShowmapSnapshotHelper.setDropCacheOption(2));
-    assertTrue(mShowmapSnapshotHelper.setDropCacheOption(3));
-  }
-
-  /**
-   * Test no metrics are sampled if process name is empty.
-   */
-  @Test
-  public void testEmptyProcessName() {
-    mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, EMPTY_PROCESS_LIST);
-    Map<String, String> metrics = mShowmapSnapshotHelper.getMetrics();
-    assertTrue(metrics.isEmpty());
-  }
-
-  /**
-   * Test sampling on a valid and running process.
-   */
-  @Test
-  public void testValidFile() {
-    mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, ONE_PROCESS_LIST);
-    assertTrue(mShowmapSnapshotHelper.startCollecting());
-  }
-
-  /**
-   * Test sampling on using an invalid output file.
-   */
-  @Test
-  public void testInvalidFile() {
-    mShowmapSnapshotHelper.setUp(INVALID_OUTPUT_DIR, ONE_PROCESS_LIST);
-    assertFalse(mShowmapSnapshotHelper.startCollecting());
-  }
-
-  /**
-   * Test getting metrics from one process.
-   */
-  @Test
-  public void testGetMetrics_OneProcess() {
-    testProcessList(METRIC_INDEX_STR, ONE_PROCESS_LIST);
-  }
-
-  /**
-   * Test getting metrics from multiple processes process.
-   */
-  @Test
-  public void testGetMetrics_MultipleProcesses() {
-    testProcessList(METRIC_INDEX_STR, TWO_PROCESS_LIST);
-  }
-
-  /**
-   * Test all process flag return more than 2 processes metrics atleast.
-   */
-  @Test
-  public void testGetMetrics_AllProcess() {
-    mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, NO_PROCESS_LIST);
-    mShowmapSnapshotHelper.setMetricNameIndex(METRIC_INDEX_STR);
-    mShowmapSnapshotHelper.setAllProcesses();
-    assertTrue(mShowmapSnapshotHelper.startCollecting());
-    Map<String, String> metrics = mShowmapSnapshotHelper.getMetrics();
-    assertTrue(metrics.size() > 2);
-    assertTrue(metrics.containsKey(ShowmapSnapshotHelper.OUTPUT_FILE_PATH_KEY));
-
-  }
-
-  @Test
-  public void testGetMetrics_Invalid_Metric_Pattern() {
-    mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, NO_PROCESS_LIST);
-    try {
-        mShowmapSnapshotHelper.setMetricNameIndex(METRIC_INVALID_INDEX_STR);
-        fail("Should have thrown an exception due to invalid pattern.");
-    } catch (Exception e) {
-        // No-op during the exception
+    @Before
+    public void setUp() {
+        mShowmapSnapshotHelper = new ShowmapSnapshotHelper();
     }
 
-    mShowmapSnapshotHelper.setAllProcesses();
-    assertTrue(mShowmapSnapshotHelper.startCollecting());
-    Map<String, String> metrics = mShowmapSnapshotHelper.getMetrics();
-    // process count and path to snapshot file in the output by default.
-    assertTrue(metrics.size() == 2);
-  }
-
-  @Test
-  public void testGetMetrics_Empty_Metric_Pattern() {
-    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();
-    // process count and path to snapshot file in the output by default.
-    assertTrue(metrics.size() == 2);
-  }
-
-
-  private void testProcessList(String metricIndexStr, String... processNames) {
-    mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, processNames);
-    mShowmapSnapshotHelper.setMetricNameIndex(metricIndexStr);
-    assertTrue(mShowmapSnapshotHelper.startCollecting());
-    Map<String, String> metrics = mShowmapSnapshotHelper.getMetrics();
-    assertFalse(metrics.isEmpty());
-    for (String processName : processNames) {
-      assertTrue(
-          metrics.containsKey(constructKey(String.format(
-                  ShowmapSnapshotHelper.OUTPUT_METRIC_PATTERN, "rss"), processName)));
-      assertTrue(
-              metrics.containsKey(constructKey(String.format(
-                      ShowmapSnapshotHelper.OUTPUT_METRIC_PATTERN, "pss"), processName)));
+    /**
+     * Test start collecting returns false if the helper has not been properly set up.
+     */
+    @Test
+    public void testSetUpNotCalled() {
+        assertFalse(mShowmapSnapshotHelper.startCollecting());
     }
-    assertTrue(metrics.containsKey(ShowmapSnapshotHelper.OUTPUT_FILE_PATH_KEY));
-  }
+
+    /**
+     * Test invalid options for drop cache flag.
+     */
+    @Test
+    public void testInvalidDropCacheOptions() {
+        assertFalse(mShowmapSnapshotHelper.setDropCacheOption(-1));
+        assertFalse(mShowmapSnapshotHelper.setDropCacheOption(0));
+        assertFalse(mShowmapSnapshotHelper.setDropCacheOption(4));
+    }
+
+    /**
+     * Test invalid options for drop cache flag.
+     */
+    @Test
+    public void testValidDropCacheOptions() {
+        assertTrue(mShowmapSnapshotHelper.setDropCacheOption(1));
+        assertTrue(mShowmapSnapshotHelper.setDropCacheOption(2));
+        assertTrue(mShowmapSnapshotHelper.setDropCacheOption(3));
+    }
+
+    /**
+     * Test no metrics are sampled if process name is empty.
+     */
+    @Test
+    public void testEmptyProcessName() {
+        mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, EMPTY_PROCESS_LIST);
+        Map<String, String> metrics = mShowmapSnapshotHelper.getMetrics();
+        assertTrue(metrics.isEmpty());
+    }
+
+    /**
+     * Test sampling on a valid and running process.
+     */
+    @Test
+    public void testValidFile() {
+        mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, ONE_PROCESS_LIST);
+        assertTrue(mShowmapSnapshotHelper.startCollecting());
+    }
+
+    /**
+     * Test sampling on using an invalid output file.
+     */
+    @Test
+    public void testInvalidFile() {
+        mShowmapSnapshotHelper.setUp(INVALID_OUTPUT_DIR, ONE_PROCESS_LIST);
+        assertFalse(mShowmapSnapshotHelper.startCollecting());
+    }
+
+    /**
+     * Test getting metrics from one process.
+     */
+    @Test
+    public void testGetMetrics_OneProcess() {
+        testProcessList(METRIC_INDEX_STR, ONE_PROCESS_LIST);
+    }
+
+    /**
+     * Test getting metrics from multiple processes process.
+     */
+    @Test
+    public void testGetMetrics_MultipleProcesses() {
+        testProcessList(METRIC_INDEX_STR, TWO_PROCESS_LIST);
+    }
+
+    /**
+     * Test all process flag return more than 2 processes metrics atleast.
+     */
+    @Test
+    public void testGetMetrics_AllProcess() {
+        mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, NO_PROCESS_LIST);
+        mShowmapSnapshotHelper.setMetricNameIndex(METRIC_INDEX_STR);
+        mShowmapSnapshotHelper.setAllProcesses();
+        assertTrue(mShowmapSnapshotHelper.startCollecting());
+        Map<String, String> metrics = mShowmapSnapshotHelper.getMetrics();
+        assertTrue(metrics.size() > 2);
+        assertTrue(metrics.containsKey(ShowmapSnapshotHelper.OUTPUT_FILE_PATH_KEY));
+
+    }
+
+    @Test
+    public void testGetMetrics_Invalid_Metric_Pattern() {
+        mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, NO_PROCESS_LIST);
+        try {
+            mShowmapSnapshotHelper.setMetricNameIndex(METRIC_INVALID_INDEX_STR);
+            fail("Should have thrown an exception due to invalid pattern.");
+        } catch (Exception e) {
+            // No-op during the exception
+        }
+
+        mShowmapSnapshotHelper.setAllProcesses();
+        assertTrue(mShowmapSnapshotHelper.startCollecting());
+        Map<String, String> metrics = mShowmapSnapshotHelper.getMetrics();
+        // process count and path to snapshot file in the output by default.
+        assertTrue(metrics.size() == 2);
+    }
+
+    @Test
+    public void testGetMetrics_Empty_Metric_Pattern() {
+        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();
+        // process count and path to snapshot file in the output by default.
+        assertTrue(metrics.size() == 2);
+    }
+
+    private void testProcessList(String metricIndexStr, String... processNames) {
+        mShowmapSnapshotHelper.setUp(VALID_OUTPUT_DIR, processNames);
+        mShowmapSnapshotHelper.setMetricNameIndex(metricIndexStr);
+        assertTrue(mShowmapSnapshotHelper.startCollecting());
+        Map<String, String> metrics = mShowmapSnapshotHelper.getMetrics();
+        assertFalse(metrics.isEmpty());
+        for (String processName : processNames) {
+            assertTrue(
+                    metrics.containsKey(constructKey(String.format(
+                            ShowmapSnapshotHelper.OUTPUT_METRIC_PATTERN, "rss"), processName)));
+            assertTrue(
+                    metrics.containsKey(constructKey(String.format(
+                            ShowmapSnapshotHelper.OUTPUT_METRIC_PATTERN, "pss"), processName)));
+        }
+        assertTrue(metrics.containsKey(ShowmapSnapshotHelper.OUTPUT_FILE_PATH_KEY));
+    }
 }