Factorize out print-dexsegments to utils, enable for other scripts:

Enable for run_on_app and run_proguard_dx_on_gmscore.

Bug:
Change-Id: I7dfe7272c42e9bc879032b44612daa404b64d266
diff --git a/tools/test_framework.py b/tools/test_framework.py
index 57279bf..04a12d3 100755
--- a/tools/test_framework.py
+++ b/tools/test_framework.py
@@ -35,9 +35,6 @@
     'goyt_160525751')
 FRAMEWORK_JAR = os.path.join('third_party', 'framework',
     'framework_160115954.jar')
-DEX_SEGMENTS_JAR = os.path.join(utils.REPO_ROOT, 'build', 'libs',
-    'dexsegments.jar')
-DEX_SEGMENTS_RESULT_PATTERN = re.compile('- ([^:]+): ([0-9]+)')
 MIN_SDK_VERSION = '24'
 
 def parse_arguments():
@@ -61,27 +58,6 @@
       action = 'store_true')
   return parser.parse_args()
 
-# Return a dictionary: {segment_name -> segments_size}
-def getDexSegmentSizes(dex_files):
-  assert len(dex_files) > 0
-  cmd = ['java', '-jar', DEX_SEGMENTS_JAR]
-  cmd.extend(dex_files)
-  utils.PrintCmd(cmd)
-  output = subprocess.check_output(cmd)
-
-  matches = DEX_SEGMENTS_RESULT_PATTERN.findall(output)
-
-  if matches is None or len(matches) == 0:
-    raise Exception('DexSegments failed to return any output for' \
-        ' these files: {}'.format(dex_files))
-
-  result = {}
-
-  for match in matches:
-    result[match[0]] = int(match[1])
-
-  return result
-
 def Main():
   args = parse_arguments()
 
@@ -136,9 +112,7 @@
     print('{}-Total(CodeSize): {}'
       .format(args.name, code_size))
 
-    for segment_name, size in getDexSegmentSizes(dex_files).items():
-      print('{}-{}(CodeSize): {}'
-          .format(args.name, segment_name, size))
+    utils.print_dexsegments(args.name, dex_files)
 
 if __name__ == '__main__':
   sys.exit(Main())