Re: [PATCH 4/6] perf tools: Add support to store time of day in CTF data conversion

2020-08-03 Thread Jiri Olsa
On Mon, Aug 03, 2020 at 01:00:12PM +0900, Namhyung Kim wrote:
> On Thu, Jul 30, 2020 at 11:39:48PM +0200, Jiri Olsa wrote:
> > Adding support to convert and store time of day in CTF
> > data conversion for 'perf data convert' subcommand.
> > 
> > The perf.data used for conversion needs to have clock data
> > information - must be recorded with -k/--clockid option).
> > 
> > New --tod option is added to 'perf data convert' subcommand
> > to convert data with timestamps converted to wall clock time.
> > 
> > Record data with clockid set:
> >   # perf record -k CLOCK_MONOTONIC kill
> >   kill: not enough arguments
> >   [ perf record: Woken up 1 times to write data ]
> >   [ perf record: Captured and wrote 0.033 MB perf.data (8 samples) ]
> > 
> > Convert data with TOD timestamps:
> >   # perf data convert --tod --to-ctf ./ctf
> >   [ perf data convert: Converted 'perf.data' into CTF data './ctf' ]
> >   [ perf data convert: Converted and wrote 0.000 MB (8 samples) ]
> > 
> > Display data in perf script:
> >   # perf script -F+tod --ns
> > perf 262150 2020-07-13 18:38:50.097678523 153633.958246159: 
> >  1 cycles: ...
> > perf 262150 2020-07-13 18:38:50.097682941 153633.958250577: 
> >  1 cycles: ...
> > perf 262150 2020-07-13 18:38:50.097684997 153633.958252633: 
> >  7 cycles: ...
> >   ...
> 
> I believe this belongs to a later patch.

I wanted to show in changelog that the timestamps match
for both script and data convert tools

jirka

