-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcflow_stack_memory
More file actions
executable file
·40 lines (35 loc) · 1.01 KB
/
Copy pathcflow_stack_memory
File metadata and controls
executable file
·40 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
# Current script directory path
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# Check if argument was provided
if [ $# -lt 1 ]; then
echo " You need to provide a C/C++ file to analyze."
echo " Example:"
echo " ${0} main.c"
echo ""
exit 1
fi
# Get CFlow and memory usage
FLOW=`cflow $1`
SU=`cat ${DIR}/../build/memory_ram.txt`
# Show usage for each cflow line (ignore duplicates)
while IFS= read -r line
do
function=`echo "${line}" | awk '{print $1}'`
stack_usage=`echo "${SU}" | grep ${function::-2} | awk -F "\t" '{print $2 " " $3}'`
num_usages=`echo "${stack_usage}" | wc -l`
if [ $num_usages -gt 1 ]; then
echo "${line} [Multiples coincidences]:"
echo " ["
usages=`echo "${SU}" | grep ${function}`
while IFS= read -r usage
do
echo " ${usage}"
done <<< "$usages"
echo " ]"
echo ""
else
echo "${line} ${stack_usage}"
fi
done <<< "$FLOW"
exit 0