summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2019-09-23 12:35:03 -0700
committerYabin Cui <yabinc@google.com>2019-09-23 12:35:03 -0700
commit169b4a2400b6c3cd07e268e4da57de912186412a (patch)
treebdb1a115470d724fe26251666f9b4f5e5a0d2453
parent61c47892cc293d279be03ccdc2b7906068254cec (diff)
downloadextras-169b4a2400b6c3cd07e268e4da57de912186412a.tar.gz
simpleperf: fix location addresses in generated pprof files.
The address of a location in pprof proto files should be within memory range of the corresponding mapping. But in pprof_proto_generator.py, it is written as the virtual address in elf file. Bug: 141026312 Test: run test.py TestPprofProtoGenerator* Change-Id: I3bc13548477b6b6069f712035b7177cc4bd60c80
-rwxr-xr-xsimpleperf/scripts/pprof_proto_generator.py2
-rwxr-xr-xsimpleperf/scripts/test.py16
2 files changed, 17 insertions, 1 deletions
diff --git a/simpleperf/scripts/pprof_proto_generator.py b/simpleperf/scripts/pprof_proto_generator.py
index 2a4e1d2a..c6355947 100755
--- a/simpleperf/scripts/pprof_proto_generator.py
+++ b/simpleperf/scripts/pprof_proto_generator.py
@@ -305,7 +305,7 @@ class PprofProfileGenerator(object):
sample.add_value(sample_type_id, 1)
sample.add_value(sample_type_id + 1, report_sample.period)
if self._filter_symbol(symbol):
- location_id = self.get_location_id(symbol.vaddr_in_file, symbol)
+ location_id = self.get_location_id(report_sample.ip, symbol)
sample.add_location_id(location_id)
for i in range(max(0, callchain.nr - self.max_chain_length), callchain.nr):
entry = callchain.entries[i]
diff --git a/simpleperf/scripts/test.py b/simpleperf/scripts/test.py
index a5ccd681..52bc32ca 100755
--- a/simpleperf/scripts/test.py
+++ b/simpleperf/scripts/test.py
@@ -63,6 +63,8 @@ from utils import str_to_bytes
try:
# pylint: disable=unused-import
import google.protobuf
+ # pylint: disable=ungrouped-imports
+ from pprof_proto_generator import load_pprof_profile
HAS_GOOGLE_PROTOBUF = True
except ImportError:
HAS_GOOGLE_PROTOBUF = False
@@ -1528,6 +1530,20 @@ class TestPprofProtoGenerator(TestBase):
""" Test the build ids generated are not padded with zeros. """
self.assertIn('build_id: e3e938cc9e40de2cfe1a5ac7595897de(', self.run_generator())
+ def test_location_address(self):
+ """ Test if the address of a location is within the memory range of the corresponding
+ mapping.
+ """
+ self.run_cmd(['pprof_proto_generator.py', '-i',
+ os.path.join('testdata', 'perf_with_interpreter_frames.data')])
+
+ profile = load_pprof_profile('pprof.profile')
+ # pylint: disable=no-member
+ for location in profile.location:
+ mapping = profile.mapping[location.mapping_id - 1]
+ self.assertLessEqual(mapping.memory_start, location.address)
+ self.assertGreaterEqual(mapping.memory_limit, location.address)
+
def get_all_tests():
tests = []