@@ -79,47 +79,82 @@ rm -f "$SIGNAL_FILE"
7979# Find and collect for each process type
8080echo " Starting collection processes..."
8181
82- # Collect ncs.smp or beam.smp NSO process
83- NCS_PID=$( pgrep -f " \.smp.*-ncs true" )
84- if [ ! -z " $NCS_PID " ]; then
85- echo " Starting collection for ncs.smp PID $NCS_PID "
86- bash collect.sh $NCS_PID " data/ncs.smp/mem_ncs.smp.log" $DURATION $VERBOSE " $SIGNAL_FILE " &
87- fi
88-
89- # Collect NcsJVMLauncher process
90- JVM_PID=$( pgrep -f NcsJVMLauncher)
91- if [ ! -z " $JVM_PID " ]; then
92- echo " Starting collection for NcsJVMLauncher PID $JVM_PID "
93- bash collect.sh $JVM_PID " data/NcsJVMLauncher/mem_NcsJVMLauncher.log" $DURATION $VERBOSE " $SIGNAL_FILE " &
94- fi
82+ NS=1000000000
83+
84+ mkdir -p data/python3
85+ for (( i= 0 ;i<= $DURATION ;i++ ))
86+ do
87+ START_TIME=$( date +%s%N)
88+ PYTHON_PIDS=$( pgrep -f " python.* .*startup\.py" )
89+ JVM_PID=$( pgrep -f NcsJVMLauncher)
90+ NCS_PID=$( pgrep -f " \.smp.*-ncs true" )
91+
92+ # Collect ncs.smp or beam.smp NSO process
93+ if [ ! -z " $NCS_PID " ]; then
94+ # echo "Starting collection for ncs.smp PID $NCS_PID"
95+ COLLECT_PIDS=$( pgrep -f " .*collect.sh.* $NCS_PID " )
96+ if [ -z " $COLLECT_PIDS " ]; then
97+ bash collect.sh $NCS_PID " data/ncs.smp/mem_ncs.smp.log" $DURATION $VERBOSE " $SIGNAL_FILE " &
98+ fi
99+ fi
95100
96- # Collect Python processes
97- PYTHON_PIDS=$( pgrep -f " python.* .*startup\.py" )
98- if [ ! -z " $PYTHON_PIDS " ]; then
99- mkdir -p data/python3
100- for pid in $PYTHON_PIDS ; do
101- PYTHON_SCRIPT=$( ps -p $pid -o command | tail -n 1 | awk -F' ' ' {print $9}' )
102- SCRIPT_NAME=$( basename " $PYTHON_SCRIPT " .py 2> /dev/null || echo " python_$pid " )
103- if [ ! -z " $PYTHON_SCRIPT " ]; then
104- echo " Starting collection for Python process PID $pid : $SCRIPT_NAME "
105- bash collect.sh $pid " data/python3/mem_$SCRIPT_NAME .log" $DURATION $VERBOSE " $SIGNAL_FILE " &
101+ # Collect NcsJVMLauncher process
102+ if [ ! -z " $JVM_PID " ]; then
103+ # echo "Starting collection for NcsJVMLauncher PID $JVM_PID"
104+ COLLECT_PIDS=$( pgrep -f " .*collect.sh.* $JVM_PID " )
105+ if [ -z " $COLLECT_PIDS " ]; then
106+ bash collect.sh $JVM_PID " data/NcsJVMLauncher/mem_NcsJVMLauncher.log" $DURATION $VERBOSE " $SIGNAL_FILE " &
106107 fi
107- done
108- else
109- echo " No Python processes found to collect"
110- fi
108+ fi
111109
112- # Give a moment for all processes to register
113- sleep 1
110+ # Collect Python processes
111+ if [ ! -z " $PYTHON_PIDS " ]; then
112+ for pid in $PYTHON_PIDS ; do
113+ COLLECT_PIDS=$( pgrep -f " .*collect.sh.* $pid " )
114+ if [ -z " $COLLECT_PIDS " ]; then
115+ # echo "Not Found Collection Process for Python process PID $pid. Spwaning new Collection Process."
116+ PYTHON_SCRIPT=$( ps -p $pid -o command | tail -n 1 | awk -F' ' ' {print $9}' )
117+ SCRIPT_NAME=$( basename " $PYTHON_SCRIPT " .py 2> /dev/null || echo " python_$pid " )
118+ if [ ! -z " $PYTHON_SCRIPT " ]; then
119+ # echo "Starting collection for Python process PID $pid: $SCRIPT_NAME"
120+ bash collect.sh $pid " data/python3/mem_$SCRIPT_NAME .log" $DURATION -$i $VERBOSE " $SIGNAL_FILE " &
121+ fi
122+ # else
123+ # echo "Collection Process already running for Python process PID $pid"
124+ fi
125+ done
126+ # else
127+ # echo "No Python processes found to collect. for second $i"
128+ fi
129+
130+
131+
132+ END_TIME=$( date +%s%N)
133+ ELAPSED=$(( $END_TIME - $START_TIME ))
134+ SLEEP_TIME=$(( $NS - $ELAPSED ))
135+ if (( SLEEP_TIME > 0 )) ; then
136+ SLEEP_SECONDS=$( awk " BEGIN {printf \" %.9f\" , $SLEEP_TIME /$NS }" )
137+ # echo $SLEEP_SECONDS
138+ sleep $SLEEP_SECONDS
139+ fi
114140
115- # Signal all processes to start collecting
116- echo " All collection processes started. Signaling to begin data collection..."
117- touch " $SIGNAL_FILE "
141+ # Signal all processes to start collecting
142+ touch " $SIGNAL_FILE "
143+ wait
144+ echo -ne " Data Collection - $i second out of $DURATION second" \\ r
118145
119- wait
146+ # Clean up signal file
147+ rm -f " $SIGNAL_FILE "
148+ pkill -f collect.sh
149+ # # Give a moment for all processes to register
150+ # sleep 1
151+ done
152+
153+ echo " "
154+ echo " Data Collection - OK!"
155+
156+ sleep 2
120157
121- # Clean up signal file
122- rm -f " $SIGNAL_FILE "
123158
124159if [ ! -z " $PYTHON_PIDS " ]; then
125160 create_combined_python_log
@@ -146,4 +181,4 @@ echo "===================================== Ploting graph for python3 processes
146181echo " ====================================== Ploting graph to compare between process ========================================================"
147182bash graphs_compare.sh $VERBOSE
148183echo -e " ====================================== Ploting graph to compare between process done ========================================================\n"
149- echo " ===================================== Ploting graph to all process done ================================================="
184+ echo " ===================================== Ploting graph to all process done ================================================="
0 commit comments