-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-profiling_local.sh
More file actions
134 lines (123 loc) · 5.01 KB
/
task-profiling_local.sh
File metadata and controls
134 lines (123 loc) · 5.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# Initialize total private dirty memory in KB for each path
declare -A ArrayheapPrivateDirtyInKB
declare -A ArraystackPrivateDirtyInKB
declare -A ArraytotalPrivateDirtyInKB
declare -A ArraytotalEmptyPathPrivateDirtyInKB
declare -A ArraytaskPID
totalPrivateDirtyInKB=0
totalEmptyPathPrivateDirtyInKB=0
isAnonymous=false
currentPath=""
currentTaskID=""
in_entry=false
file_to_parse=$1
get_next_index() {
local taskID=$1
local -n DataArray=$2
local count=0
for key in "${!DataArray[@]}"; do
if [[ $key == "$taskID,"* ]]; then
((count++))
fi
done
echo $((count + 1))
}
echo "Private Dirty Memory Analysis from Smap"
echo "======= ===== ====== ======== ==== ===="
# Read smaps line by line
while IFS= read -r line; do
# Start processing when a Timestamp line is found
if [[ $line =~ ^Timestamp: ]]; then
echo "$line"
continue
fi
if [[ $line =~ ^Task\ ID:\ ([0-9]+) ]]; then
currentTaskID="${BASH_REMATCH[1]}"
ArraytaskPID[$currentTaskID]="${BASH_REMATCH[1]}"
in_entry=true
echo "$line"
continue
fi
# Stop processing when the delimiter line is found
if $in_entry && [[ $line == "========================================" ]]; then
in_entry=false
echo "Found Empty path Private_Dirty: $totalEmptyPathPrivateDirtyInKB : $((totalEmptyPathPrivateDirtyInKB / 1024))MB"
echo "Total Private Dirty Memory: $((totalPrivateDirtyInKB * 1024))bytes : ${totalPrivateDirtyInKB}KB : $((totalPrivateDirtyInKB / 1024))MB"
Index_To_Update=$(get_next_index $currentTaskID ArraytotalEmptyPathPrivateDirtyInKB)
ArraytotalEmptyPathPrivateDirtyInKB[$currentTaskID,$Index_To_Update]=$totalEmptyPathPrivateDirtyInKB
Index_To_Update=0
Index_To_Update=$(get_next_index $currentTaskID ArraytotalPrivateDirtyInKB)
ArraytotalPrivateDirtyInKB[$currentTaskID,$Index_To_Update]=$totalPrivateDirtyInKB
Index_To_Update=0
totalEmptyPathPrivateDirtyInKB=0
totalPrivateDirtyInKB=0
currentTaskID=""
echo "$line"
continue
fi
if $in_entry; then
# Check if the line contains memory region information
if [[ $line =~ ^[[:xdigit:]]+-[[:xdigit:]]+ ]]; then
isAnonymous=true
# Extract the path from the line containing memory region information
if [[ $line =~ [[:space:]](/.*)$ ]]; then
currentPath="${BASH_REMATCH[1]}"
elif [[ $line =~ \[([^]]+)\] ]]; then
currentPath="${BASH_REMATCH[1]}"
else
currentPath=""
fi
fi
# If the line contains "Private_Dirty" information, add it to the total for the current path
if $isAnonymous && [[ $line =~ ^Private_Dirty:[[:space:]]+([[:digit:]]+) ]]; then
privateDirtyInKB=${BASH_REMATCH[1]}
totalPrivateDirtyInKB=$((totalPrivateDirtyInKB + privateDirtyInKB))
if [[ -z $currentPath ]]; then
totalEmptyPathPrivateDirtyInKB=$((totalEmptyPathPrivateDirtyInKB + privateDirtyInKB))
elif [[ $currentPath == *"heap"* ]]; then
echo "Found Private_Dirty: $privateDirtyInKB for path: $currentPath"
Index_To_Update=$(get_next_index $currentTaskID ArrayheapPrivateDirtyInKB)
ArrayheapPrivateDirtyInKB[$currentTaskID,$Index_To_Update]=$privateDirtyInKB
Index_To_Update=0
elif [[ $currentPath == *"stack"* ]]; then
echo "Found Private_Dirty: $privateDirtyInKB for path: $currentPath"
Index_To_Update=$(get_next_index $currentTaskID ArraystackPrivateDirtyInKB)
ArraystackPrivateDirtyInKB[$currentTaskID,$Index_To_Update]=$privateDirtyInKB
Index_To_Update=0
else
#echo "Found Private_Dirty: $privateDirtyInKB for path: $currentPath"
dummy=0
fi
fi
# Reset isAnonymous flag for next memory region
if [[ -z $line ]]; then
isAnonymous=false
fi
fi
done < "$file_to_parse"
# Print out the initialized statuses
for pid in "${ArraytaskPID[@]}"; do
echo "Task ID: $pid"
echo -n "Heap Private Dirty Memory:[ "
for ((i=1; i<$(get_next_index $pid ArrayheapPrivateDirtyInKB); i++)); do
echo -n "${ArrayheapPrivateDirtyInKB[$pid,$i]} "
done
echo "]"
echo -n "Stack Private Dirty Memory:[ "
for ((i=1; i<$(get_next_index $pid ArraystackPrivateDirtyInKB); i++)); do
echo -n "${ArraystackPrivateDirtyInKB[$pid,$i]} "
done
echo "]"
echo -n "Total Empty Path Private Dirty Memory:[ "
for ((i=1; i<$(get_next_index $pid ArraytotalEmptyPathPrivateDirtyInKB); i++)); do
echo -n "${ArraytotalEmptyPathPrivateDirtyInKB[$pid,$i]} "
done
echo "]"
echo -n "Total Private Dirty Memory:[ "
for ((i=1; i<$(get_next_index $pid ArraytotalPrivateDirtyInKB); i++)); do
echo -n "${ArraytotalPrivateDirtyInKB[$pid,$i]} "
done
echo "]"
done
# End of script