summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2019-08-02 16:31:40 -0700
committerYabin Cui <yabinc@google.com>2019-08-02 16:36:35 -0700
commit68220c5b7687b61c4d8bcf2a15b09348ca94ba57 (patch)
treed3a45e228c19eda89a1374a276b0de4a579ce130
parent9a3596488e08533d7a2944258f2cedefc3a01adb (diff)
downloadextras-68220c5b7687b61c4d8bcf2a15b09348ca94ba57.tar.gz
simpleperf: fix report_html.py.
report_html.py removes threads having too small percentage of samples. But it doesn't remove processes having no threads, which makes showing flamegraph broken. Bug: none Test: run test.py TestReportHtml.test_no_empty_process. Change-Id: I3d568c98f0426a8ebbc9760dbc3c2bd25eda4c67
-rwxr-xr-xsimpleperf/scripts/report_html.py5
-rw-r--r--simpleperf/scripts/script_testdata/two_process_perf.databin0 -> 53289 bytes
-rwxr-xr-xsimpleperf/scripts/test.py15
3 files changed, 20 insertions, 0 deletions
diff --git a/simpleperf/scripts/report_html.py b/simpleperf/scripts/report_html.py
index d7fe0ecf..f2292720 100755
--- a/simpleperf/scripts/report_html.py
+++ b/simpleperf/scripts/report_html.py
@@ -642,6 +642,7 @@ class RecordData(object):
hit_func_ids = set()
for event in self.events.values():
min_limit = event.event_count * min_func_percent * 0.01
+ to_del_processes = []
for process in event.processes.values():
to_del_threads = []
for thread in process.threads.values():
@@ -651,6 +652,10 @@ class RecordData(object):
thread.limit_percents(min_limit, min_callchain_percent, hit_func_ids)
for thread in to_del_threads:
del process.threads[thread]
+ if not process.threads:
+ to_del_processes.append(process.pid)
+ for process in to_del_processes:
+ del event.processes[process]
self.functions.trim_functions(hit_func_ids)
def _get_event(self, event_name):
diff --git a/simpleperf/scripts/script_testdata/two_process_perf.data b/simpleperf/scripts/script_testdata/two_process_perf.data
new file mode 100644
index 00000000..c61d5916
--- /dev/null
+++ b/simpleperf/scripts/script_testdata/two_process_perf.data
Binary files differ
diff --git a/simpleperf/scripts/test.py b/simpleperf/scripts/test.py
index 1b01c5f9..24a04356 100755
--- a/simpleperf/scripts/test.py
+++ b/simpleperf/scripts/test.py
@@ -1285,6 +1285,21 @@ class TestReportHtml(TestBase):
hit_count += 1
self.assertEqual(hit_count, len(event_count_for_thread_name))
+ def test_no_empty_process(self):
+ """ Test not showing a process having no threads. """
+ perf_data = os.path.join('testdata', 'two_process_perf.data')
+ self.run_cmd(['report_html.py', '-i', perf_data])
+ record_data = self._load_record_data_in_html('report.html')
+ processes = record_data['sampleInfo'][0]['processes']
+ self.assertEqual(len(processes), 2)
+
+ # One process is removed because all its threads are removed for not
+ # reaching the min_func_percent limit.
+ self.run_cmd(['report_html.py', '-i', perf_data, '--min_func_percent', '20'])
+ record_data = self._load_record_data_in_html('report.html')
+ processes = record_data['sampleInfo'][0]['processes']
+ self.assertEqual(len(processes), 1)
+
def _load_record_data_in_html(self, html_file):
with open(html_file, 'r') as fh:
data = fh.read()