> 
> Thanks
> Namhyung
> 
> > 
> > Display data in babeltrace:
> >   # babeltrace --clock-date  ./ctf
> >   [2020-07-13 18:38:50.097678523] (+?.?) cycles: { cpu_id = 0 }, { 
> > perf_ip = 0xFFF ...
> >   [2020-07-13 18:38:50.097682941] (+0.04418) cycles: { cpu_id = 0 }, { 
> > perf_ip = 0xFFF ...
> >   [2020-07-13 18:38:50.097684997] (+0.02056) cycles: { cpu_id = 0 }, { 
> > perf_ip = 0xFFF ...
> >   ...
> > 
> > It's available only for recording with clockid specified,
> > because it's the only case where we can get reference time
> > to wallclock time. It's can't do that with perf clock yet.
> > 
> > Error is display if you want to use --tod on data without
> > clockid specified:
> > 
> >   # perf data convert --tod --to-ctf ./ctf
> >   Can't provide --tod time, missing clock data. Please record with 
> > -k/--clockid option.
> >   Failed to setup CTF writer.
> >   Error during conversion setup.
> > 
> > Signed-off-by: Jiri Olsa 
> > ---
> >  tools/perf/Documentation/perf-data.txt |  3 ++
> >  tools/perf/builtin-data.c  |  1 +
> >  tools/perf/util/data-convert-bt.c  | 56 +-
> >  tools/perf/util/data-convert.h |  1 +
> >  4 files changed, 41 insertions(+), 20 deletions(-)
> 



Re: [PATCH 4/6] perf tools: Add support to store time of day in CTF data conversion

2020-08-02 Thread Namhyung Kim
On Thu, Jul 30, 2020 at 11:39:48PM +0200, Jiri Olsa wrote:
> Adding support to convert and store time of day in CTF
> data conversion for 'perf data convert' subcommand.
> 
> The perf.data used for conversion needs to have clock data
> information - must be recorded with -k/--clockid option).
> 
> New --tod option is added to 'perf data convert' subcommand
> to convert data with timestamps converted to wall clock time.
> 
> Record data with clockid set:
>   # perf record -k CLOCK_MONOTONIC kill
>   kill: not enough arguments
>   [ perf record: Woken up 1 times to write data ]
>   [ perf record: Captured and wrote 0.033 MB perf.data (8 samples) ]
> 
> Convert data with TOD timestamps:
>   # perf data convert --tod --to-ctf ./ctf
>   [ perf data convert: Converted 'perf.data' into CTF data './ctf' ]
>   [ perf data convert: Converted and wrote 0.000 MB (8 samples) ]
> 
> Display data in perf script:
>   # perf script -F+tod --ns
> perf 262150 2020-07-13 18:38:50.097678523 153633.958246159:   
>1 cycles: ...
> perf 262150 2020-07-13 18:38:50.097682941 153633.958250577:   
>1 cycles: ...
> perf 262150 2020-07-13 18:38:50.097684997 153633.958252633:   
>7 cycles: ...
>   ...

I believe this belongs to a later patch.

Thanks
Namhyung

> 
> Display data in babeltrace:
>   # babeltrace --clock-date  ./ctf
>   [2020-07-13 18:38:50.097678523] (+?.?) cycles: { cpu_id = 0 }, { 
> perf_ip = 0xFFF ...
>   [2020-07-13 18:38:50.097682941] (+0.04418) cycles: { cpu_id = 0 }, { 
> perf_ip = 0xFFF ...
>   [2020-07-13 18:38:50.097684997] (+0.02056) cycles: { cpu_id = 0 }, { 
> perf_ip = 0xFFF ...
>   ...
> 
> It's available only for recording with clockid specified,
> because it's the only case where we can get reference time
> to wallclock time. It's can't do that with perf clock yet.
> 
> Error is display if you want to use --tod on data without
> clockid specified:
> 
>   # perf data convert --tod --to-ctf ./ctf
>   Can't provide --tod time, missing clock data. Please record with 
> -k/--clockid option.
>   Failed to setup CTF writer.
>   Error during conversion setup.
> 
> Signed-off-by: Jiri Olsa 
> ---
>  tools/perf/Documentation/perf-data.txt |  3 ++
>  tools/perf/builtin-data.c  |  1 +
>  tools/perf/util/data-convert-bt.c  | 56 +-
>  tools/perf/util/data-convert.h |  1 +
>  4 files changed, 41 insertions(+), 20 deletions(-)


[PATCH 4/6] perf tools: Add support to store time of day in CTF data conversion

2020-07-30 Thread Jiri Olsa
Adding support to convert and store time of day in CTF
data conversion for 'perf data convert' subcommand.

The perf.data used for conversion needs to have clock data
information - must be recorded with -k/--clockid option).

New --tod option is added to 'perf data convert' subcommand
to convert data with timestamps converted to wall clock time.

Record data with clockid set:
  # perf record -k CLOCK_MONOTONIC kill
  kill: not enough arguments
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.033 MB perf.data (8 samples) ]

Convert data with TOD timestamps:
  # perf data convert --tod --to-ctf ./ctf
  [ perf data convert: Converted 'perf.data' into CTF data './ctf' ]
  [ perf data convert: Converted and wrote 0.000 MB (8 samples) ]

Display data in perf script:
  # perf script -F+tod --ns
perf 262150 2020-07-13 18:38:50.097678523 153633.958246159: 
 1 cycles: ...
perf 262150 2020-07-13 18:38:50.097682941 153633.958250577: 
 1 cycles: ...
perf 262150 2020-07-13 18:38:50.097684997 153633.958252633: 
 7 cycles: ...
  ...

Display data in babeltrace:
  # babeltrace --clock-date  ./ctf
  [2020-07-13 18:38:50.097678523] (+?.?) cycles: { cpu_id = 0 }, { 
perf_ip = 0xFFF ...
  [2020-07-13 18:38:50.097682941] (+0.04418) cycles: { cpu_id = 0 }, { 
perf_ip = 0xFFF ...
  [2020-07-13 18:38:50.097684997] (+0.02056) cycles: { cpu_id = 0 }, { 
perf_ip = 0xFFF ...
  ...

It's available only for recording with clockid specified,
because it's the only case where we can get reference time
to wallclock time. It's can't do that with perf clock yet.

Error is display if you want to use --tod on data without
clockid specified:

  # perf data convert --tod --to-ctf ./ctf
  Can't provide --tod time, missing clock data. Please record with -k/--clockid 
option.
  Failed to setup CTF writer.
  Error during conversion setup.

Signed-off-by: Jiri Olsa 
---
 tools/perf/Documentation/perf-data.txt |  3 ++
 tools/perf/builtin-data.c  |  1 +
 tools/perf/util/data-convert-bt.c  | 56 +-
 tools/perf/util/data-convert.h |  1 +
 4 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/tools/perf/Documentation/perf-data.txt 
b/tools/perf/Documentation/perf-data.txt
index c87180764829..726b9bc9e1a7 100644
--- a/tools/perf/Documentation/perf-data.txt
+++ b/tools/perf/Documentation/perf-data.txt
@@ -27,6 +27,9 @@ OPTIONS for 'convert'
 --to-ctf::
Triggers the CTF conversion, specify the path of CTF data directory.
 
+--tod::
+   Convert time to wall clock time.
+
 -i::
Specify input perf data file path.
 
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index ca2fb44874e4..8d23b8d6ee8e 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -65,6 +65,7 @@ static int cmd_data_convert(int argc, const char **argv)
OPT_STRING('i', "input", _name, "file", "input file 
name"),
 #ifdef HAVE_LIBBABELTRACE_SUPPORT
OPT_STRING(0, "to-ctf", _ctf, NULL, "Convert to CTF format"),
+   OPT_BOOLEAN(0, "tod", , "Convert time to wall clock 
time"),
 #endif
OPT_BOOLEAN('f', "force", , "don't complain, do it"),
OPT_BOOLEAN(0, "all", , "Convert all events"),
diff --git a/tools/perf/util/data-convert-bt.c 
b/tools/perf/util/data-convert-bt.c
index 5f36fc6a5578..ded8a9da0fe8 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -31,6 +31,8 @@
 #include "config.h"
 #include 
 #include 
+#include 
+#include "util.h"
 
 #define pr_N(n, fmt, ...) \
eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
@@ -1381,11 +1383,26 @@ do {
\
return 0;
 }
 
-static int ctf_writer__setup_clock(struct ctf_writer *cw)
+static int ctf_writer__setup_clock(struct ctf_writer *cw,
+  struct perf_session *session,
+  bool tod)
 {
struct bt_ctf_clock *clock = cw->clock;
+   const char *desc = "perf clock";
+   int64_t offset = 0;
 
-   bt_ctf_clock_set_description(clock, "perf clock");
+   if (tod) {
+   struct perf_env *env = >header.env;
+
+   if (!env->clock.enabled) {
+   pr_err("Can't provide --tod time, missing clock data. "
+  "Please record with -k/--clockid option.\n");
+   return -1;
+   }
+
+   desc   = clockid_name(env->clock.clockid);
+   offset = env->clock.tod_ns - env->clock.clockid_ns;
+   }
 
 #define SET(__n, __v)  \
 do {   \
@@ -1394,8 +1411,8 @@ do {  \
 } while (0)
 
SET(frequency,   10);
-   SET(offset_s,0);
-