Commit 2131133c authored by Kevin Atkinson's avatar Kevin Atkinson

Added "-b" option to schedmon to block until the run is done on
SIGTERM and SIGHUP

Add wrapper script around schedmon.
parent 7d5630ee
#!/bin/sh
cd ..
tar cfvz schedmon/schedmon.tar.gz schedmon/schedmon schedmon/schedmon-run.sh
#/bin/sh
SCHEDMON="/local/schedmon/schedmon -s 10000 -n 100 -t -l 59 -b"
ACTIVELOG=/tmp/schedmon.log
loop=1
function hup_h () {
loop=1
}
function term_h () {
loop=0
}
# just to be safe
killall -w -SIGKILL schedmon > /dev/null 2>&1
while [ $loop -ne 0 ]
do
loop=0
trap hup_h SIGHUP
trap term_h SIGTERM
# run until it dies via a signal
$SCHEDMON > $ACTIVELOG
trap '' SIGTERM # to make sure the log gets copied
ID=`date -u +%Y%m%d%H%M%S`
# now move and compress the log
cat $ACTIVELOG | gzip -c > /local/logs/schedmon-$ID.log.gz
rm $ACTIVELOG
done
exit 0
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <sched.h> #include <sched.h>
#include <signal.h>
#define MAX_SAMPLES 100000 #define MAX_SAMPLES 100000
...@@ -27,7 +28,7 @@ void ...@@ -27,7 +28,7 @@ void
usage() usage()
{ {
fprintf(stderr, fprintf(stderr,
"Usage: %s [-s usecs] [-n numsamples] [-t] [-l seconds] [-r numruns]\n", "Usage: %s [-s usecs] [-n numsamples] [-t] [-l seconds] [-r numruns] [-b]\n",
progname); progname);
exit(-1); exit(-1);
} }
...@@ -42,6 +43,7 @@ int main (int argc, char **argv) { ...@@ -42,6 +43,7 @@ int main (int argc, char **argv) {
unsigned long run = 0; unsigned long run = 0;
char c; char c;
int i; int i;
sigset_t block_sig;
/* config variables */ /* config variables */
int sleepusecs = 0; int sleepusecs = 0;
...@@ -49,10 +51,11 @@ int main (int argc, char **argv) { ...@@ -49,10 +51,11 @@ int main (int argc, char **argv) {
int usegettimeofday = 0; int usegettimeofday = 0;
int loopdelay = 1; int loopdelay = 1;
int numruns = 0; int numruns = 0;
int block = 0;
progname = argv[0]; progname = argv[0];
while ((c = getopt(argc, argv, "s:n:tl:r:")) != -1) { while ((c = getopt(argc, argv, "s:n:tl:r:b")) != -1) {
switch (c) { switch (c) {
case 's': case 's':
sleepusecs = atoi(optarg); sleepusecs = atoi(optarg);
...@@ -83,6 +86,9 @@ int main (int argc, char **argv) { ...@@ -83,6 +86,9 @@ int main (int argc, char **argv) {
numruns = atoi(optarg); numruns = atoi(optarg);
printf("Runs: %u\n", numruns); printf("Runs: %u\n", numruns);
break; break;
case 'b':
block = 1;
break;
default: default:
usage(); usage();
} }
...@@ -90,16 +96,23 @@ int main (int argc, char **argv) { ...@@ -90,16 +96,23 @@ int main (int argc, char **argv) {
argc -= optind; argc -= optind;
argv += optind; argv += optind;
sigemptyset (&block_sig);
sigaddset (&block_sig, SIGTERM);
sigaddset (&block_sig, SIGHUP);
run = 1; run = 1;
while(!numruns || run <= numruns) { while(!numruns || run <= numruns) {
struct timeval now; struct timeval now;
if (block)
sigprocmask (SIG_BLOCK, &block_sig, NULL);
gettimeofday(&now, &dummytz); gettimeofday(&now, &dummytz);
printf("*** Run: %lu ***\n", run); printf("*** Run: %lu ***\n", run);
printf("Time: %lu %lu\n", now.tv_sec, now.tv_usec); printf("Time: %lu %lu\n", now.tv_sec, now.tv_usec);
getloadavg(loadavg, 3); getloadavg(loadavg, 3);
printf("Load: %f %f %f\n", loadavg[0], loadavg[1], loadavg[2]); printf("Load: %f %f %f\n", loadavg[0], loadavg[1], loadavg[2]);
fflush(stdout);
for (i = 0; i < numsamples; ++i) { for (i = 0; i < numsamples; ++i) {
usegettimeofday ? usegettimeofday ?
...@@ -110,8 +123,6 @@ int main (int argc, char **argv) { ...@@ -110,8 +123,6 @@ int main (int argc, char **argv) {
sched_yield(); sched_yield();
} }
sleep(loopdelay);
for (i = 1; i < numsamples; ++i) { for (i = 1; i < numsamples; ++i) {
if (usegettimeofday) { if (usegettimeofday) {
long usecs, lastusecs, tmp; long usecs, lastusecs, tmp;
...@@ -124,7 +135,16 @@ int main (int argc, char **argv) { ...@@ -124,7 +135,16 @@ int main (int argc, char **argv) {
} }
} }
run++; run++;
fflush(stdout);
if (block)
sigprocmask (SIG_UNBLOCK, &block_sig, NULL);
sleep(loopdelay);
} }
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment