summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Hansen <markhansen@google.com>2021-09-29 02:54:34 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-09-29 02:54:34 +0000
commit3f58f74f03f8d70b21fafd3ac032b92eac815ed8 (patch)
treea8cdbb79f42a9abb7dc2d898d91b30aba5888955
parenta8ac5899b8babaa7369e53039824dfeecead5886 (diff)
parentc6326ed84490e8140d288276b95a842d34966ad2 (diff)
downloadextras-3f58f74f03f8d70b21fafd3ac032b92eac815ed8.tar.gz
Merge "pprof_proto_generator: Set units for common events"
-rwxr-xr-xsimpleperf/scripts/pprof_proto_generator.py14
-rw-r--r--simpleperf/scripts/test/pprof_proto_generator_test.py6
2 files changed, 18 insertions, 2 deletions
diff --git a/simpleperf/scripts/pprof_proto_generator.py b/simpleperf/scripts/pprof_proto_generator.py
index 09d54d5f..43ba5fd7 100755
--- a/simpleperf/scripts/pprof_proto_generator.py
+++ b/simpleperf/scripts/pprof_proto_generator.py
@@ -38,6 +38,15 @@ except ImportError:
log_exit('google.protobuf module is missing. Please install it first.')
+# Some units of common event names
+EVENT_UNITS = {
+ 'cpu-clock': 'nanoseconds',
+ 'cpu-cycles': 'cpu-cycles',
+ 'instructions': 'instructions',
+ 'task-clock': 'nanoseconds',
+}
+
+
def load_pprof_profile(filename):
profile = profile_pb2.Profile()
with open(filename, "rb") as f:
@@ -404,10 +413,11 @@ class PprofProfileGenerator(object):
sample_type_id = len(self.profile.sample_type)
sample_type = self.profile.sample_type.add()
sample_type.type = self.get_string_id('event_' + name + '_samples')
- sample_type.unit = self.get_string_id('count')
+ sample_type.unit = self.get_string_id('samples')
sample_type = self.profile.sample_type.add()
sample_type.type = self.get_string_id('event_' + name + '_count')
- sample_type.unit = self.get_string_id('count')
+ units = EVENT_UNITS.get(name, 'count')
+ sample_type.unit = self.get_string_id(units)
self.sample_types[name] = sample_type_id
return sample_type_id
diff --git a/simpleperf/scripts/test/pprof_proto_generator_test.py b/simpleperf/scripts/test/pprof_proto_generator_test.py
index e246faa7..bc33fb58 100644
--- a/simpleperf/scripts/test/pprof_proto_generator_test.py
+++ b/simpleperf/scripts/test/pprof_proto_generator_test.py
@@ -103,6 +103,12 @@ class TestPprofProtoGenerator(TestBase):
self.assertLessEqual(mapping.memory_start, location.address)
self.assertGreaterEqual(mapping.memory_limit, location.address)
+ def test_sample_type(self):
+ """Test sample types have the right units."""
+ output = self.run_generator()
+ self.assertIn('sample_type[0] = ValueType(typeID=1, unitID=2, type=event_cpu-cycles_samples, unit=samples)', output)
+ self.assertIn('sample_type[1] = ValueType(typeID=3, unitID=4, type=event_cpu-cycles_count, unit=cpu-cycles)', output)
+
def test_multiple_perf_data(self):
""" Test reporting multiple recording file. """
profile1 = self.generate_profile(None, ['aggregatable_perf1.data'])