Skip to contentSkip to conversation

trace-cmd: Add record --clock option to specify a trace clock

PATCH Superseded Ian Webster 3 participants 5 messages Dec 11, 2013 – May 14, 2015 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Add record --clock option to specify a trace clock

This change adds a --clock option to trace-cmd record. It simply writes trace_clock on debugfs. Examples of valid choices on most systems are: local, global, counter, and any other choice compatible with ftrace.

This complements Yoshihiro Yunomae's change 8c9867c (trace-cmd: Add support for extracting trace_clock in report).

---

Documentation/trace-cmd-record.1.txt |    5 +++++
trace-record.c                       |   19 +++++++++++++++++++
trace-usage.c                        |    1 +
3 files changed, 25 insertions(+)
Documentation/trace-cmd-record.1.txt +5 -0
index 832a257..201be2b 100644
@@ -240,6 +240,11 @@ OPTIONS
     timestamp to gettimeofday which will allow wall time output from the
     timestamps reading the created 'trace.dat' file.
 
+*--clock* 'clock_name'::
+    When an event is recorded into the ring buffer, a timestamp is added. This
+    stamp comes from the specified clock. Ftrace uses the "local" clock by
+    default. Other common clocks include: global, counter, uptime, perf, x86-tsc.
+

EXAMPLES
--------

trace-record.c +0 -0
index 0199627..18de026 100644
@@ -399,6 +399,20 @@ static int set_ftrace(int set, int use_proc)
  return 0;

}

+static void set_trace_clock(char *clock_choice)
+{
+ FILE *fp;
+ char *path;
+
+ path = tracecmd_get_tracing_file("trace_clock");
+ fp = fopen(path, "w");
+ if (!fp)
+ die("writing to '%s'", path);
+ tracecmd_put_tracing_file(path);
+ fwrite(clock_choice, 1, strlen(clock_choice), fp);
+ fclose(fp);
+}
+
static char *
get_instance_file(struct buffer_instance *instance, const char *file) {
@@ -2279,6 +2293,7 @@ static void record_all_events(void) }

enum {
+ OPT_clock = 252,
OPT_nosplice = 253,
OPT_funcstack = 254,
OPT_date = 255,
@@ -2351,6 +2366,7 @@ void trace_record (int argc, char **argv)
{"func-stack", no_argument, NULL, OPT_funcstack}, {"nosplice", no_argument, NULL, OPT_nosplice}, {"help", no_argument, NULL, '?'},
+ {"clock", required_argument, NULL, OPT_clock},

      {NULL, 0, NULL, 0}
    };

@@ -2530,6 +2546,9 @@ void trace_record (int argc, char **argv)

    case OPT_nosplice:
      recorder_flags |= TRACECMD_RECORD_NOSPLICE;
      break;
+   case OPT_clock:
+     set_trace_clock(optarg);
+     break;
    default:
      usage(argv);
    }
trace-usage.c +1 -0
index b8f26e6..54dbb85 100644
@@ -46,6 +46,7 @@ static struct usage_help usage_help[] = {
    "          -i do not fail if an event is not found\n"
    "          --func-stack perform a stack trace for function tracer\n"
    "             (use with caution)\n"
+   "          --clock change the method used to produce trace timestamps\n"
  },
  {
    "start",

--
1.7.9.5

#1 lore raw
Quoted 35 lines · On Wed, 11 Dec 2013 11:08:32 -0800 Ian Webster <[email protected]>…

This change adds a --clock option to trace-cmd record. It simply writes trace_clock on debugfs. Examples of valid choices on most systems are: local, global, counter, and any other choice compatible with ftrace.

This complements Yoshihiro Yunomae's change 8c9867c (trace-cmd: Add support for extracting trace_clock in report).

---

Documentation/trace-cmd-record.1.txt |    5 +++++
trace-record.c                       |   19 +++++++++++++++++++
trace-usage.c                        |    1 +
3 files changed, 25 insertions(+)
Documentation/trace-cmd-record.1.txt +5 -0
index 832a257..201be2b 100644
@@ -240,6 +240,11 @@ OPTIONS
     timestamp to gettimeofday which will allow wall time output from the
     timestamps reading the created 'trace.dat' file.
 
+*--clock* 'clock_name'::
+    When an event is recorded into the ring buffer, a timestamp is added. This
+    stamp comes from the specified clock. Ftrace uses the "local" clock by
+    default. Other common clocks include: global, counter, uptime, perf, x86-tsc.
+

EXAMPLES
--------

trace-record.c +0 -0
index 0199627..18de026 100644

trace-record.c static int set_ftrace(int set, int use_proc) · line 402

Quoted 4 lines
trace-record.c +1 -0
@@ -399,6 +399,20 @@ static int set_ftrace(int set, int use_proc)
  return 0;
 }
 
