Skip to content

Instantly share code, notes, and snippets.

@ckhung
Last active December 3, 2021 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckhung/501bac5587ae5f5f1b7f80cca5b3b83f to your computer and use it in GitHub Desktop.
Save ckhung/501bac5587ae5f5f1b7f80cca5b3b83f to your computer and use it in GitHub Desktop.
print android app size as .csv: adb shell dumpsys diskstats | aasize.py
#!/usr/bin/python3
# https://newtoypia.blogspot.com/2021/05/android-app-size.html
# 揪出手機上的腫脹軟體: android app 佔用空間大小散點圖
import argparse, fileinput, re, json
parser = argparse.ArgumentParser(
description='print android app size as .csv: adb shell dumpsys diskstats | aasize.py',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('files', nargs='*', help='files')
args = parser.parse_args()
info = ''
for line in fileinput.input(files=args.files if len(args.files) > 0 else ('-', )):
if not re.search(r':\s*\[.*\]', line):
line = re.sub(r':\s*(\S.*\S)', r': "\1"', line)
if line.find(':') >= 0:
line = re.sub(r'(\S.*?\S)\s*:', r'"\1":', line)
else:
line = re.sub(r'(\S.*?\S)\s*=', r'"\1":', line)
line = line[:-1] + ','
info += line
info = '{' + info[:-1] + '}'
info = json.loads(info)
print('{:>12s}, {:>12s}, {:>12s}, {:12s}, {}'.format(
'App',
'Data',
'Cache',
'Name',
'FullName',
) )
for i in range(len(info['Package Names'])):
FullName = info['Package Names'][i]
if FullName.find('com.android.theme') == 0:
name = 'theme'
else:
m = re.search(r'\.(\w+)$', FullName)
if m:
name = m.group(1)
else:
assert FullName == 'android'
name = FullName
print('{:12d}, {:12d}, {:12d}, {:12s}, {}'.format(
info['App Sizes'][i],
info['App Data Sizes'][i],
info['Cache Sizes'][i],
name,
FullName
) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment