app, tools: add "running" thread attribute to GimpBacktrace/performance-log

The "running" attribute (readable through
gimp_backtrace_is_thread_running(), and recorded in the performance
log) specifies if the thread was in a running or suspended state at
the time the backtrace was taken.  It is accurate on Linux, but
only approximated on Windows.

Adapt the performance-log-expand.py tool to maintain this attribute
(and any future thread attributes we might add).
This commit is contained in:
Ell 2018-09-03 18:13:16 -04:00
parent 667efc221d
commit 78adb7c900
6 changed files with 179 additions and 42 deletions

View file

@ -63,37 +63,38 @@ for sample in (log.find ("samples") or empty_element).iterfind ("sample"):
for thread in backtrace:
id = thread.get ("id")
head = thread.get ("head")
tail = thread.get ("tail")
attrib = dict (thread.attrib)
frames = list (thread)
last_thread = last_backtrace.setdefault (id, [{}, []])
last_frames = last_thread[1]
if head:
frames = last_frames[:int (head)] + frames
del attrib["head"]
if tail:
frames = frames + last_frames[-int (tail):]
del attrib["tail"]
last_thread[0] = attrib
last_thread[1] = frames
if not frames:
last_backtrace.pop (id, None)
else:
last_thread = last_backtrace.setdefault (id, [None, []])
last_frames = last_thread[1]
name = thread.get ("name")
head = thread.get ("head")
tail = thread.get ("tail")
if head:
frames = last_frames[:int (head)] + frames
if tail:
frames = frames + last_frames[-int (tail):]
last_thread[0] = name
last_thread[1] = frames
del last_backtrace[id]
for thread in list (backtrace):
backtrace.remove (thread)
for id, (name, frames) in last_backtrace.items ():
thread = ElementTree.SubElement (backtrace, "thread", id=id)
for id, (attrib, frames) in last_backtrace.items ():
thread = ElementTree.SubElement (backtrace, "thread", attrib)
thread.text = "\n"
thread.tail = "\n"
if name:
thread.set ("name", name)
thread.extend (frames)
# Expand address map