summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2020-09-02 16:09:40 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-09-02 16:09:40 +0000
commita3609bc743126827a29fffeeaedec3fe0217cca2 (patch)
tree40728ec1f1f9c423484bf955c2745af1c6612853
parente18c8067b9fab1fd80827b233deca59e951d6750 (diff)
parentfa4786797c5f704fb03433e722ad0dd8e694f0c6 (diff)
downloadextras-a3609bc743126827a29fffeeaedec3fe0217cca2.tar.gz
Merge "simpleperf: support dynamic field in simpleperf_report_lib.py."
-rw-r--r--simpleperf/scripts/simpleperf_report_lib.py11
-rwxr-xr-xsimpleperf/scripts/test.py16
2 files changed, 26 insertions, 1 deletions
diff --git a/simpleperf/scripts/simpleperf_report_lib.py b/simpleperf/scripts/simpleperf_report_lib.py
index a46c2242..2b99602f 100644
--- a/simpleperf/scripts/simpleperf_report_lib.py
+++ b/simpleperf/scripts/simpleperf_report_lib.py
@@ -83,12 +83,14 @@ class TracingFieldFormatStruct(ct.Structure):
elem_size: size of the element type.
elem_count: the number of elements in this field, more than one if the field is an array.
is_signed: whether the element type is signed or unsigned.
+ is_dynamic: whether the element is a dynamic string.
"""
_fields_ = [('_name', ct.c_char_p),
('offset', ct.c_uint32),
('elem_size', ct.c_uint32),
('elem_count', ct.c_uint32),
- ('is_signed', ct.c_uint32)]
+ ('is_signed', ct.c_uint32),
+ ('is_dynamic', ct.c_uint32)]
_unpack_key_dict = {1: 'b', 2: 'h', 4: 'i', 8: 'q'}
@@ -102,6 +104,13 @@ class TracingFieldFormatStruct(ct.Structure):
an array of int values, etc. If the type can't be parsed, return a byte array or an
array of byte arrays.
"""
+ if self.is_dynamic:
+ offset, max_len = struct.unpack('<HH', data[self.offset:self.offset + 4])
+ length = 0
+ while length < max_len and bytes_to_str(data[offset + length]) != '\x00':
+ length += 1
+ return bytes_to_str(data[offset: offset + length])
+
if self.elem_count > 1 and self.elem_size == 1:
# Probably the field is a string.
# Don't use self.is_signed, which has different values on x86 and arm.
diff --git a/simpleperf/scripts/test.py b/simpleperf/scripts/test.py
index be1a855c..14efc326 100755
--- a/simpleperf/scripts/test.py
+++ b/simpleperf/scripts/test.py
@@ -1114,6 +1114,22 @@ class TestReportLib(TestBase):
self.assertIsNone(tracing_data)
self.assertTrue(has_tracing_data)
+ def test_dynamic_field_in_tracing_data(self):
+ self.report_lib.SetRecordFile(TEST_HELPER.testdata_path(
+ 'perf_with_tracepoint_event_dynamic_field.data'))
+ has_dynamic_field = False
+ while self.report_lib.GetNextSample():
+ event = self.report_lib.GetEventOfCurrentSample()
+ tracing_data = self.report_lib.GetTracingDataOfCurrentSample()
+ if event.name == 'kprobes:myopen':
+ self.assertIsNotNone(tracing_data)
+ self.assertIn('name', tracing_data)
+ if tracing_data['name'] == '/sys/kernel/debug/tracing/events/kprobes/myopen/format':
+ has_dynamic_field = True
+ else:
+ self.assertIsNone(tracing_data)
+ self.assertTrue(has_dynamic_field)
+
class TestRunSimpleperfOnDevice(TestBase):
def test_smoke(self):