summaryrefslogtreecommitdiff
path: root/cesar/common
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/common')
-rw-r--r--cesar/common/tools/traceviewer/annotate/cpu.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/cesar/common/tools/traceviewer/annotate/cpu.py b/cesar/common/tools/traceviewer/annotate/cpu.py
new file mode 100644
index 0000000000..3e64981fd3
--- /dev/null
+++ b/cesar/common/tools/traceviewer/annotate/cpu.py
@@ -0,0 +1,32 @@
+"""Annotate CPU usage trace."""
+import re
+
+def annotate (trace):
+ re_switch = re.compile (r'^switch .*to sp=(.*)')
+ re_enter = re.compile (r'^(isr|dsr|phy)')
+ re_exit = re.compile (r'^(?:isr|dsr|phy) exit')
+ stack = [ ]
+ for t in trace.trace:
+ # Colorize.
+ if t.text.startswith ('switch'):
+ t.view_attr = 'green'
+ elif t.text.startswith ('isr sp='):
+ t.view_attr = 'blue'
+ elif t.text.startswith ('dsr sp='):
+ t.view_attr = 'cyan'
+ elif t.text.startswith ('phy 0'):
+ t.view_attr = 'red'
+ # Handle stack.
+ m_switch = re_switch.search (t.text)
+ if m_switch:
+ stack = [ m_switch.group (1) ]
+ elif re_exit.search (t.text):
+ if stack:
+ stack.pop ()
+ else:
+ m_enter = re_enter.search (t.text)
+ if m_enter:
+ stack.append (m_enter.group (1))
+ if stack:
+ t.view_text = stack[-1]
+