+static void set_trace_clock(char *clock_choice)

Should be const char *clock_choice.

trace-record.c static int set_ftrace(int set, int use_proc) · line 413

Quoted 11 lines
trace-record.c +11 -0
+{
+ FILE *fp;
+ char *path;
+
+ path = tracecmd_get_tracing_file("trace_clock");
+ fp = fopen(path, "w");
+ if (!fp)
+   die("writing to '%s'", path);
+ tracecmd_put_tracing_file(path);
+ fwrite(clock_choice, 1, strlen(clock_choice), fp);
+ fclose(fp);

Whitespace damage here.

I like the change, but the patch needs to be fixed. The tabs turned to spaces and the clock_choice above needs to be const.

Thanks,

-- Steve

Quoted 46 lines
trace-record.c +2 -0
+}
+

static char *
get_instance_file(struct buffer_instance *instance, const char *file) {

trace-record.c +5 -0
@@ -2279,6 +2293,7 @@ static void record_all_events(void)
 }
 
 enum {
+ OPT_clock = 252,
  OPT_nosplice  = 253,
  OPT_funcstack = 254,
  OPT_date  = 255,
@@ -2351,6 +2366,7 @@ void trace_record (int argc, char **argv)
      {"func-stack", no_argument, NULL, OPT_funcstack},
      {"nosplice", no_argument, NULL, OPT_nosplice},
      {"help", no_argument, NULL, '?'},
+     {"clock", required_argument, NULL, OPT_clock},
      {NULL, 0, NULL, 0}
    };
 
@@ -2530,6 +2546,9 @@ void trace_record (int argc, char **argv)
    case OPT_nosplice:
      recorder_flags |= TRACECMD_RECORD_NOSPLICE;
      break;
+   case OPT_clock:
+     set_trace_clock(optarg);
+     break;
    default:
      usage(argv);
    }
trace-usage.c +1 -1
index b8f26e6..54dbb85 100644
@@ -46,6 +46,7 @@ static struct usage_help usage_help[] = {
    "          -i do not fail if an event is not found\n"
    "          --func-stack perform a stack trace for function tracer\n"
    "             (use with caution)\n"
+   "          --clock change the method used to produce trace timestamps\n"
  },
  {
    "start",
--

1.7.9.5

#2 lore raw

PATCH v2 1/1 trace-cmd: Add record --clock option to specify a trace clock

This change adds a --clock option to trace-cmd record. It simply writes trace_clock on debugfs. Examples of valid choices on most systems are: local, global, counter, and any other choice compatible with ftrace.

This complements Yoshihiro Yunomae's change 8c9867c (trace-cmd: Add support for extracting trace_clock in report).

---
Changes per Steven's comments:
* add missing const
* preserve tab whitespace

 Documentation/trace-cmd-record.1.txt |    5 +++++
 trace-record.c                       |   19 +++++++++++++++++++
 trace-usage.c                        |    1 +
 3 files changed, 25 insertions(+)
Documentation/trace-cmd-record.1.txt +5 -0
index 832a257..5e83454 100644
@@ -240,6 +240,11 @@ OPTIONS
     timestamp to gettimeofday which will allow wall time output from the
     timestamps reading the created 'trace.dat' file.
 
+*--clock* 'clock_name'::
+    When an event is recorded into the ring buffer, a timestamp is added. This
+    stamp comes from the specified clock. Ftrace uses the "local" clock by
+    default. Other common clocks include: global, counter, uptime, perf, x86-tsc.
+
 EXAMPLES
 --------
 
trace-record.c +19 -0
index 0199627..2143080 100644
@@ -399,6 +399,20 @@ static int set_ftrace(int set, int use_proc)
 	return 0;
 }
 
