Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015, Google, Inc. | |
| 2 # | |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 # you may not use this file except in compliance with the License. | |
| 5 # You may obtain a copy of the License at | |
| 6 # | |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 # | |
| 9 # Unless required by applicable law or agreed to in writing, software | |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 # See the License for the specific language governing permissions and | |
| 13 # limitations under the License. | |
| 14 | |
| 15 | |
| 16 import operator | |
| 17 | |
| 18 | |
| 19 def ExtractBits(val, offset_in_bits, size_in_bits): | |
|
Mark Seaborn
2015/07/01 19:21:23
Not used; can be removed.
ruiq
2015/07/01 20:42:59
Done.
| |
| 20 return [(val >> offset_in_bits) & ((1 << size_in_bits) - 1), | |
| 21 size_in_bits] | |
| 22 | |
| 23 | |
| 24 def GetResultPfns(log_filename): | |
| 25 for line in open(log_filename): | |
| 26 parts = line.strip('\n')[:-1].split(' '); | |
| 27 yield [int(part, 16) for part in parts] | |
| 28 | |
| 29 | |
| 30 def Main(): | |
| 31 counter = 0 | |
|
Mark Seaborn
2015/07/01 19:21:23
Not used
ruiq
2015/07/01 20:42:59
Done.
| |
| 32 cont_count = {} | |
| 33 for pfns in GetResultPfns('physmem_alloc_results'): | |
| 34 i1 = 0 | |
| 35 i2 = 0 | |
| 36 while i2 < len(pfns): | |
| 37 while i2 + 1 < len(pfns) and pfns[i2+1] - pfns[i2] == 1: | |
| 38 i2 += 1 | |
| 39 size = i2 - i1 + 1 | |
| 40 cont_count.setdefault(size, 0) | |
| 41 cont_count[size] += 1 | |
| 42 i2 += 1 | |
| 43 i1 = i2 | |
| 44 | |
| 45 total_pages = 0 | |
| 46 for size, count in cont_count.iteritems(): | |
| 47 total_pages += size * count | |
| 48 cont_fraction = {} | |
|
Mark Seaborn
2015/07/01 19:21:22
I don't think you need to build another dict for t
ruiq
2015/07/01 20:42:59
Done.
| |
| 49 for size, count in cont_count.iteritems(): | |
| 50 cont_fraction[size] = 1.0 * size * count / total_pages | |
| 51 | |
| 52 sorted_by_size = sorted(cont_fraction.items(), key=operator.itemgetter(0)) | |
|
Mark Seaborn
2015/07/01 19:21:22
Note that this is equivalent to:
sorted_by_size =
ruiq
2015/07/01 20:42:59
Done.
| |
| 53 for size, fraction in sorted_by_size: | |
| 54 count = cont_count[size] | |
| 55 size_total = size * count | |
| 56 print "%10d %10d %10d %10.2f" % (size, count, size_total, fraction) | |
|
Mark Seaborn
2015/07/01 19:21:22
Nit: be consistent about whether you use ' or " fo
ruiq
2015/07/01 20:42:59
Done.
| |
| 57 | |
| 58 | |
| 59 if __name__ == '__main__': | |
| 60 Main() | |
| OLD | NEW |