Skip to content

Commit 9a4af70

Browse files
Merge pull request #3 from MikaelMollberg/calculate-elapsed-sleep-remainder
Account for processing time when sleeping
2 parents 973b8b6 + 69d1169 commit 9a4af70

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

collect.sh

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

3+
NS=1000000000
34

45
rm -rf data/$1
56
mkdir data/$1
@@ -31,6 +32,7 @@ case "$1" in
3132

3233
for (( i=0;i<=$2;i++ ))
3334
do
35+
START_TIME=$(date +%s%N)
3436
#echo $i" second is collected"
3537
PID=$(pgrep -f $1)
3638
#PYfiles=$(ls data/python3)
@@ -98,8 +100,15 @@ do
98100
fi
99101

100102
#echo $TIME" 0 0 0 0" >> "data/ref.log"
101-
102-
sleep 1
103+
104+
END_TIME=$(date +%s%N)
105+
ELAPSED=$(($END_TIME - $START_TIME))
106+
SLEEP_TIME=$(($NS - $ELAPSED))
107+
108+
if (( SLEEP_TIME > 0 )); then
109+
SLEEP_SECONDS=$(awk "BEGIN {printf \"%.9f\", $SLEEP_TIME/$NS}")
110+
sleep $SLEEP_SECONDS
111+
fi
103112
done
104113

105114
echo "Collection for "$1" done"

0 commit comments

Comments
 (0)