aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Kirienko <pavel.kirienko@gmail.com>2015-01-17 02:58:07 +0300
committerLorenz Meier <lm@inf.ethz.ch>2015-01-21 14:54:23 +0100
commitf158c8270b7572b3f3384a52cb6f6c51ecd7ec57 (patch)
treed2a0b085c08ac28d197e4cd01a3603eb05d278a9
parentd1abf9c133bfe865f9648a88610d92a78f787f21 (diff)
downloadpx4-firmware-f158c8270b7572b3f3384a52cb6f6c51ecd7ec57.tar.gz
px4-firmware-f158c8270b7572b3f3384a52cb6f6c51ecd7ec57.tar.bz2
px4-firmware-f158c8270b7572b3f3384a52cb6f6c51ecd7ec57.zip
Rich man's profiler - handling quotes
-rwxr-xr-xDebug/poor-mans-profiler.sh49
1 files changed, 31 insertions, 18 deletions
diff --git a/Debug/poor-mans-profiler.sh b/Debug/poor-mans-profiler.sh
index 7657e4dc7..89ff4f424 100755
--- a/Debug/poor-mans-profiler.sh
+++ b/Debug/poor-mans-profiler.sh
@@ -122,13 +122,12 @@ fi
#
[ -f $stacksfile ] || die "Where are the stack samples?"
-cat $stacksfile | python -c "
+cat << 'EOF' > /tmp/pmpn-folder.py
#
# This stack folder correctly handles C++ types.
#
-
from __future__ import print_function, division
-import fileinput, collections, os
+import fileinput, collections, os, sys
def enforce(x, msg='Invalid input'):
if not x:
@@ -137,20 +136,29 @@ def enforce(x, msg='Invalid input'):
def split_first_part_with_parens(line):
LBRACES = {'(':'()', '<':'<>', '[':'[]', '{':'{}'}
RBRACES = {')':'()', '>':'<>', ']':'[]', '}':'{}'}
+ QUOTES = set(['"', "'"])
+ quotes = collections.defaultdict(bool)
braces = collections.defaultdict(int)
out = ''
for ch in line:
out += ch
+ # escape character cancels further processing
+ if ch == '\\':
+ continue
# special cases
if out.endswith('operator>') or out.endswith('operator->'): # gotta love c++
braces['<>'] += 1
if out.endswith('operator<'):
braces['<>'] -= 1
- # counting parens
- if ch in LBRACES.keys():
- braces[LBRACES[ch]] += 1
- if ch in RBRACES.keys():
- braces[RBRACES[ch]] -= 1
+ # switching quotes
+ if ch in QUOTES:
+ quotes[ch] = not quotes[ch]
+ # counting parens only when outside quotes
+ if sum(quotes.values()) == 0:
+ if ch in LBRACES.keys():
+ braces[LBRACES[ch]] += 1
+ if ch in RBRACES.keys():
+ braces[RBRACES[ch]] -= 1
# sanity check
for v in braces.values():
enforce(v >= 0, 'Unaligned braces: ' + str(dict(braces)))
@@ -206,19 +214,24 @@ def parse(line):
stacks = collections.defaultdict(int)
current = ''
-for line in fileinput.input():
- line = line.strip()
- if line:
- inf = parse(line)
- fun = inf['function']
- current = (fun + ';' + current) if current else fun
- elif current:
- stacks[current] += 1
- current = ''
+for idx,line in enumerate(fileinput.input()):
+ try:
+ line = line.strip()
+ if line:
+ inf = parse(line)
+ fun = inf['function']
+ current = (fun + ';' + current) if current else fun
+ elif current:
+ stacks[current] += 1
+ current = ''
+ except Exception, ex:
+ print('ERROR (line %d):' % (idx + 1), ex, file=sys.stderr)
for s, f in sorted(stacks.items(), key=lambda (s, f): s):
print(s, f)
-" > $foldfile
+EOF
+
+cat $stacksfile | python /tmp/pmpn-folder.py > $foldfile
echo "Folded stacks saved to $foldfile"