Skip to content

Commit 88371c5

Browse files
olsajiriacmel
authored andcommitted
perf data: Add support to store time of day in CTF data conversion
Adad 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.000004418) cycles: { cpu_id = 0 }, { perf_ip = 0xFFF ... [2020-07-13 18:38:50.097684997] (+0.000002056) 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 <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: David Ahern <[email protected]> Cc: Geneviève Bastien <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jeremie Galarneau <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9d88a1a commit 88371c5

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

tools/perf/Documentation/perf-data.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ OPTIONS for 'convert'
2727
--to-ctf::
2828
Triggers the CTF conversion, specify the path of CTF data directory.
2929

30+
--tod::
31+
Convert time to wall clock time.
32+
3033
-i::
3134
Specify input perf data file path.
3235

tools/perf/builtin-data.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static int cmd_data_convert(int argc, const char **argv)
6565
OPT_STRING('i', "input", &input_name, "file", "input file name"),
6666
#ifdef HAVE_LIBBABELTRACE_SUPPORT
6767
OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
68+
OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
6869
#endif
6970
OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
7071
OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),

tools/perf/util/data-convert-bt.c

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include "config.h"
3232
#include <linux/ctype.h>
3333
#include <linux/err.h>
34+
#include <linux/time64.h>
35+
#include "util.h"
36+
#include "clockid.h"
3437

3538
#define pr_N(n, fmt, ...) \
3639
eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
@@ -1381,11 +1384,26 @@ do { \
13811384
return 0;
13821385
}
13831386

1384-
static int ctf_writer__setup_clock(struct ctf_writer *cw)
1387+
static int ctf_writer__setup_clock(struct ctf_writer *cw,
1388+
struct perf_session *session,
1389+
bool tod)
13851390
{
13861391
struct bt_ctf_clock *clock = cw->clock;
1392+
const char *desc = "perf clock";
1393+
int64_t offset = 0;
13871394

1388-
bt_ctf_clock_set_description(clock, "perf clock");
1395+
if (tod) {
1396+
struct perf_env *env = &session->header.env;
1397+
1398+
if (!env->clock.enabled) {
1399+
pr_err("Can't provide --tod time, missing clock data. "
1400+
"Please record with -k/--clockid option.\n");
1401+
return -1;
1402+
}
1403+
1404+
desc = clockid_name(env->clock.clockid);
1405+
offset = env->clock.tod_ns - env->clock.clockid_ns;
1406+
}
13891407

13901408
#define SET(__n, __v) \
13911409
do { \
@@ -1394,8 +1412,8 @@ do { \
13941412
} while (0)
13951413

13961414
SET(frequency, 1000000000);
1397-
SET(offset_s, 0);
1398-
SET(offset, 0);
1415+
SET(offset, offset);
1416+
SET(description, desc);
13991417
SET(precision, 10);
14001418
SET(is_absolute, 0);
14011419

@@ -1481,7 +1499,8 @@ static void ctf_writer__cleanup(struct ctf_writer *cw)
14811499
memset(cw, 0, sizeof(*cw));
14821500
}
14831501

1484-
static int ctf_writer__init(struct ctf_writer *cw, const char *path)
1502+
static int ctf_writer__init(struct ctf_writer *cw, const char *path,
1503+
struct perf_session *session, bool tod)
14851504
{
14861505
struct bt_ctf_writer *writer;
14871506
struct bt_ctf_stream_class *stream_class;
@@ -1505,7 +1524,7 @@ static int ctf_writer__init(struct ctf_writer *cw, const char *path)
15051524

15061525
cw->clock = clock;
15071526

1508-
if (ctf_writer__setup_clock(cw)) {
1527+
if (ctf_writer__setup_clock(cw, session, tod)) {
15091528
pr("Failed to setup CTF clock.\n");
15101529
goto err_cleanup;
15111530
}
@@ -1613,17 +1632,15 @@ int bt_convert__perf2ctf(const char *input, const char *path,
16131632
if (err)
16141633
return err;
16151634

1616-
/* CTF writer */
1617-
if (ctf_writer__init(cw, path))
1618-
return -1;
1619-
16201635
err = -1;
16211636
/* perf.data session */
16221637
session = perf_session__new(&data, 0, &c.tool);
1623-
if (IS_ERR(session)) {
1624-
err = PTR_ERR(session);
1625-
goto free_writer;
1626-
}
1638+
if (IS_ERR(session))
1639+
return PTR_ERR(session);
1640+
1641+
/* CTF writer */
1642+
if (ctf_writer__init(cw, path, session, opts->tod))
1643+
goto free_session;
16271644

16281645
if (c.queue_size) {
16291646
ordered_events__set_alloc_size(&session->ordered_events,
@@ -1632,17 +1649,17 @@ int bt_convert__perf2ctf(const char *input, const char *path,
16321649

16331650
/* CTF writer env/clock setup */
16341651
if (ctf_writer__setup_env(cw, session))
1635-
goto free_session;
1652+
goto free_writer;
16361653

16371654
/* CTF events setup */
16381655
if (setup_events(cw, session))
1639-
goto free_session;
1656+
goto free_writer;
16401657

16411658
if (opts->all && setup_non_sample_events(cw, session))
1642-
goto free_session;
1659+
goto free_writer;
16431660

16441661
if (setup_streams(cw, session))
1645-
goto free_session;
1662+
goto free_writer;
16461663

16471664
err = perf_session__process_events(session);
16481665
if (!err)
@@ -1670,10 +1687,10 @@ int bt_convert__perf2ctf(const char *input, const char *path,
16701687

16711688
return err;
16721689

1673-
free_session:
1674-
perf_session__delete(session);
16751690
free_writer:
16761691
ctf_writer__cleanup(cw);
1692+
free_session:
1693+
perf_session__delete(session);
16771694
pr_err("Error during conversion setup.\n");
16781695
return err;
16791696
}

tools/perf/util/data-convert.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
struct perf_data_convert_opts {
66
bool force;
77
bool all;
8+
bool tod;
89
};
910

1011
#endif /* __DATA_CONVERT_H */

0 commit comments

Comments
 (0)