Skip to content

Commit c045ed5

Browse files
MikaelMollbergMikael Mollberg
authored andcommitted
Add verbose flag to reduce script output
Use --verbose/-v to enabled verbose prints
1 parent 025ddba commit c045ed5

File tree

9 files changed

+168
-70
lines changed

9 files changed

+168
-70
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ apt-get install gnuplot
1212
## Usage
1313
Start measurment and input measurment time period. The diagram will generated afterwards in the graphs folder per process after the data collection
1414
```
15-
sh plot.sh <Time Duration>
15+
sh plot.sh [--verbose|-v] <Time Duration>
1616
```
1717

1818

@@ -102,4 +102,3 @@ writing, software distributed under the License is distributed on an "AS
102102
IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
103103
or implied.
104104
```
105-

collect.sh

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@
22

33
NS=1000000000
44

5-
rm -rf data/$1
6-
mkdir data/$1
5+
PROCESS=$1
6+
DURATION=$2
7+
VERBOSE=${3:-0}
8+
9+
if [ -z "$PROCESS" ] || [ -z "$DURATION" ]; then
10+
echo "Usage: $0 <process_name> <duration> [verbose_flag]"
11+
exit 1
12+
fi
13+
14+
log_verbose() {
15+
if [ $VERBOSE -eq 1 ]; then
16+
echo "$1"
17+
fi
18+
}
19+
20+
rm -rf data/$PROCESS
21+
mkdir data/$PROCESS
722

823
PY_CHECK=0
924

10-
case "$1" in
11-
"python3")
25+
case "$PROCESS" in
26+
"python3")
1227
PY_CHECK=1
1328
;;
14-
"python")
29+
"python")
1530
PY_CHECK=1
1631
;;
1732
*)
@@ -20,7 +35,7 @@ case "$1" in
2035
esac
2136

2237
NCS_CHECK=0
23-
case "$1" in
38+
case "$PROCESS" in
2439
"ncs.smp")
2540
NCS_CHECK=1
2641
;;
@@ -30,11 +45,11 @@ case "$1" in
3045
esac
3146

3247

33-
for (( i=0;i<=$2;i++ ))
48+
for (( i=0;i<=$DURATION;i++ ))
3449
do
3550
START_TIME=$(date +%s%N)
3651
#echo $i" second is collected"
37-
PID=$(pgrep -f $1)
52+
PID=$(pgrep -f $PROCESS)
3853
#PYfiles=$(ls data/python3)
3954
#UPDATEfiles=$(ps -o command -p $data | awk -F' ' '{print $9}')
4055
#Diff=$(comm <(echo $PYfiles) <(echo $UPDATEfiles))
@@ -59,14 +74,14 @@ do
5974
name=$(ps -p $pid -o command | awk -F' ' '{print $9}')
6075
com=name
6176
else
62-
name=$1
77+
name=$PROCESS
6378
com=$(ps -p $pid -o command | awk -F' ' '{print $5}')
6479
#echo $pid" "$name " " $com " "$(ps -p $pid -o command)
6580
fi
6681
if [ ! -z "${name}" ] && [ ! -z "${com}" ] ; then
6782
name=$(echo $name)
68-
echo "Monitoring PID: "$pid $name
69-
ALO_PID=$(pmap -d $pid | grep "writeable/private" | awk -F' ' '{print $4}' | egrep -o '[0-9.]+' )
83+
log_verbose "Monitoring PID: $pid $name"
84+
ALO_PID=$(pmap -d $pid | grep "writeable/private" | awk -F' ' '{print $4}' | egrep -o '[0-9.]+' )
7085
PHY=$(cat /proc/$pid/status | grep VmRSS | awk -F' ' '{print $2}')
7186

7287
if [ $PY_CHECK -eq 1 ] || [ $NCS_CHECK -eq 1 ] ; then
@@ -80,23 +95,23 @@ do
8095
if [ $counter -gt 1 ] ; then
8196
if [ ! -z "${name}" ] && [ ! -z "${com}" ] ; then
8297
if [ $NCS_CHECK -eq 1 ] ; then
83-
echo $TIME" "$SUM_PHY" "$SUM_ALO_PID" "$ALO_TOTAL" "$Limit >> "data/"$1"/mem_"$name".log"
84-
echo $i" second is collected towards data/"$1"/mem_"$name".log"
98+
echo $TIME" "$SUM_PHY" "$SUM_ALO_PID" "$ALO_TOTAL" "$Limit >> "data/"$PROCESS"/mem_"$name".log"
99+
log_verbose "$i second is collected towards data/$PROCESS/mem_$name.log"
85100
else
86-
echo $TIME" "$PHY" "$ALO_PID" "$ALO_TOTAL" "$Limit >> "data/"$1"/mem_"$name".log"
87-
echo $i" second is collected towards data/"$1"/mem_"$name".log"
101+
echo $TIME" "$PHY" "$ALO_PID" "$ALO_TOTAL" "$Limit >> "data/"$PROCESS"/mem_"$name".log"
102+
log_verbose "$i second is collected towards data/$PROCESS/mem_$name.log"
88103
fi
89104
fi
90105
else
91106
if [ ! -z "${name}" ] ; then
92-
echo $TIME" "$PHY" "$ALO_PID" "$ALO_TOTAL" "$Limit >> "data/"$1"/mem_"$name".log"
93-
echo $i" second is collected towards data/"$1"/mem_"$name".log"
107+
echo $TIME" "$PHY" "$ALO_PID" "$ALO_TOTAL" "$Limit >> "data/"$PROCESS"/mem_"$name".log"
108+
log_verbose "$i second is collected towards data/$PROCESS/mem_$name.log"
94109
fi
95110
fi
96-
done
111+
done
97112

98113
if [ $PY_CHECK -eq 1 ]; then
99-
echo $TIME" "$SUM_PHY" "$SUM_ALO_PID" "$ALO_TOTAL" "$Limit >> "data/"$1"/mem_total.log"
114+
echo $TIME" "$SUM_PHY" "$SUM_ALO_PID" "$ALO_TOTAL" "$Limit >> "data/"$PROCESS"/mem_total.log"
100115
fi
101116

102117
#echo $TIME" 0 0 0 0" >> "data/ref.log"
@@ -111,4 +126,4 @@ do
111126
fi
112127
done
113128

114-
echo "Collection for "$1" done"
129+
echo "Collection for $PROCESS done"

compare_mem_alloc.plt

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
if (GPVAL_VERSION >= 5.0) set for [i=1:8] linetype i dashtype i
22
if (GPVAL_VERSION < 5.0) set termoption dashed
33

4-
print "Statistical Data for Memory Allocation on JavaVM "
5-
stats 'data/NcsJVMLauncher/mem_NcsJVMLauncher.log' using 3
6-
7-
print "Statistical Data for Memory Allocation on PythonVM(Total)"
8-
stats 'data/python3/mem_total.log' using 3
9-
10-
print "Statistical Data for Memory Allocation on ncs.smp"
11-
stats 'data/ncs.smp/mem_ncs.smp.log' using 3
12-
13-
print "Statistical Data for Commited_AS"
14-
stats 'data/python3/mem_total.log' using 4
4+
if (!exists("verbose")) verbose = 0
5+
6+
if (verbose == 1) {
7+
print "Statistical Data for Memory Allocation on JavaVM "
8+
stats 'data/NcsJVMLauncher/mem_NcsJVMLauncher.log' using 3
9+
} else {
10+
stats 'data/NcsJVMLauncher/mem_NcsJVMLauncher.log' using 3 nooutput
11+
}
12+
13+
if (verbose == 1) {
14+
print "Statistical Data for Memory Allocation on PythonVM(Total)"
15+
stats 'data/python3/mem_total.log' using 3
16+
} else {
17+
stats 'data/python3/mem_total.log' using 3 nooutput
18+
}
19+
20+
if (verbose == 1) {
21+
print "Statistical Data for Memory Allocation on ncs.smp"
22+
stats 'data/ncs.smp/mem_ncs.smp.log' using 3
23+
} else {
24+
stats 'data/ncs.smp/mem_ncs.smp.log' using 3 nooutput
25+
}
26+
27+
if (verbose == 1) {
28+
print "Statistical Data for Commited_AS"
29+
stats 'data/python3/mem_total.log' using 4
30+
} else {
31+
stats 'data/python3/mem_total.log' using 4 nooutput
32+
}
1533
print "Recommended CommitLimit: ",STATS_max
1634
print "Please add some buffer range based on the Recommended CommitLimit"
1735

compare_mem_rss.plt

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
if (GPVAL_VERSION >= 5.0) set for [i=1:8] linetype i dashtype i
22
if (GPVAL_VERSION < 5.0) set termoption dashed
33

4-
print "Statistical Data for Memory Consumption on JavaVM Used"
5-
stats 'data/NcsJVMLauncher/mem_NcsJVMLauncher.log' using 2
6-
7-
print "Statistical Data for Memory Consumption on PythonVM(Total) Used"
8-
stats 'data/python3/mem_total.log' using 2
9-
10-
print "Statistical Data for Physical Memory Consumption on ncs.smp Used"
11-
stats 'data/ncs.smp/mem_ncs.smp.log' using 2
12-
13-
print "Statistical Data for Commited_AS"
14-
stats 'data/python3/mem_total.log' using 4
4+
if (!exists("verbose")) verbose = 0
5+
6+
if (verbose == 1) {
7+
print "Statistical Data for Memory Consumption on JavaVM Used"
8+
stats 'data/NcsJVMLauncher/mem_NcsJVMLauncher.log' using 2
9+
} else {
10+
stats 'data/NcsJVMLauncher/mem_NcsJVMLauncher.log' using 2 nooutput
11+
}
12+
13+
if (verbose == 1) {
14+
print "Statistical Data for Memory Consumption on PythonVM(Total) Used"
15+
stats 'data/python3/mem_total.log' using 2
16+
} else {
17+
stats 'data/python3/mem_total.log' using 2 nooutput
18+
}
19+
20+
if (verbose == 1) {
21+
print "Statistical Data for Physical Memory Consumption on ncs.smp Used"
22+
stats 'data/ncs.smp/mem_ncs.smp.log' using 2
23+
} else {
24+
stats 'data/ncs.smp/mem_ncs.smp.log' using 2 nooutput
25+
}
26+
27+
if (verbose == 1) {
28+
print "Statistical Data for Commited_AS"
29+
stats 'data/python3/mem_total.log' using 4
30+
} else {
31+
stats 'data/python3/mem_total.log' using 4 nooutput
32+
}
1533
print "Recommended CommitLimit: ",STATS_max
1634
print "Please add some buffer range based on the Recommended CommitLimit"
1735

graphs.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22

3+
VERBOSE=${2:-0}
34

45

56

@@ -37,9 +38,9 @@ for filename in data/$1/*.log; do
3738
echo "generated graph for pid "$name
3839
ln -s $PWD/data/$1/mem_$name.log $PWD/data/mem.log
3940
if [ $PY_CHECK -eq 1 ]; then
40-
gnuplot show_mem_2.plt
41+
gnuplot -e "verbose=$VERBOSE" show_mem_2.plt
4142
else
42-
gnuplot show_mem.plt
43+
gnuplot -e "verbose=$VERBOSE" show_mem.plt
4344
fi
4445

4546
cp mem-graph.png graphs/$1/mem_$name.png
@@ -52,7 +53,7 @@ if [ $PY_CHECK -eq 1 ]; then
5253
echo "generated graph for total "$name
5354
rm -f data/mem.log
5455
ln -s $PWD/data/$1/mem_$name.log $PWD/data/mem.log
55-
gnuplot show_mem.plt
56+
gnuplot -e "verbose=$VERBOSE" show_mem.plt
5657
cp mem-graph.png graphs/$1/mem_$name.png
5758
fi
5859

graphs_compare.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

3+
VERBOSE=${1:-0}
34

45
rm -rf graphs/compare
56
mkdir graphs/compare
67

78

8-
gnuplot compare_mem_alloc.plt
9-
gnuplot compare_mem_rss.plt
10-
9+
gnuplot -e "verbose=$VERBOSE" compare_mem_alloc.plt
10+
gnuplot -e "verbose=$VERBOSE" compare_mem_rss.plt

plot.sh

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,48 @@
11
#!/bin/bash
22

3+
VERBOSE=0
4+
DURATION=""
5+
6+
# Parse arguments
7+
while [[ $# -gt 0 ]]; do
8+
case $1 in
9+
-v|--verbose)
10+
VERBOSE=1
11+
shift
12+
;;
13+
*)
14+
DURATION="$1"
15+
shift
16+
;;
17+
esac
18+
done
19+
20+
if [ -z "$DURATION" ]; then
21+
echo "Usage: $0 [--verbose|-v] <duration>"
22+
echo " duration: Collection duration in seconds"
23+
echo " --verbose: Enable verbose logging"
24+
exit 1
25+
fi
26+
327
echo "====================================== Collection for for all process ====================================================="
4-
bash collect.sh ncs.smp $1 &
5-
bash collect.sh NcsJVMLauncher $1 &
6-
bash collect.sh python3 $1 &
28+
bash collect.sh ncs.smp $DURATION $VERBOSE &
29+
bash collect.sh NcsJVMLauncher $DURATION $VERBOSE &
30+
bash collect.sh python3 $DURATION $VERBOSE &
731
wait
832
echo -e "===================================== Collection for for all process done =================================================\n\n"
933

1034

1135
echo "====================================== Ploting graph to all process ========================================================"
1236
echo "====================================== Ploting graph for ncs.smp process ========================================================"
13-
bash graphs.sh ncs.smp
37+
bash graphs.sh ncs.smp $VERBOSE
1438
echo -e "===================================== Ploting graph for ncs.smp process done =================================================\n"
1539
echo "====================================== Ploting graph for NcsJVMLauncher process ========================================================"
16-
bash graphs.sh NcsJVMLauncher
40+
bash graphs.sh NcsJVMLauncher $VERBOSE
1741
echo -e "===================================== Ploting graph for NcsJVMLauncher process done =================================================\n"
1842
echo "====================================== Ploting graph for python3 process ========================================================"
19-
bash graphs.sh python3
43+
bash graphs.sh python3 $VERBOSE
2044
echo -e "===================================== Ploting graph for python3 process done =================================================\n"
2145
echo "====================================== Ploting graph to compare between process ========================================================"
22-
bash graphs_compare.sh
46+
bash graphs_compare.sh $VERBOSE
2347
echo -e "====================================== Ploting graph to compare between process done ========================================================\n"
2448
echo "===================================== Ploting graph to all process done ================================================="

show_mem.plt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
if (GPVAL_VERSION >= 5.0) set for [i=1:8] linetype i dashtype i
22
if (GPVAL_VERSION < 5.0) set termoption dashed
33

4-
print "Statistical Data for Commited_AS"
5-
stats 'data/mem.log' using 4
4+
if (!exists("verbose")) verbose = 0
5+
6+
if (verbose == 1) {
7+
print "Statistical Data for Commited_AS"
8+
stats 'data/mem.log' using 4
9+
} else {
10+
stats 'data/mem.log' using 4 nooutput
11+
}
612
print "Recommended CommitLimit: ",STATS_max
713
print "Please add some buffer range based on the Recommended CommitLimit"
814

9-
print "Statistical Data for RSS"
10-
stats 'data/mem.log' using 2
11-
12-
print "Statistical Data for Allocated"
13-
stats 'data/mem.log' using 3
15+
if (verbose == 1) {
16+
print "Statistical Data for RSS"
17+
stats 'data/mem.log' using 2
18+
} else {
19+
stats 'data/mem.log' using 2 nooutput
20+
}
21+
22+
if (verbose == 1) {
23+
print "Statistical Data for Allocated"
24+
stats 'data/mem.log' using 3
25+
} else {
26+
stats 'data/mem.log' using 3 nooutput
27+
}
1428

1529

1630

show_mem_2.plt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
if (GPVAL_VERSION >= 5.0) set for [i=1:8] linetype i dashtype i
22
if (GPVAL_VERSION < 5.0) set termoption dashed
33

4-
5-
print "Statistical Data for RSS"
6-
stats 'data/mem.log' using 2
7-
8-
print "Statistical Data for Allocated"
9-
stats 'data/mem.log' using 3
4+
if (!exists("verbose")) verbose = 0
5+
6+
if (verbose == 1) {
7+
print "Statistical Data for RSS"
8+
stats 'data/mem.log' using 2
9+
} else {
10+
stats 'data/mem.log' using 2 nooutput
11+
}
12+
13+
if (verbose == 1) {
14+
print "Statistical Data for Allocated"
15+
stats 'data/mem.log' using 3
16+
} else {
17+
stats 'data/mem.log' using 3 nooutput
18+
}
1019

1120

1221
set term png small size 800,600

0 commit comments

Comments
 (0)