[PATCH] blktrace: add stopwatch functionality
authorNathan Scott <nathans@sgi.com>
Wed, 14 Sep 2005 17:32:27 +0000 (19:32 +0200)
committerJens Axboe <axboe@suse.de>
Wed, 14 Sep 2005 17:32:27 +0000 (19:32 +0200)
Enables you to stop the trace after a defined period has passed.

blktrace.c
btrace

index 179c50a1888343fd906e440056db300a61987c27..0e12d10e0973e15fa23af3638aec2a384754d359 100644 (file)
@@ -65,7 +65,7 @@ struct mask_map mask_maps[] = {
        DECLARE_MASK_MAP(PC),
 };
 
-#define S_OPTS "d:a:A:r:o:k"
+#define S_OPTS "d:a:A:r:o:kw:"
 static struct option l_opts[] = {
        {
                .name = "dev",
@@ -103,6 +103,12 @@ static struct option l_opts[] = {
                .flag = NULL,
                .val = 'k'
        },
+       {
+               .name = "stopwatch",
+               .has_arg = 1,
+               .flag = NULL,
+               .val = 'w'
+       },
        {
                .name = NULL,
                .has_arg = 0,
@@ -529,6 +535,7 @@ int main(int argc, char *argv[])
        static char default_relay_path[] = "/relay";
        struct stat st;
        int i, c;
+       int stop_watch = 0;
        int act_mask_tmp = 0;
 
        while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) >= 0) {
@@ -568,6 +575,15 @@ int main(int argc, char *argv[])
                case 'k':
                        kill_running_trace = 1;
                        break;
+               case 'w':
+                       stop_watch = atoi(optarg);
+                       if (stop_watch <= 0) {
+                               fprintf(stderr,
+                                       "Invalid stopwatch value (%d secs)\n",
+                                       stop_watch);
+                               return 1;
+                       }
+                       break;
 
                default:
                        show_usage(argv[0]);
@@ -619,9 +635,13 @@ int main(int argc, char *argv[])
        signal(SIGINT, handle_sigint);
        signal(SIGHUP, handle_sigint);
        signal(SIGTERM, handle_sigint);
+       signal(SIGALRM, handle_sigint);
 
        atexit(stop_all_tracing);
 
+       if (stop_watch)
+               alarm(stop_watch);
+
        while (!is_done())
                sleep(1);
 
diff --git a/btrace b/btrace
index f698f9c78a341bec5bf1f5c33f2d172353f4883c..7e5460806d4b87f3f0365983797a9abc55c57aa4 100644 (file)
--- a/btrace
+++ b/btrace
@@ -9,13 +9,14 @@
 TRACEOPTS=""
 PARSEOPTS=""
 SUMMARIZE="-q" # quiet (no dev/cpu summary by default)
-USAGE="Usage: btrace [-s] [-t] [-S] [-a <trace>...] <dev>..."
+USAGE="Usage: btrace [-s] [-t] [-S] [-w N] [-a <trace>...] <dev>..."
 DIRNAME=`dirname $0`
 
-while getopts "a:stS" c
+while getopts "a:stSw:" c
 do
        case $c in
        a)      TRACEOPTS=$TRACEOPTS" -a "$OPTARG" ";;
+       w)      TRACEOPTS=$TRACEOPTS" -w "$OPTARG" ";;
        s)      PARSEOPTS=$PARSEOPTS" -s";;
        t)      PARSEOPTS=$PARSEOPTS" -t";;
        S)      SUMMARIZE="";;