Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Unified Diff: build/android/resource_sizes.py

Issue 2692933004: Print pak sizes on a per-header basis in resource_sizes.py (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/resource_sizes.py
diff --git a/build/android/resource_sizes.py b/build/android/resource_sizes.py
index c6c015f7b6e5ae9387957760681ddef49c6bdef6..81ecfd91ed75cb501e370166d2534c602ba09e61 100755
--- a/build/android/resource_sizes.py
+++ b/build/android/resource_sizes.py
@@ -520,23 +520,41 @@ def PrintPakAnalysis(apk_filename, min_pak_resource_size):
total_resource_size)
print
- resource_id_name_map = _GetResourceIdNameMap()
+ resource_id_name_map, resources_id_header_map = _AnnotatePakResources()
# Output the table of details about all resources across pak files.
print
print '%56s %5s %17s' % ('RESOURCE', 'COUNT', 'UNCOMPRESSED SIZE')
for i in sorted(resource_size_map, key=resource_size_map.get,
reverse=True):
- if resource_size_map[i] >= min_pak_resource_size:
- print '%56s %5s %9s %6.2f%%' % (
- resource_id_name_map.get(i, i),
- resource_count_map[i],
- _FormatBytes(resource_size_map[i]),
- 100.0 * resource_size_map[i] / total_resource_size)
+ if resource_size_map[i] < min_pak_resource_size:
+ break
+ print '%56s %5s %9s %6.2f%%' % (
+ resource_id_name_map.get(i, i),
+ resource_count_map[i],
+ _FormatBytes(resource_size_map[i]),
+ 100.0 * resource_size_map[i] / total_resource_size)
-def _GetResourceIdNameMap():
- """Returns a map of {resource_id: resource_name}."""
+ # Print breakdown on a per-grd file basis.
+ size_by_header = collections.defaultdict(int)
+ for resid, size in resource_size_map.iteritems():
+ size_by_header[resources_id_header_map.get(resid, 'unknown')] += size
+
+ print
+ print '%80s %17s' % ('HEADER', 'UNCOMPRESSED SIZE')
+ for header in sorted(size_by_header, key=size_by_header.get, reverse=True):
+ if size_by_header[header] < min_pak_resource_size:
+ break
+
+ print '%80s %9s %6.2f%%' % (
+ header,
+ _FormatBytes(size_by_header[header]),
+ 100.0 * size_by_header[header] / total_resource_size)
+
+
+def _AnnotatePakResources():
+ """Returns a pair of maps: id_name_map, id_header_map."""
out_dir = constants.GetOutDirectory()
assert os.path.isdir(out_dir), 'Failed to locate out dir at %s' % out_dir
print 'Looking at resources in: %s' % out_dir
@@ -548,6 +566,7 @@ def _GetResourceIdNameMap():
assert grit_headers, 'Failed to find grit headers in %s' % out_dir
id_name_map = {}
+ id_header_map = {}
for header in grit_headers:
with open(header, 'r') as f:
for line in f.readlines():
@@ -559,7 +578,8 @@ def _GetResourceIdNameMap():
print 'WARNING: Resource ID conflict %s (%s vs %s)' % (
i, id_name_map[i], name)
id_name_map[i] = name
- return id_name_map
+ id_header_map[i] = os.path.relpath(header, out_dir)
+ return id_name_map, id_header_map
def _PrintStaticInitializersCountFromApk(apk_filename, chartjson=None):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698