Include total_pss and total_rss in startup metrics

Bug: b/242498457
Change-Id: I3d2506412449eaea3fad701aa70db7986ebac03f
diff --git a/tools/apk_utils.py b/tools/apk_utils.py
index 906284e..f126f91 100755
--- a/tools/apk_utils.py
+++ b/tools/apk_utils.py
@@ -56,7 +56,7 @@
   zipalign_path = (
       'zipalign' if 'build_tools' in os.environ.get('PATH')
       else os.path.join(utils.getAndroidBuildTools(), 'zipalign'))
-  cmd = [zipalign_path, '-f', '4', apk, aligned_apk]
+  cmd = [zipalign_path, '-f', '-p', '4', apk, aligned_apk]
   utils.RunCmd(cmd, quiet=True, logging=False)
   return aligned_apk
 
diff --git a/tools/startup/adb_utils.py b/tools/startup/adb_utils.py
index c181682..a376018 100755
--- a/tools/startup/adb_utils.py
+++ b/tools/startup/adb_utils.py
@@ -156,6 +156,19 @@
   else:
     return '%s/%s' % (app_id, activity)
 
+def get_meminfo(app_id, device_id=None):
+  cmd = create_adb_cmd('shell dumpsys meminfo -s %s' % app_id, device_id)
+  stdout = subprocess.check_output(cmd).decode('utf-8').strip()
+  for line in stdout.splitlines():
+    if 'TOTAL PSS: ' in line:
+      elements = [s for s in line.replace('TOTAL ', 'TOTAL_').split()]
+      assert elements[0] == 'TOTAL_PSS:', elements[0]
+      assert elements[1].isdigit()
+      assert elements[2] == 'TOTAL_RSS:'
+      assert elements[3].isdigit()
+      return { 'total_pss': int(elements[1]), 'total_rss': int(elements[3]) }
+  raise ValueError('Unexpected stdout: %s' % stdout)
+
 def get_profile_data(app_id, device_id=None):
   with utils.TempDir() as temp:
     source = get_profile_path(app_id)
diff --git a/tools/startup/measure_startup.py b/tools/startup/measure_startup.py
index ef529b6..1b94fad 100755
--- a/tools/startup/measure_startup.py
+++ b/tools/startup/measure_startup.py
@@ -245,12 +245,14 @@
 def compute_data(launch_activity_result, logcat, perfetto_trace_path, options):
   minfl, majfl = adb_utils.get_minor_major_page_faults(
       options.app_id, options.device_id)
+  meminfo = adb_utils.get_meminfo(options.app_id, options.device_id)
   data = {
     'app_id': options.app_id,
     'time': time.ctime(time.time()),
     'minfl': minfl,
     'majfl': majfl
   }
+  data.update(meminfo)
   startup_data = compute_startup_data(
       launch_activity_result, logcat, perfetto_trace_path, options)
   return data | startup_data