OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 # based on an almost identical script by: jyrki@google.com (Jyrki Alakuijala) | |
6 # | |
7 # This script prints out include dependencies in chrome. Since it ignores | |
8 # defines, it gives just a rough estimation of file size. | |
9 # | |
10 # Usage: | |
11 # python tools/include_tracer.py chrome/browser/ui/browser.h | |
12 | |
13 import os | |
14 import sys | |
15 | |
16 # Created by copying the command line for prerender_browsertest.cc, replacing | |
17 # spaces with newlines, and dropping everything except -F and -I switches. | |
18 # TODO(port): Add windows, linux directories. | |
19 INCLUDE_PATHS = [ | |
20 '', | |
21 'gpu', | |
22 'skia/config', | |
23 'skia/ext', | |
24 'testing/gmock/include', | |
25 'testing/gtest/include', | |
26 'third_party/GTM', | |
27 'third_party/WebKit/Source', | |
28 'third_party/WebKit/Source/JavaScriptCore', | |
29 'third_party/WebKit/Source/JavaScriptCore/wtf', | |
30 'third_party/WebKit/Source/ThirdParty/glu', | |
31 'third_party/WebKit/Source/WebCore', | |
32 'third_party/WebKit/Source/WebCore/accessibility', | |
33 'third_party/WebKit/Source/WebCore/accessibility/chromium', | |
34 'third_party/WebKit/Source/WebCore/bindings', | |
35 'third_party/WebKit/Source/WebCore/bindings/generic', | |
36 'third_party/WebKit/Source/WebCore/bindings/v8', | |
37 'third_party/WebKit/Source/WebCore/bindings/v8/custom', | |
38 'third_party/WebKit/Source/WebCore/bindings/v8/specialization', | |
39 'third_party/WebKit/Source/WebCore/bridge', | |
40 'third_party/WebKit/Source/WebCore/bridge/jni', | |
41 'third_party/WebKit/Source/WebCore/bridge/jni/v8', | |
42 'third_party/WebKit/Source/WebCore/css', | |
43 'third_party/WebKit/Source/WebCore/dom', | |
44 'third_party/WebKit/Source/WebCore/dom/default', | |
45 'third_party/WebKit/Source/WebCore/editing', | |
46 'third_party/WebKit/Source/WebCore/fileapi', | |
47 'third_party/WebKit/Source/WebCore/history', | |
48 'third_party/WebKit/Source/WebCore/html', | |
49 'third_party/WebKit/Source/WebCore/html/canvas', | |
50 'third_party/WebKit/Source/WebCore/html/parser', | |
51 'third_party/WebKit/Source/WebCore/html/shadow', | |
52 'third_party/WebKit/Source/WebCore/inspector', | |
53 'third_party/WebKit/Source/WebCore/loader', | |
54 'third_party/WebKit/Source/WebCore/loader/appcache', | |
55 'third_party/WebKit/Source/WebCore/loader/archive', | |
56 'third_party/WebKit/Source/WebCore/loader/cache', | |
57 'third_party/WebKit/Source/WebCore/loader/icon', | |
58 'third_party/WebKit/Source/WebCore/mathml', | |
59 'third_party/WebKit/Source/WebCore/notifications', | |
60 'third_party/WebKit/Source/WebCore/page', | |
61 'third_party/WebKit/Source/WebCore/page/animation', | |
62 'third_party/WebKit/Source/WebCore/page/chromium', | |
63 'third_party/WebKit/Source/WebCore/platform', | |
64 'third_party/WebKit/Source/WebCore/platform/animation', | |
65 'third_party/WebKit/Source/WebCore/platform/audio', | |
66 'third_party/WebKit/Source/WebCore/platform/audio/chromium', | |
67 'third_party/WebKit/Source/WebCore/platform/audio/mac', | |
68 'third_party/WebKit/Source/WebCore/platform/chromium', | |
69 'third_party/WebKit/Source/WebCore/platform/cocoa', | |
70 'third_party/WebKit/Source/WebCore/platform/graphics', | |
71 'third_party/WebKit/Source/WebCore/platform/graphics/cg', | |
72 'third_party/WebKit/Source/WebCore/platform/graphics/chromium', | |
73 'third_party/WebKit/Source/WebCore/platform/graphics/cocoa', | |
74 'third_party/WebKit/Source/WebCore/platform/graphics/filters', | |
75 'third_party/WebKit/Source/WebCore/platform/graphics/gpu', | |
76 'third_party/WebKit/Source/WebCore/platform/graphics/mac', | |
77 'third_party/WebKit/Source/WebCore/platform/graphics/opentype', | |
78 'third_party/WebKit/Source/WebCore/platform/graphics/skia', | |
79 'third_party/WebKit/Source/WebCore/platform/graphics/transforms', | |
80 'third_party/WebKit/Source/WebCore/platform/image-decoders', | |
81 'third_party/WebKit/Source/WebCore/platform/image-decoders/bmp', | |
82 'third_party/WebKit/Source/WebCore/platform/image-decoders/gif', | |
83 'third_party/WebKit/Source/WebCore/platform/image-decoders/ico', | |
84 'third_party/WebKit/Source/WebCore/platform/image-decoders/jpeg', | |
85 'third_party/WebKit/Source/WebCore/platform/image-decoders/png', | |
86 'third_party/WebKit/Source/WebCore/platform/image-decoders/skia', | |
87 'third_party/WebKit/Source/WebCore/platform/image-decoders/webp', | |
88 'third_party/WebKit/Source/WebCore/platform/image-decoders/xbm', | |
89 'third_party/WebKit/Source/WebCore/platform/image-encoders/skia', | |
90 'third_party/WebKit/Source/WebCore/platform/mac', | |
91 'third_party/WebKit/Source/WebCore/platform/mock', | |
92 'third_party/WebKit/Source/WebCore/platform/network', | |
93 'third_party/WebKit/Source/WebCore/platform/network/chromium', | |
94 'third_party/WebKit/Source/WebCore/platform/sql', | |
95 'third_party/WebKit/Source/WebCore/platform/text', | |
96 'third_party/WebKit/Source/WebCore/platform/text/mac', | |
97 'third_party/WebKit/Source/WebCore/platform/text/transcoder', | |
98 'third_party/WebKit/Source/WebCore/plugins', | |
99 'third_party/WebKit/Source/WebCore/plugins/chromium', | |
100 'third_party/WebKit/Source/WebCore/rendering', | |
101 'third_party/WebKit/Source/WebCore/rendering/style', | |
102 'third_party/WebKit/Source/WebCore/rendering/svg', | |
103 'third_party/WebKit/Source/WebCore/storage', | |
104 'third_party/WebKit/Source/WebCore/storage/chromium', | |
105 'third_party/WebKit/Source/WebCore/svg', | |
106 'third_party/WebKit/Source/WebCore/svg/animation', | |
107 'third_party/WebKit/Source/WebCore/svg/graphics', | |
108 'third_party/WebKit/Source/WebCore/svg/graphics/filters', | |
109 'third_party/WebKit/Source/WebCore/svg/properties', | |
110 'third_party/WebKit/Source/WebCore/webaudio', | |
111 'third_party/WebKit/Source/WebCore/websockets', | |
112 'third_party/WebKit/Source/WebCore/workers', | |
113 'third_party/WebKit/Source/WebCore/xml', | |
114 'third_party/WebKit/Source/WebKit/chromium/public', | |
115 'third_party/WebKit/Source/WebKit/chromium/src', | |
116 'third_party/WebKit/Source/WebKit/mac/WebCoreSupport', | |
117 'third_party/WebKit/WebKitLibraries', | |
118 'third_party/cld', | |
119 'third_party/icu/public/common', | |
120 'third_party/icu/public/i18n', | |
121 'third_party/npapi', | |
122 'third_party/npapi/bindings', | |
123 'third_party/protobuf', | |
124 'third_party/protobuf/src', | |
125 'third_party/skia/gpu/include', | |
126 'third_party/skia/include/config', | |
127 'third_party/skia/include/core', | |
128 'third_party/skia/include/effects', | |
129 'third_party/skia/include/gpu', | |
130 'third_party/skia/include/pdf', | |
131 'third_party/skia/include/ports', | |
132 'v8/include', | |
133 'xcodebuild/Debug/include', | |
134 'xcodebuild/DerivedSources/Debug/chrome', | |
135 'xcodebuild/DerivedSources/Debug/policy', | |
136 'xcodebuild/DerivedSources/Debug/protoc_out', | |
137 'xcodebuild/DerivedSources/Debug/webkit', | |
138 'xcodebuild/DerivedSources/Debug/webkit/bindings', | |
139 ] | |
140 | |
141 | |
142 def Walk(seen, filename, parent, indent): | |
143 """Returns the size of |filename| plus the size of all files included by | |
144 |filename| and prints the include tree of |filename| to stdout. Every file | |
145 is visited at most once. | |
146 """ | |
147 total_bytes = 0 | |
148 | |
149 # .proto(devel) filename translation | |
150 if filename.endswith('.pb.h'): | |
151 basename = filename[:-5] | |
152 if os.path.exists(basename + '.proto'): | |
153 filename = basename + '.proto' | |
154 else: | |
155 print 'could not find ', filename | |
156 | |
157 # Show and count files only once. | |
158 if filename in seen: | |
159 return total_bytes | |
160 seen.add(filename) | |
161 | |
162 # Display the paths. | |
163 print ' ' * indent + filename | |
164 | |
165 # Skip system includes. | |
166 if filename[0] == '<': | |
167 return total_bytes | |
168 | |
169 # Find file in all include paths. | |
170 resolved_filename = filename | |
171 for root in INCLUDE_PATHS + [os.path.dirname(parent)]: | |
172 if os.path.exists(os.path.join(root, filename)): | |
173 resolved_filename = os.path.join(root, filename) | |
174 break | |
175 | |
176 # Recurse. | |
177 if os.path.exists(resolved_filename): | |
178 lines = open(resolved_filename).readlines() | |
179 else: | |
180 print ' ' * (indent + 2) + "-- not found" | |
181 lines = [] | |
182 for line in lines: | |
183 line = line.strip() | |
184 if line.startswith('#include "'): | |
185 total_bytes += Walk( | |
186 seen, line.split('"')[1], resolved_filename, indent + 2) | |
187 elif line.startswith('#include '): | |
188 include = '<' + line.split('<')[1].split('>')[0] + '>' | |
189 total_bytes += Walk( | |
190 seen, include, resolved_filename, indent + 2) | |
191 elif line.startswith('import '): | |
192 total_bytes += Walk( | |
193 seen, line.split('"')[1], resolved_filename, indent + 2) | |
194 return total_bytes + len("".join(lines)) | |
195 | |
196 | |
197 bytes = Walk(set(), sys.argv[1], '', 0) | |
viettrungluu
2011/04/19 00:16:30
Is it so hard to iterate over the arguments, so pe
| |
198 print | |
199 print float(bytes) / (1 << 20), "megabytes of chrome source" | |
OLD | NEW |