Messages in this thread Patch in this message | | | From | David Hildenbrand <> | Subject | [PATCH v1] trace-cmd: introduce --initital-delay for record command | Date | Mon, 18 Dec 2017 12:24:12 +0100 |
| |
If recording a big number of events to a big buffer, one might want to minimize the trace-cmd activity for a certain period in time. Especially, don't see any trace-cmd activity for some time. If there are a lot of events, the loop might actually never sleep, resulting in the "-s" option never becomming active.
E.g. I am using scheduler events to trace thread activity per CPU. Esp. sched:sched_wakeup and sched:sched_stat_runtime. Even when setting the sleep time to something huge like 30 seconds, I can see constant activity from the trace-cmd tasks.
Signed-off-by: David Hildenbrand <david@redhat.com> --- Documentation/trace-cmd-record.1.txt | 10 ++++++++++ trace-cmd.h | 3 ++- trace-record.c | 11 ++++++++++- trace-recorder.c | 9 ++++++++- 4 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/Documentation/trace-cmd-record.1.txt b/Documentation/trace-cmd-record.1.txt index 68afa16..d429caf 100644 --- a/Documentation/trace-cmd-record.1.txt +++ b/Documentation/trace-cmd-record.1.txt @@ -326,6 +326,16 @@ OPTIONS executed will not be changed. This is useful if you want to monitor the output of the command being executed, but not see the output from trace-cmd. +*--initital-delay* 'delay':: + The processes that trace-cmd creates to record from the ring buffer need + to start copying the data from the ring buffer at some point in time. + Setting the 'delay' to zero will cause the processes to start copying + from the ring buffer immediately. This is helpful when wanting to + minimize trace-cmd activity during some period of time (where -s + will not help due to the amount of events being recorded). + + The 'delay' metric is microseconds. The default is set to 0. + EXAMPLES -------- diff --git a/trace-cmd.h b/trace-cmd.h index 6fd34d7..bae7153 100644 --- a/trace-cmd.h +++ b/trace-cmd.h @@ -285,7 +285,8 @@ struct tracecmd_recorder *tracecmd_create_buffer_recorder_fd(int fd, int cpu, un struct tracecmd_recorder *tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, const char *buffer); struct tracecmd_recorder *tracecmd_create_buffer_recorder_maxkb(const char *file, int cpu, unsigned flags, const char *buffer, int maxkb); -int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep); +int tracecmd_start_recording(struct tracecmd_recorder *recorder, + unsigned long sleep, unsigned long initital_sleep); void tracecmd_stop_recording(struct tracecmd_recorder *recorder); void tracecmd_stat_cpu(struct trace_seq *s, int cpu); long tracecmd_flush_recording(struct tracecmd_recorder *recorder); diff --git a/trace-record.c b/trace-record.c index f128257..cd6e158 100644 --- a/trace-record.c +++ b/trace-record.c @@ -79,6 +79,7 @@ static const char *output_file = "trace.dat"; static int latency; static int sleep_time = 1000; +static int initial_sleep_time = 0; static int recorder_threads; static struct pid_record_data *pids; static int buffers; @@ -2668,7 +2669,8 @@ static int create_recorder(struct buffer_instance *instance, int cpu, } while (!finished) { - if (tracecmd_start_recording(recorder, sleep_time) < 0) + if (tracecmd_start_recording(recorder, sleep_time, + initial_sleep_time) < 0) break; } tracecmd_free_recorder(recorder); @@ -4211,6 +4213,7 @@ enum { OPT_funcstack = 254, OPT_date = 255, OPT_module = 256, + OPT_initital_delay = 257, }; void trace_stop(int argc, char **argv) @@ -4452,6 +4455,7 @@ static void parse_record_options(int argc, {"quiet", no_argument, NULL, OPT_quiet}, {"help", no_argument, NULL, '?'}, {"module", required_argument, NULL, OPT_module}, + {"initital-delay", required_argument, NULL, OPT_initital_delay}, {NULL, 0, NULL, 0} }; @@ -4732,6 +4736,11 @@ static void parse_record_options(int argc, ctx->instance->filter_mod = optarg; ctx->filtered = 0; break; + case OPT_initital_delay: + if (!optarg) + usage(argv); + initial_sleep_time = atoi(optarg); + break; case OPT_quiet: case 'q': quiet = 1; diff --git a/trace-recorder.c b/trace-recorder.c index 85150fd..a48c9e8 100644 --- a/trace-recorder.c +++ b/trace-recorder.c @@ -439,7 +439,8 @@ long tracecmd_flush_recording(struct tracecmd_recorder *recorder) return total; } -int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep) +int tracecmd_start_recording(struct tracecmd_recorder *recorder, + unsigned long sleep, unsigned long initital_sleep) { struct timespec req; long read = 1; @@ -447,6 +448,12 @@ int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long s recorder->stop = 0; + if (initital_sleep) { + req.tv_sec = initital_sleep / 1000000; + req.tv_nsec = (initital_sleep % 1000000) * 1000; + nanosleep(&req, NULL); + } + do { /* Only sleep if we did not read anything last time */ if (!read && sleep) { -- 2.14.3
| |