+static void set_trace_clock(const char *clock_choice)
+{
+	FILE *fp;
+	char *path;
+
+	path = tracecmd_get_tracing_file("trace_clock");
+	fp = fopen(path, "w");
+	if (!fp)
+		die("writing to '%s'", path);
+	tracecmd_put_tracing_file(path);
+	fwrite(clock_choice, 1, strlen(clock_choice), fp);
+	fclose(fp);
+}
+
 static char *
 get_instance_file(struct buffer_instance *instance, const char *file)
 {
@@ -2279,6 +2293,7 @@ static void record_all_events(void)
 }
 
 enum {
+	OPT_clock = 252,
 	OPT_nosplice	= 253,
 	OPT_funcstack	= 254,
 	OPT_date	= 255,
@@ -2351,6 +2366,7 @@ void trace_record (int argc, char **argv)
 			{"func-stack", no_argument, NULL, OPT_funcstack},
 			{"nosplice", no_argument, NULL, OPT_nosplice},
 			{"help", no_argument, NULL, '?'},
+			{"clock", required_argument, NULL, OPT_clock},
 			{NULL, 0, NULL, 0}
 		};
 
@@ -2530,6 +2546,9 @@ void trace_record (int argc, char **argv)
 		case OPT_nosplice:
 			recorder_flags |= TRACECMD_RECORD_NOSPLICE;
 			break;
+		case OPT_clock:
+			set_trace_clock(optarg);
+			break;
 		default:
 			usage(argv);
 		}
trace-usage.c +1 -0
index b8f26e6..54dbb85 100644
@@ -46,6 +46,7 @@ static struct usage_help usage_help[] = {
 		"          -i do not fail if an event is not found\n"
 		"          --func-stack perform a stack trace for function tracer\n"
 		"             (use with caution)\n"
+		"          --clock change the method used to produce trace timestamps\n"
 	},
 	{
 		"start",

--
1.7.9.5

#3 lore raw

Hi Ian,

Quoted 3 lines · Ian Webster

This change adds a --clock option to trace-cmd record. It simply writes trace_clock on debugfs. Examples of valid choices on most systems are: local, global, counter, and any other choice compatible with ftrace.

Nice work!
Please see my following comments.

Quoted 40 lines

This complements Yoshihiro Yunomae's change 8c9867c (trace-cmd: Add support for extracting trace_clock in report).

---
Changes per Steven's comments:
* add missing const
* preserve tab whitespace

  Documentation/trace-cmd-record.1.txt |    5 +++++
  trace-record.c                       |   19 +++++++++++++++++++
  trace-usage.c                        |    1 +
  3 files changed, 25 insertions(+)
Documentation/trace-cmd-record.1.txt +5 -0
index 832a257..5e83454 100644
@@ -240,6 +240,11 @@ OPTIONS
      timestamp to gettimeofday which will allow wall time output from the
      timestamps reading the created 'trace.dat' file.
 
+*--clock* 'clock_name'::
+    When an event is recorded into the ring buffer, a timestamp is added. This
+    stamp comes from the specified clock. Ftrace uses the "local" clock by
+    default. Other common clocks include: global, counter, uptime, perf, x86-tsc.
+
  EXAMPLES
  --------
 
trace-record.c +1 -0
index 0199627..2143080 100644
@@ -399,6 +399,20 @@ static int set_ftrace(int set, int use_proc)
  	return 0;
  }
 
+static void set_trace_clock(const char *clock_choice)

trace-record.c static int set_ftrace(int set, int use_proc) · line 412

Quoted 10 lines
trace-record.c +10 -0
+{
+	FILE *fp;
+	char *path;
+
+	path = tracecmd_get_tracing_file("trace_clock");
+	fp = fopen(path, "w");
+	if (!fp)
+		die("writing to '%s'", path);
+	tracecmd_put_tracing_file(path);
+	fwrite(clock_choice, 1, strlen(clock_choice), fp);

Please add an error check for fwrite(). If clock_choice is invalid, trace-cmd would better output the error report and die.

Quoted 23 lines
trace-record.c +5 -0
+	fclose(fp);
+}
+
  static char *
  get_instance_file(struct buffer_instance *instance, const char *file)
  {
@@ -2279,6 +2293,7 @@ static void record_all_events(void)
  }
 
  enum {
+	OPT_clock = 252,
  	OPT_nosplice	= 253,
  	OPT_funcstack	= 254,
  	OPT_date	= 255,
@@ -2351,6 +2366,7 @@ void trace_record (int argc, char **argv)
  			{"func-stack", no_argument, NULL, OPT_funcstack},
  			{"nosplice", no_argument, NULL, OPT_nosplice},
  			{"help", no_argument, NULL, '?'},
+			{"clock", required_argument, NULL, OPT_clock},
  			{NULL, 0, NULL, 0}
  		};
 

trace-record.c void trace_record (int argc, char **argv) · line 2551

Quoted 6 lines
trace-record.c +3 -0
@@ -2530,6 +2546,9 @@ void trace_record (int argc, char **argv)
  		case OPT_nosplice:
  			recorder_flags |= TRACECMD_RECORD_NOSPLICE;
  			break;
