diff options
author | Tiancong Wang <tcwang@google.com> | 2020-02-13 21:08:49 +0000 |
---|---|---|
committer | Tiancong Wang <tcwang@google.com> | 2020-02-13 21:08:49 +0000 |
commit | b75f321fc8978b92ce3db6886ccb966768f0c7a8 (patch) | |
tree | 35fa0fbaeaaddd9cc2a126a05eee3527b51e83a8 /heatmaps/heatmap_generator.py | |
parent | cddd960b0ba2eb62c372c0d3176c75f0bd05d5e8 (diff) | |
parent | e617e3393dd24003aa976ece5050bb291070041c (diff) | |
download | toolchain-utils-b75f321fc8978b92ce3db6886ccb966768f0c7a8.tar.gz |
Merging 18 commit(s) from Chromium's toolchain-utils am: 0ae38c8498 am: 2a19d36a82 am: e617e3393dr_aml_301500702android-mainline-12.0.0_r55android-mainline-11.0.0_r9android-mainline-11.0.0_r8android-mainline-11.0.0_r7android-mainline-11.0.0_r6android-mainline-11.0.0_r5android-mainline-11.0.0_r45android-mainline-11.0.0_r44android-mainline-11.0.0_r43android-mainline-11.0.0_r42android-mainline-11.0.0_r41android-mainline-11.0.0_r40android-mainline-11.0.0_r4android-mainline-11.0.0_r39android-mainline-11.0.0_r38android-mainline-11.0.0_r37android-mainline-11.0.0_r36android-mainline-11.0.0_r35android-mainline-11.0.0_r34android-mainline-11.0.0_r33android-mainline-11.0.0_r32android-mainline-11.0.0_r31android-mainline-11.0.0_r30android-mainline-11.0.0_r3android-mainline-11.0.0_r29android-mainline-11.0.0_r28android-mainline-11.0.0_r27android-mainline-11.0.0_r26android-mainline-11.0.0_r25android-mainline-11.0.0_r24android-mainline-11.0.0_r23android-mainline-11.0.0_r22android-mainline-11.0.0_r21android-mainline-11.0.0_r20android-mainline-11.0.0_r2android-mainline-11.0.0_r19android-mainline-11.0.0_r18android-mainline-11.0.0_r17android-mainline-11.0.0_r16android-mainline-11.0.0_r15android-mainline-11.0.0_r14android-mainline-11.0.0_r13android-mainline-11.0.0_r12android-mainline-11.0.0_r10android-mainline-11.0.0_r1android-11.0.0_r48android-11.0.0_r47android-11.0.0_r46android-11.0.0_r45android-11.0.0_r44android-11.0.0_r43android-11.0.0_r42android-11.0.0_r41android-11.0.0_r40android-11.0.0_r39android-11.0.0_r38android-11.0.0_r37android-11.0.0_r36android-11.0.0_r35android-11.0.0_r34android-11.0.0_r33android-11.0.0_r32android-11.0.0_r31android-11.0.0_r30android-11.0.0_r29android-11.0.0_r28android-11.0.0_r27android-11.0.0_r26android-11.0.0_r24android-11.0.0_r23android-11.0.0_r22android-11.0.0_r21android-11.0.0_r20android-11.0.0_r19android-11.0.0_r18android-11.0.0_r16android11-qpr3-s1-releaseandroid11-qpr3-releaseandroid11-qpr2-releaseandroid11-qpr1-s2-releaseandroid11-qpr1-s1-releaseandroid11-qpr1-releaseandroid11-qpr1-d-s1-releaseandroid11-qpr1-d-releaseandroid11-qpr1-c-releaseandroid11-mainline-tethering-releaseandroid11-mainline-sparse-2021-jan-releaseandroid11-mainline-sparse-2020-dec-releaseandroid11-mainline-releaseandroid11-mainline-permission-releaseandroid11-mainline-os-statsd-releaseandroid11-mainline-networkstack-releaseandroid11-mainline-media-swcodec-releaseandroid11-mainline-media-releaseandroid11-mainline-extservices-releaseandroid11-mainline-documentsui-releaseandroid11-mainline-conscrypt-releaseandroid11-mainline-cellbroadcast-releaseandroid11-mainline-captiveportallogin-releaseandroid11-devandroid11-d2-releaseandroid11-d1-b-release
Change-Id: I3f25c7ee034b2e20e37ed941b8eae24eec7043eb
Diffstat (limited to 'heatmaps/heatmap_generator.py')
-rw-r--r-- | heatmaps/heatmap_generator.py | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/heatmaps/heatmap_generator.py b/heatmaps/heatmap_generator.py index 42fd6352..0dd6ad28 100644 --- a/heatmaps/heatmap_generator.py +++ b/heatmaps/heatmap_generator.py @@ -13,7 +13,7 @@ performed by another script perf-to-inst-page.sh). It can also analyze the symbol names in hot pages. """ -from __future__ import print_function +from __future__ import division, print_function import bisect import collections @@ -93,10 +93,10 @@ class HeatmapGenerator(object): self.max_addr = 1024 * 1024 * 1024 self.ce = command_executer.GetCommandExecuter(log_level=log_level) self.dir = os.path.dirname(os.path.realpath(__file__)) - with open(perf_report) as f: + with open(perf_report, 'r', encoding='utf-8') as f: self.perf_report_contents = f.readlines() # Write histogram results to a text file, in order to use gnu plot to draw - self.hist_temp_output = open('out.txt', 'w') + self.hist_temp_output = open('out.txt', 'w', encoding='utf-8') self.processes = {} self.deleted_processes = {} self.count = 0 @@ -277,7 +277,7 @@ class HeatmapGenerator(object): if address < self.max_addr: self.count += 1 line = '%d/%d: %d %d' % (pid[0], pid[1], self.count, - address / self.page_size * self.page_size) + address // self.page_size * self.page_size) if self.hugepage: if self.hugepage.start <= address < self.hugepage.end: line += ' hugepage' @@ -321,7 +321,7 @@ class HeatmapGenerator(object): names = [x for x in os.listdir('.') if 'inst-histo' in x and '.txt' in x] hist = {} for n in names: - with open(n) as f: + with open(n, encoding='utf-8') as f: for l in f.readlines(): num, addr = l.strip().split(' ') assert int(addr) not in hist @@ -354,7 +354,7 @@ class HeatmapGenerator(object): if 't' not in symbol_type and 'T' not in symbol_type: # Filter out symbols not in text sections continue - if len(self.symbol_addresses) == 0: + if not self.symbol_addresses: # The first symbol in text sections text_section_start = addr self.symbol_addresses.append(0) @@ -374,9 +374,9 @@ class HeatmapGenerator(object): def _map_addr_to_symbol(self, addr): # Find out the symbol name - assert len(self.symbol_addresses) > 0 + assert self.symbol_addresses index = bisect.bisect(self.symbol_addresses, addr) - assert index > 0 and index <= len(self.symbol_names), \ + assert 0 < index <= len(self.symbol_names), \ 'Failed to find an index (%d) in the list (len=%d)' % ( index, len(self.symbol_names)) return self.symbol_names[index - 1] @@ -387,7 +387,7 @@ class HeatmapGenerator(object): print( '----------------------------------------------------------', file=fp) print( - 'Page Offset: %d MB, Count: %d' % (page_num / 1024 / 1024, + 'Page Offset: %d MB, Count: %d' % (page_num // 1024 // 1024, sample_num), file=fp) @@ -400,8 +400,8 @@ class HeatmapGenerator(object): if pid is None: # The sampling is not on Chrome continue - if addr / self.page_size != ( - self.processes[pid].start_address + page_num) / self.page_size: + if addr // self.page_size != ( + self.processes[pid].start_address + page_num) // self.page_size: # Sampling not in the current page continue @@ -410,14 +410,14 @@ class HeatmapGenerator(object): assert name, 'Failed to find symbol name of addr %x' % addr symbol_counts[name] += 1 - assert sum(symbol_counts.itervalues()) == sample_num, \ + assert sum(symbol_counts.values()) == sample_num, \ 'Symbol name matching missing for some addresses: %d vs %d' % ( - sum(symbol_counts.itervalues()), sample_num) + sum(symbol_counts.values()), sample_num) # Print out the symbol names sorted by the number of samples in # the page for name, count in sorted( - symbol_counts.iteritems(), key=lambda kv: kv[1], reverse=True): + symbol_counts.items(), key=lambda kv: kv[1], reverse=True): if count == 0: break print('> %s : %d' % (name, count), file=fp) @@ -434,20 +434,19 @@ class HeatmapGenerator(object): # Read histogram from histo.txt hist = self._restore_histogram() # Sort the pages in histogram - sorted_hist = sorted( - hist.iteritems(), key=lambda value: value[1], reverse=True) + sorted_hist = sorted(hist.items(), key=lambda value: value[1], reverse=True) # Generate symbolizations self._read_symbols_from_binary(binary) # Write hottest pages - with open('addr2symbol.txt', 'w') as fp: + with open('addr2symbol.txt', 'w', encoding='utf-8') as fp: if self.hugepage: # Print hugepage region first print( 'Hugepage top %d hot pages (%d MB - %d MB):' % - (top_n, self.hugepage.start / 1024 / 1024, - self.hugepage.end / 1024 / 1024), + (top_n, self.hugepage.start // 1024 // 1024, + self.hugepage.end // 1024 // 1024), file=fp) pages_to_print = [(k, v) for k, v in sorted_hist @@ -464,5 +463,5 @@ class HeatmapGenerator(object): self._print_symbols_in_hot_pages(fp, pages_to_print) else: # Print top_n hottest pages. - pages_to_print = [(k, v) for k, v in sorted_hist][:top_n] + pages_to_print = sorted_hist[:top_n] self._print_symbols_in_hot_pages(fp, pages_to_print) |