Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

trappy: add support to parse TGID in systrace #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_parse_empty_array(self):
in_data = """ kworker/4:1-397 [004] 720.741315: thermal_power_cpu_get: cpus=000000f0 freq=1900000 raw_cpu_power=1259 load={} power=61
kworker/4:1-397 [004] 720.741349: thermal_power_cpu_get: cpus=0000000f freq=1400000 raw_cpu_power=189 load={} power=14"""

expected_columns = set(["__comm", "__pid", "__cpu", "__line", "cpus", "freq",
expected_columns = set(["__comm", "__pid", "__tgid", "__cpu", "__line", "cpus", "freq",
"raw_cpu_power", "power"])

with open("trace.txt", "w") as fout:
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_parse_special_fields(self):
timestamp
)

expected_columns = set(["__comm", "__pid", "__cpu", "__line", "tag"])
expected_columns = set(["__comm", "__pid", "__tgid", "__cpu", "__line", "tag"])

with open("trace.txt", "w") as fout:
fout.write(in_data)
Expand All @@ -157,7 +157,7 @@ def test_parse_values_concatenation(self):

in_data = """ rcu_preempt-7 [000] 73.604532: my_sched_stat_runtime: comm=Space separated taskname pid=7 runtime=262875 [ns] vruntime=17096359856 [ns]"""

expected_columns = set(["__comm", "__pid", "__cpu", "__line", "comm", "pid", "runtime", "vruntime"])
expected_columns = set(["__comm", "__pid", "__tgid", "__cpu", "__line", "comm", "pid", "runtime", "vruntime"])

with open("trace.txt", "w") as fout:
fout.write(in_data)
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_equals_in_field_value(self):

df = trace.equals_event.data_frame
self.assertSetEqual(set(df.columns),
set(["__comm", "__pid", "__cpu", "__line", "my_field"]))
set(["__comm", "__pid", "__tgid", "__cpu", "__line", "my_field"]))
self.assertListEqual(df["my_field"].tolist(),
["foo", "foo=bar", "foo=bar=baz", 1,
"1=2", "1=foo", "1foo=2"])
3 changes: 2 additions & 1 deletion tests/test_systrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ def test_systrace_userspace(self):
self.assertEquals(edfr['event'].iloc[0], 'E')
self.assertEquals(edfr['data'].iloc[0], None)

def test_systrace_line_num(self):
def test_systrace_line_num_tgid(self):
"""Test for line numbers in a systrace"""
trace = trappy.SysTrace("trace_sf.html")
dfr = trace.sched_switch.data_frame
self.assertEquals(dfr['__tgid'].iloc[0], 959)
self.assertEquals(trace.lines, 2506)
self.assertEquals(dfr['__line'].iloc[0], 0)
self.assertEquals(dfr['__line'].iloc[1], 6)
Expand Down
12 changes: 7 additions & 5 deletions trappy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(self, parse_raw=False, fallback=False):
self.time_array = []
self.comm_array = []
self.pid_array = []
self.tgid_array = []
self.cpu_array = []
self.parse_raw = parse_raw
self.cached = False
Expand Down Expand Up @@ -152,7 +153,7 @@ def __get_trace_array_lengths(self):

return ret

def append_data(self, time, comm, pid, cpu, line, data):
def append_data(self, time, comm, pid, tgid, cpu, line, data):
"""Append data parsed from a line to the corresponding arrays

The :mod:`DataFrame` will be created from this when the whole trace
Expand All @@ -176,6 +177,7 @@ def append_data(self, time, comm, pid, cpu, line, data):
self.time_array.append(time)
self.comm_array.append(comm)
self.pid_array.append(pid)
self.tgid_array.append(tgid)
self.cpu_array.append(cpu)
self.line_array.append(line)
self.data_array.append(data)
Expand Down Expand Up @@ -226,10 +228,10 @@ def generate_parsed_data(self):
check_memory_usage = True
check_memory_count = 1

for (comm, pid, cpu, line, data_str) in zip(self.comm_array, self.pid_array,
self.cpu_array, self.line_array,
self.data_array):
data_dict = {"__comm": comm, "__pid": pid, "__cpu": cpu, "__line": line}
for (comm, pid, tgid, cpu, line, data_str) in zip(self.comm_array, self.pid_array,
self.tgid_array, self.cpu_array,
self.line_array, self.data_array):
data_dict = {"__comm": comm, "__pid": pid, "__tgid": tgid, "__cpu": cpu, "__line": line}
data_dict.update(self.generate_data_dict(data_str))

# When running out of memory, Pandas has been observed to segfault
Expand Down
8 changes: 5 additions & 3 deletions trappy/ftrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def _plot_freq_hists(allfreqs, what, axis, title):
"Frequency", xlim, "default")

SPECIAL_FIELDS_RE = re.compile(
r"^\s*(?P<comm>.*)-(?P<pid>\d+)(?:\s+\(.*\))"\
r"?\s+\[(?P<cpu>\d+)\](?:\s+....)?\s+"\
r"^\s*(?P<comm>.*)-(?P<pid>\d+)\s+\(?(?P<tgid>.*?)?\)"\
r"?\s*\[(?P<cpu>\d+)\](?:\s+....)?\s+"\
r"(?P<timestamp>[0-9]+(?P<us>\.[0-9]+)?): (\w+:\s+)+(?P<data>.+)"
)

Expand Down Expand Up @@ -279,6 +279,8 @@ def __populate_data(self, fin, cls_for_unique_word):
comm = fields_match.group('comm')
pid = int(fields_match.group('pid'))
cpu = int(fields_match.group('cpu'))
tgid = fields_match.group('tgid')
tgid = -1 if (not tgid or '-' in tgid) else int(tgid)

# The timestamp, depending on the trace_clock configuration, can be
# reported either in [s].[us] or [ns] format. Let's ensure that we
Expand All @@ -305,7 +307,7 @@ def __populate_data(self, fin, cls_for_unique_word):
if "={}" in data_str:
data_str = re.sub(r"[A-Za-z0-9_]+=\{\} ", r"", data_str)

trace_class.append_data(timestamp, comm, pid, cpu, self.lines, data_str)
trace_class.append_data(timestamp, comm, pid, tgid, cpu, self.lines, data_str)
self.lines += 1

def trace_hasnt_started(self):
Expand Down