+		case OPT_clock:
+			set_trace_clock(optarg);
+			break;

This implementation does not support multiple buffers. trace_clock had better be changed after sub-buffers are created, I think.

Example:
trace-cmd record -e sched --clock local -B foo -e block --clock x86-tsc

Thanks,
Yoshihiro YUNOMAE

Signature · 4 lines
Yoshihiro YUNOMAE
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#4 lore raw
Quoted 9 lines · On Mon, 16 Dec 2013 13:10:52 +0900 Yoshihiro YUNOMAE…

Hi Ian,

Quoted 3 lines · Ian Webster

This change adds a --clock option to trace-cmd record. It simply writes trace_clock on debugfs. Examples of valid choices on most systems are: local, global, counter, and any other choice compatible with ftrace.

Nice work!
Please see my following comments.

Hmm, I was waiting for a reply back with an update against these comments and never saw one. I eventually forgot about this patch :-(

I went to add it now, and noticed that I already added a -C option for trace-clock which also works for instances.

Sorry about forgetting about this patch (just found it buried in my inbox).

I'll be releasing 2.6 soon, with a bunch of new updates.

-- Steve

Quoted 95 lines
Quoted 41 lines

This complements Yoshihiro Yunomae's change 8c9867c (trace-cmd: Add support for extracting trace_clock in report).

---
Changes per Steven's comments:
* add missing const
* preserve tab whitespace

  Documentation/trace-cmd-record.1.txt |    5 +++++
  trace-record.c                       |   19 +++++++++++++++++++
  trace-usage.c                        |    1 +
  3 files changed, 25 insertions(+)
Documentation/trace-cmd-record.1.txt +5 -0
index 832a257..5e83454 100644
@@ -240,6 +240,11 @@ OPTIONS
      timestamp to gettimeofday which will allow wall time output from the
      timestamps reading the created 'trace.dat' file.
 
+*--clock* 'clock_name'::
+    When an event is recorded into the ring buffer, a timestamp is added. This
+    stamp comes from the specified clock. Ftrace uses the "local" clock by
+    default. Other common clocks include: global, counter, uptime, perf, x86-tsc.
+
  EXAMPLES
  --------
 
trace-record.c +1 -0
index 0199627..2143080 100644
@@ -399,6 +399,20 @@ static int set_ftrace(int set, int use_proc)
  	return 0;
  }
 
+static void set_trace_clock(const char *clock_choice)

trace-record.c static int set_ftrace(int set, int use_proc) · line 412

Quoted 10 lines
trace-record.c +10 -0
+{
+	FILE *fp;
+	char *path;
+
+	path = tracecmd_get_tracing_file("trace_clock");
+	fp = fopen(path, "w");
+	if (!fp)
+		die("writing to '%s'", path);
+	tracecmd_put_tracing_file(path);
+	fwrite(clock_choice, 1, strlen(clock_choice), fp);

Please add an error check for fwrite(). If clock_choice is invalid, trace-cmd would better output the error report and die.

Quoted 23 lines
trace-record.c +5 -0
+	fclose(fp);
+}
+
  static char *
  get_instance_file(struct buffer_instance *instance, const char *file)
  {
@@ -2279,6 +2293,7 @@ static void record_all_events(void)
  }
 
  enum {
+	OPT_clock = 252,
  	OPT_nosplice	= 253,
  	OPT_funcstack	= 254,
  	OPT_date	= 255,
@@ -2351,6 +2366,7 @@ void trace_record (int argc, char **argv)
  			{"func-stack", no_argument, NULL, OPT_funcstack},
  			{"nosplice", no_argument, NULL, OPT_nosplice},
  			{"help", no_argument, NULL, '?'},
+			{"clock", required_argument, NULL, OPT_clock},
  			{NULL, 0, NULL, 0}
  		};
 

trace-record.c void trace_record (int argc, char **argv) · line 2551

Quoted 6 lines
trace-record.c +3 -0
@@ -2530,6 +2546,9 @@ void trace_record (int argc, char **argv)
  		case OPT_nosplice:
  			recorder_flags |= TRACECMD_RECORD_NOSPLICE;
  			break;
+		case OPT_clock:
+			set_trace_clock(optarg);
+			break;

This implementation does not support multiple buffers. trace_clock had better be changed after sub-buffers are created, I think.

Example:
trace-cmd record -e sched --clock local -B foo -e block --clock x86-tsc

Thanks,
Yoshihiro YUNOMAE