mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gregory Haskins <gregory.haskins@gmail.com>
To: rostedt@goodmis.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] FTRACE: Add a "-D usec" switch to limit execution time of "trace-cmd record"
Date: Tue, 24 Jan 2012 17:15:22 -0500	[thread overview]
Message-ID: <20120124221453.26831.9039.stgit@linux-mp.laurelwood.net> (raw)

[Applies to trace-cmd.git:699f544895]

It is sometimes useful to have a fairly precise timelimit on the capture
rather than relying on a human to hit Cntrl-C in a timely manner.  This
patch simply adds an optional timeout parameter which will automatically
terminate the capture after the specified duration.

Signed-off-by: Gregory Haskins <gregory.haskins@gmail.com>
CC: Steven Rostedt <rostedt@goodmis.org>
---

 trace-record.c |   12 +++++++++++-
 trace-usage.c  |    3 ++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/trace-record.c b/trace-record.c
index fcec28b..444745e 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -77,6 +77,7 @@ static int buffer_size;
 static const char *output_file = "trace.dat";
 
 static int latency;
+static int timeout = -1;
 static int sleep_time = 1000;
 static int cpu_count;
 static int *pids;
@@ -1953,7 +1954,7 @@ void trace_record (int argc, char **argv)
 			{NULL, 0, NULL, 0}
 		};
 
-		c = getopt_long (argc-1, argv+1, "+hae:f:Fp:cdo:O:s:r:vg:l:n:P:N:tb:kiT",
+		c = getopt_long (argc-1, argv+1, "+hae:f:Fp:cdo:O:s:r:vg:l:n:D:P:N:tb:kiT",
 				 long_options, &option_index);
 		if (c == -1)
 			break;
@@ -2051,6 +2052,9 @@ void trace_record (int argc, char **argv)
 			optarg++;
 			optarg[0] = '\0';
 			break;
+		case 'D':
+		        timeout = atoi(optarg);
+		        break;
 		case 'd':
 			if (extract)
 				usage(argv);
@@ -2189,8 +2193,14 @@ void trace_record (int argc, char **argv)
 
 	if (record) {
 		signal(SIGINT, finish);
+		signal(SIGALRM, finish);
 		if (!latency)
 			start_threads();
+
+		if (timeout > 0) {
+		        struct itimerval tv = { {0, 0}, {0, timeout}};
+		        setitimer(ITIMER_REAL, &tv, NULL);
+		}
 	}
 
 	if (extract) {
diff --git a/trace-usage.c b/trace-usage.c
index 0e2194e..df41f76 100644
--- a/trace-usage.c
+++ b/trace-usage.c
@@ -17,7 +17,7 @@ static struct usage_help usage_help[] = {
 		"record",
 		"record a trace into a trace.dat file",
 		" %s record [-v][-e event [-f filter]][-p plugin][-F][-d][-o file] \\\n"
-		"           [-s usecs][-O option ][-l func][-g func][-n func] \\\n"
+		"           [-s usecs][-D usecs][-O option ][-l func][-g func][-n func] \\\n"
 		"           [-P pid][-N host:port][-t][-r prio][-b size][command ...]\n"
 		"          -e run command with event enabled\n"
 		"          -f filter for previous -e event\n"
@@ -35,6 +35,7 @@ static struct usage_help usage_help[] = {
 		"          -O option to enable (or disable)\n"
 		"          -r real time priority to run the capture threads\n"
 		"          -s sleep interval between recording (in usecs) [default: 1000]\n"
+		"          -D run-time duration (in usecs) [default: disabled]\n"
 		"          -N host:port to connect to (see listen)\n"
 		"          -t used with -N, forces use of tcp in live trace\n"
 		"          -b change kernel buffersize (in kilobytes per CPU)\n"


                 reply	other threads:[~2012-01-24 22:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120124221453.26831.9039.stgit@linux-mp.laurelwood.net \
    --to=gregory.haskins@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®