diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2009-12-15 19:07:16 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-15 19:07:16 -0500 |
| commit | a2fc047f34a527af7cc313a1f094ffa86e9cbc16 (patch) | |
| tree | 10aa96dce3eb4706311c614f4d8e0517692659eb | |
| parent | 5c5678691b5e7ced2ff9b4cfa0aa8ea74cb3616d (diff) | |
trace-cmd: Add sleep_time between splice reads
I found that tracing few events causes trace-cmd to almost spin
in a busy loop since it can constantly read a page, and the process
of reading that page causes it to run again. We end up just causing
events to read.
This adds a -s sleep time option that forces trace-cmd to sleep.
The default is 1ms. But it can be disabled with 0.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | trace-cmd.c | 10 | ||||
| -rw-r--r-- | trace-cmd.h | 2 | ||||
| -rw-r--r-- | trace-record.c | 9 |
3 files changed, 16 insertions, 5 deletions
diff --git a/trace-cmd.c b/trace-cmd.c index 0d53e8c..92008cd 100644 --- a/trace-cmd.c +++ b/trace-cmd.c | |||
| @@ -51,7 +51,7 @@ unsigned int page_size; | |||
| 51 | static const char *output_file = "trace.dat"; | 51 | static const char *output_file = "trace.dat"; |
| 52 | 52 | ||
| 53 | static int latency; | 53 | static int latency; |
| 54 | 54 | static int sleep_time = 1000; | |
| 55 | static int cpu_count; | 55 | static int cpu_count; |
| 56 | static int *pids; | 56 | static int *pids; |
| 57 | 57 | ||
| @@ -568,7 +568,7 @@ static int create_recorder(int cpu) | |||
| 568 | 568 | ||
| 569 | if (!recorder) | 569 | if (!recorder) |
| 570 | die ("can't create recorder"); | 570 | die ("can't create recorder"); |
| 571 | tracecmd_start_recording(recorder); | 571 | tracecmd_start_recording(recorder, sleep_time); |
| 572 | tracecmd_free_recorder(recorder); | 572 | tracecmd_free_recorder(recorder); |
| 573 | 573 | ||
| 574 | exit(0); | 574 | exit(0); |
| @@ -631,12 +631,13 @@ void usage(char **argv) | |||
| 631 | printf("\n" | 631 | printf("\n" |
| 632 | "%s version %s\n\n" | 632 | "%s version %s\n\n" |
| 633 | "usage:\n" | 633 | "usage:\n" |
| 634 | " %s record [-e event][-p plugin] [-d] [-o file] [-O option ] [command ...]\n" | 634 | " %s record [-e event][-p plugin][-d][-o file][-s usecs][-O option ] [command ...]\n" |
| 635 | " -e run command with event enabled\n" | 635 | " -e run command with event enabled\n" |
| 636 | " -p run command with plugin enabled\n" | 636 | " -p run command with plugin enabled\n" |
| 637 | " -d disable function tracer when running\n" | 637 | " -d disable function tracer when running\n" |
| 638 | " -o data output file [default trace.dat]\n" | 638 | " -o data output file [default trace.dat]\n" |
| 639 | " -O option to enable (or disable)\n" | 639 | " -O option to enable (or disable)\n" |
| 640 | " -s sleep interval between recording (in usecs) [default: 1000]\n" | ||
| 640 | "\n" | 641 | "\n" |
| 641 | " %s start [-e event][-p plugin] [-d] [-O option ]\n" | 642 | " %s start [-e event][-p plugin] [-d] [-O option ]\n" |
| 642 | " Uses same options as record, but does not run a command.\n" | 643 | " Uses same options as record, but does not run a command.\n" |
| @@ -726,6 +727,9 @@ int main (int argc, char **argv) | |||
| 726 | option = optarg; | 727 | option = optarg; |
| 727 | set_option(option); | 728 | set_option(option); |
| 728 | break; | 729 | break; |
| 730 | case 's': | ||
| 731 | sleep_time = atoi(optarg); | ||
| 732 | break; | ||
| 729 | } | 733 | } |
| 730 | } | 734 | } |
| 731 | 735 | ||
diff --git a/trace-cmd.h b/trace-cmd.h index 564c959..27f30a7 100644 --- a/trace-cmd.h +++ b/trace-cmd.h | |||
| @@ -107,7 +107,7 @@ void tracecmd_output_close(struct tracecmd_output *handle); | |||
| 107 | 107 | ||
| 108 | void tracecmd_free_recorder(struct tracecmd_recorder *recorder); | 108 | void tracecmd_free_recorder(struct tracecmd_recorder *recorder); |
| 109 | struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu); | 109 | struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu); |
| 110 | int tracecmd_start_recording(struct tracecmd_recorder *recorder); | 110 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep); |
| 111 | void tracecmd_stop_recording(struct tracecmd_recorder *recorder); | 111 | void tracecmd_stop_recording(struct tracecmd_recorder *recorder); |
| 112 | 112 | ||
| 113 | 113 | ||
diff --git a/trace-record.c b/trace-record.c index 0cd81ac..96579f1 100644 --- a/trace-record.c +++ b/trace-record.c | |||
| @@ -92,14 +92,21 @@ struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu) | |||
| 92 | return NULL; | 92 | return NULL; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | int tracecmd_start_recording(struct tracecmd_recorder *recorder) | 95 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep) |
| 96 | { | 96 | { |
| 97 | struct timespec req; | ||
| 97 | char *buf[recorder->page_size]; | 98 | char *buf[recorder->page_size]; |
| 98 | int ret; | 99 | int ret; |
| 99 | 100 | ||
| 100 | recorder->stop = 0; | 101 | recorder->stop = 0; |
| 101 | 102 | ||
| 102 | do { | 103 | do { |
| 104 | if (sleep) { | ||
| 105 | req.tv_sec = sleep / 1000000; | ||
| 106 | req.tv_nsec = (sleep % 1000000) * 1000; | ||
| 107 | nanosleep(&req, NULL); | ||
| 108 | } | ||
| 109 | |||
| 103 | ret = splice(recorder->trace_fd, NULL, recorder->brass[1], NULL, | 110 | ret = splice(recorder->trace_fd, NULL, recorder->brass[1], NULL, |
| 104 | recorder->page_size, 1 /* SPLICE_F_MOVE */); | 111 | recorder->page_size, 1 /* SPLICE_F_MOVE */); |
| 105 | if (ret < 0) { | 112 | if (ret < 0) { |
