-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot.sh
More file actions
executable file
·296 lines (226 loc) · 6.92 KB
/
plot.sh
File metadata and controls
executable file
·296 lines (226 loc) · 6.92 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/bin/bash
VERBOSE=0
MONITOR=0
DURATION=""
log_info () {
timestamp=$(date)
echo $timestamp" [INFO] "$1
}
log_error () {
timestamp=$(date)
echo $timestamp" [ERR] "$1
}
create_combined_python_log() {
log_info "Creating combined Python total log..."
if ! ls data/python3/mem_*.log >/dev/null 2>&1; then
log_info "No Python process logs found to combine"
return
fi
num_files=$(find data/python3 -name "mem_*.log" ! -name "mem_total.log" | wc -l)
find data/python3 -name "mem_*.log" ! -name "mem_total.log" -exec cat {} \; | awk -v num_files="$num_files" '
{
timestamp = $1
rss = $2
alloc = $3
system_total = $4
limit = $5
mem_used = $6
mem_total = $7
totals[timestamp,"rss"] += rss
totals[timestamp,"alloc"] += alloc
totals[timestamp,"system"] = system_total
totals[timestamp,"limit"] = limit
totals[timestamp,"used"] = mem_used
totals[timestamp,"memtotal"] = mem_total
count[timestamp]++
if (!(timestamp in seen)) {
timestamps[++ts_count] = timestamp
seen[timestamp] = 1
}
}
END {
for (i = 1; i <= ts_count; i++) {
ts = timestamps[i]
if (count[ts] == num_files) {
print ts, totals[ts,"rss"], totals[ts,"alloc"], totals[ts,"system"], totals[ts,"limit"], totals[ts,"used"], totals[ts,"memtotal"]
}
}
}
' | sort > data/python3/mem_total.log
log_info "Combined Python total log created"
}
plot_clenup() {
pkill -f collect.sh
pkill -f monitor.sh
rm -rf /tmp/signalback
rm $1
log_info "Data Collection - OK!"
sleep 2
if [ ! -z "$2" ]; then
create_combined_python_log
fi
log_info "Collection for for all process done "
log_info "Ploting graph to all process "
log_info "Ploting graph for ncs.smp process "
bash graphs.sh ncs.smp $VERBOSE
log_info "Ploting graph for ncs.smp process done "
log_info "Ploting graph for NcsJVMLauncher process "
bash graphs.sh NcsJVMLauncher $VERBOSE
log_info "Ploting graph for NcsJVMLauncher process done"
log_info "Ploting graph for python3 processes "
if [ -d "data/python3" ]; then
log_info "Plotting combined graph for python3 processes"
bash graphs.sh python3 $VERBOSE
else
log_info "No python3 data directory found"
fi
log_info "Ploting graph for python3 processes done"
log_info "Ploting graph to compare between process "
bash graphs_compare.sh $VERBOSE
log_info "Ploting graph to compare between process done "
log_info "Ploting graph to all process done"
exit 1
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-v|--verbose)
VERBOSE=1
shift
;;
-m|--monitor)
MONITOR=1
DURATION="NaN"
shift
;;
*)
DURATION="$1"
shift
;;
esac
done
while [[ $# -gt 1 ]]; do
case $2 in
-v|--verbose)
VERBOSE=1
DURATION="$3"
shift
;;
-m|--monitor)
MONITOR=1
DURATION="$3"
shift
;;
*)
DURATION="$2"
shift
;;
esac
done
if [ -z "$DURATION" ]; then
echo "Usage: $0 [--verbose|-v] [--monitor|-m] <duration>"
echo " duration: Collection duration in seconds"
echo " --verbose: Enable verbose logging"
echo " --monitor: Enable monitoring when memory reach warning level"
exit 1
fi
# Clean up old data
rm -rf data/ncs.smp data/NcsJVMLauncher data/python3
log_info "Collection for for all process"
# Create a signal file to coordinate process startup
SIGNAL_FILE="/tmp/nso_collect_start_signal_$$"
rm -f "$SIGNAL_FILE"
rm -rf /tmp/signalback
mkdir "/tmp/signalback"
# Find and collect for each process type
log_info "Starting collection processes..."
NS=1000000000
counter=0
CACHE_FILE="/tmp/cache.log"
touch $CACHE_FILE
mkdir -p data/python3
trap "rm -rf $CACHE_FILE; rm -rf /tmp/signalback ; exit 1 " SIGINT
trap "rm -rf $CACHE_FILE; rm -rf /tmp/signalback ; exit 1 " TERM
if [[ "$DURATION" == "NaN" ]]; then
DURATION=9223372036854775807
fi
for (( i=0;i<=$DURATION;i++ ))
do
START_TIME=$(date +%s%N)
PYTHON_PIDS=$(pgrep -f "python.* .*startup\.py")
JVM_PID=$(pgrep -f com.tailf.ncs.NcsJVMLauncher)
NCS_PID=$(pgrep -f "\.smp.*-ncs true")
trap "plot_clenup $CACHE_FILE $PYTHON_PIDS" SIGINT
trap "plot_clenup $CACHE_FILE $PYTHON_PIDS" TERM
# Collect ncs.smp or beam.smp NSO process
if [ ! -z "$NCS_PID" ]; then
COLLECT_PIDS=$(pgrep -f '.*collect.sh.*ncs.smp')
if [ -z "$COLLECT_PIDS" ]; then
log_info "New ncs.smp process PID $NCS_PID: ncs.smp. Start Collection"
counter=$((counter+1))
bash collect.sh ncs.smp "data/ncs.smp/mem_ncs.smp.log" $DURATION $VERBOSE "$SIGNAL_FILE" $i &
fi
fi
# Collect NcsJVMLauncher process
if [ ! -z "$JVM_PID" ]; then
COLLECT_PIDS=$(pgrep -f ".*collect.sh.*NcsJVMLauncher")
if [ -z "$COLLECT_PIDS" ]; then
log_info "New JVM process PID $JVM_PID: NcsJVMLauncher. Start Collection"
counter=$((counter+1))
bash collect.sh NcsJVMLauncher "data/NcsJVMLauncher/mem_NcsJVMLauncher.log" $DURATION $VERBOSE "$SIGNAL_FILE" $i &
fi
fi
# Collect Python processes
if [ ! -z "$PYTHON_PIDS" ]; then
for pid in $PYTHON_PIDS; do
PYTHON_SCRIPT=$(ps -p $pid -o command | tail -n 1 | awk -F' ' '{print $9}')
SCRIPT_NAME=$(basename "$PYTHON_SCRIPT" .py 2>/dev/null || echo "python_$pid")
COLLECT_PIDS=$(pgrep -f ".*collect.sh.* $SCRIPT_NAME ")
if [ -z "$COLLECT_PIDS" ]; then
if [ ! -z "$PYTHON_SCRIPT" ]; then
log_info "New Python process PID $pid: $SCRIPT_NAME. Start Collection"
cp $CACHE_FILE "data/python3/mem_$SCRIPT_NAME.log"
counter=$((counter+1))
bash collect.sh "$SCRIPT_NAME" "data/python3/mem_$SCRIPT_NAME.log" $DURATION $VERBOSE "$SIGNAL_FILE" $i &
fi
fi
done
fi
if [ "$MONITOR" -eq 1 ]; then
# Monitoring thread
if [ ! -z "$NCS_PID" ]; then
MONITOR_PIDS=$(pgrep -f '.*monitor.sh.*')
if [ -z "$MONITOR_PIDS" ]; then
log_info "Start Monitoring"
counter=$((counter+1))
bash monitor.sh $DURATION $VERBOSE "$SIGNAL_FILE" $i &
fi
fi
fi
sleep 0.1
# Signal all processes to start collecting
TIME=$(date +%T)
echo $i > $SIGNAL_FILE
echo $TIME >> $SIGNAL_FILE
while [[ $(ps -aux | grep "collect.sh" | wc -l) -gt $(($(ls "/tmp/signalback/" | grep "nso_collect_start_signalback_.*_$i" | wc -l)+1)) ]]; do
sleep 0.1
done
# Clean up signal file
rm -f $SIGNAL_FILE
rm -rf /tmp/signalback/*
END_TIME=$(date +%s%N)
ELAPSED=$(($END_TIME - $START_TIME))
SLEEP_TIME=$(($NS - $ELAPSED))
if (( SLEEP_TIME > 0 )); then
SLEEP_SECONDS=$(awk "BEGIN {printf \"%.9f\", $SLEEP_TIME/$NS}")
#echo $SLEEP_SECONDS
sleep $SLEEP_SECONDS
fi
if [[ $DURATION == 9223372036854775807 ]]; then
echo -ne "Data Collection - Infinity Collection. Ctrl+C to exit and process the data."\\r
else
echo -ne "Data Collection - $i second out of $DURATION second"\\r
fi
done
wait
plot_clenup $CACHE_FILE $PYTHON_PIDS