Repository navigation
Expand file tree
/
Copy pathparser.sh
More file actions
42 lines (32 loc) · 1.53 KB
/
Copy pathparser.sh
File metadata and controls
42 lines (32 loc) · 1.53 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
41
42
#!/bin/bash
foo() {
local input_path=$1
local output_path=$2
echo "Name,Stack Allocations,Heap Allocations,Heap Frees,Heap Bytes Allocated,Heap Allocations Percentage" > "$output_path"
local file_name=""
local stack_allocations=""
while IFS= read -r line; do
line=$(echo "$line" | tr -d '\r')
if [[ $line == *"Profiling file"* ]]; then
file_name=$(echo "$line" | awk '{print $NF}' | awk -F'/' '{print $NF}')
elif [[ $line == *"stack allocation instructions executed"* ]]; then
stack_allocations=$(echo "$line" | awk '{print $(NF-4)}' | tr -d ',')
elif [[ $line == *"total heap usage"* ]]; then
heap_allocations=$(echo "$line" | awk '{print $(NF-6)}' | tr -d ',')
heap_frees=$(echo "$line" | awk '{print $(NF-4)}' | tr -d ',')
heap_bytes_allocated=$(echo "$line" | awk '{print $(NF-2)}' | tr -d ',')
# skip if some data is missing
if [[ -z "$file_name" || "$stack_allocations" -lt 100 ]]; then
continue
fi
percentage=$(awk "BEGIN {printf \"%.5f%%\", ($heap_allocations * 100.0) / ($heap_allocations + $stack_allocations)}")
percentage=$(echo $percentage | sed 's/,/./')
echo "$file_name,$stack_allocations,$heap_allocations,$heap_frees,$heap_bytes_allocated,$percentage" >> "$output_path"
file_name=""
stack_allocations=""
fi
done < "$input_path"
}
input_path="$1"
output_path="$2"
foo "$input_path" "$output_path"