perf data pipe mode support and tests
Ian Rogers
reviewercover perf data pipe mode support and tests
Add pipe mode support to perf data conversion. Add testing to perf data with pipe mode and add --to-ctf testing if libbabeltrace is present.
Ian Rogers (5):
perf check: Add libbabeltrace to the listed features perf json: Pipe mode --to-json support
perf json: Pipe mode --to-ctf support
perf test: Test pipe mode with data conversion --to-json perf test: perf data --to-ctf testing
tools/perf/builtin-check.c | 1 + .../shell/test_perf_data_converter_ctf.sh | 104 ++++++++++++++++++ .../shell/test_perf_data_converter_json.sh | 33 ++++-- tools/perf/util/data-convert-bt.c | 54 ++++++++- tools/perf/util/data-convert-json.c | 16 +++ 5 files changed, 197 insertions(+), 11 deletions(-) create mode 100755 tools/perf/tests/shell/test_perf_data_converter_ctf.sh
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 1/5 perf check: Add libbabeltrace to the listed features
This enables scripts to more easily determine if perf data --to-ctf is supported.
--- tools/perf/builtin-check.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/builtin-check.c +1 -0
@@ -43,6 +43,7 @@ struct feature_status supported_features[] = {FEATURE_STATUS ("dwarf_getlocations" ,HAVE_LIBDW_SUPPORT ),FEATURE_STATUS ("dwarf-unwind" ,HAVE_DWARF_UNWIND_SUPPORT ),FEATURE_STATUS_TIP ("libbfd" ,HAVE_LIBBFD_SUPPORT ,"Deprecated, license incompatibility, use BUILD_NONDISTRO=1 and install binutils-dev[el]" ), +FEATURE_STATUS ("libbabeltrace" ,HAVE_LIBBABELTRACE_SUPPORT ),FEATURE_STATUS ("libbpf-strings" ,HAVE_LIBBPF_STRINGS_SUPPORT ),FEATURE_STATUS ("libcapstone" ,HAVE_LIBCAPSTONE_SUPPORT ), FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 2/5 perf json: Pipe mode --to-json support
In reply to Ian RogersIn pipe mode the environment may not be fully initialized so be robust to fields being NULL. Add default handling of feature and attr events.
--- tools/perf/util/data-convert-json.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tools/perf/util/data-convert-json.c +16 -0
@@ -48,6 +48,9 @@ struct convert_json {static void output_json_string (FILE *out,const char *s) {fputc ('"' , out); +if (!s) + goto out; +while (*s) {switch (*s) {
@@ -71,6 +74,7 @@ static void output_json_string(FILE *out, const char *s) ++s; } +out:fputc ('"' , out); }
@@ -322,6 +326,16 @@ static void output_headers(struct perf_session *session, struct convert_json *c)output_json_format (out, false,2 ,"]" ); } +static int process_feature_event (const struct perf_tool *tool__maybe_unused , +struct perf_session *session, +union perf_event *event) +{ +if (event->feat.feat_id <HEADER_LAST_FEATURE ) +return perf_event__process_feature (session, event); + +return 0 ; +} +int bt_convert__perf2json (const char *input_name,const char *output_name,struct perf_data_convert_opts *opts__maybe_unused ) {
@@ -360,6 +374,8 @@ int bt_convert__perf2json(const char *input_name, const char *output_name, c.tool.auxtrace_info = perf_event__process_auxtrace_info; c.tool.auxtrace = perf_event__process_auxtrace; c.tool.event_update = perf_event__process_event_update; + c.tool.attr = perf_event__process_attr; + c.tool.feature = process_feature_event; c.tool.ordering_requires_timestamps = true;if (opts->all) {
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 3/5 perf json: Pipe mode --to-ctf support
In reply to Ian RogersIn pipe mode the environment may not be fully initialized so be robust to fields being NULL. Add default handling of attr events, use the feature events to populate the ctf writer environment.
--- tools/perf/util/data-convert-bt.c | 54 +++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-)
tools/perf/util/data-convert-bt.c +52 -2
@@ -35,6 +35,7 @@#include "clockid.h" #include "util/sample.h" #include "util/time-utils.h" +#include "header.h" #ifdef HAVE_LIBTRACEEVENT #include <event-parse.h>
@@ -1338,7 +1339,8 @@ static void cleanup_events(struct perf_session *session)struct evsel_priv *priv; priv = evsel->priv; -bt_ctf_event_class_put (priv->event_class); +if (priv) +bt_ctf_event_class_put (priv->event_class);zfree (&evsel->priv); }
@@ -1387,7 +1389,7 @@ static int ctf_writer__setup_env(struct ctf_writer *cw,#define ADD (__n, __v) \ do { \ - if (bt_ctf_writer_add_environment_field(writer, __n, __v)) \ + if (__v && bt_ctf_writer_add_environment_field(writer, __n, __v)) \ return -1; \ } while (0)
@@ -1403,6 +1405,52 @@ do { \return 0 ; } +static int process_feature_event (const struct perf_tool *tool, +struct perf_session *session, +union perf_event *event) +{ + struct convert *c = container_of(tool, struct convert, tool); +struct ctf_writer *cw = &c->writer; +struct perf_record_header_feature *fe = &event->feat; + +if (event->feat.feat_id <HEADER_LAST_FEATURE ) { +int ret =perf_event__process_feature (session, event); + +if (ret) +return ret; + } + +switch (fe->feat_id) { +case HEADER_HOSTNAME : +if (session->header.env.hostname) { +return bt_ctf_writer_add_environment_field (cw->writer,"host" , + session->header.env.hostname); + } +break ; +case HEADER_OSRELEASE : +if (session->header.env.os_release) { +return bt_ctf_writer_add_environment_field (cw->writer,"release" , + session->header.env.os_release); + } +break ; +case HEADER_VERSION : +if (session->header.env.version) { +return bt_ctf_writer_add_environment_field (cw->writer,"version" , + session->header.env.version); + } +break ; +case HEADER_ARCH : +if (session->header.env.arch) { +return bt_ctf_writer_add_environment_field (cw->writer,"machine" , + session->header.env.arch); + } +break ; +default : +break ; + } +return 0 ; +} +static int ctf_writer__setup_clock (struct ctf_writer *cw,struct perf_session *session,bool tod)
@@ -1635,6 +1683,8 @@ int bt_convert__perf2ctf(const char *input, const char *path, c.tool.tracing_data = perf_event__process_tracing_data; c.tool.build_id = perf_event__process_build_id; c.tool.namespaces = perf_event__process_namespaces; + c.tool.attr = perf_event__process_attr; + c.tool.feature = process_feature_event; c.tool.ordering_requires_timestamps = true;if (opts->all) {
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 4/5 perf test: Test pipe mode with data conversion --to-json
In reply to Ian RogersAdd pipe mode test for json data conversion. Tidy up exit and cleanup code.
--- .../shell/test_perf_data_converter_json.sh | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-)
tools/perf/tests/shell/test_perf_data_converter_json.sh +24 -9
@@ -15,29 +15,42 @@ result=$(mktemp /tmp/__perf_test.output.json.XXXXX) cleanup() { - rm -f "${perfdata}" + rm -f "${perfdata}*" rm -f "${result}" trap - exit term int } trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" cleanup - exit ${err} + exit 1 } trap trap_cleanup exit term int test_json_converter_command() { - echo "Testing Perf Data Convertion Command to JSON" - perf record -o "$perfdata" -F 99 -g -- perf test -w noploop > /dev/null 2>&1 - perf data convert --to-json "$result" --force -i "$perfdata" >/dev/null 2>&1 + echo "Testing Perf Data Conversion Command to JSON" + perf record -o "$perfdata" -F 99 -g -- perf test -w noploop + perf data convert --to-json "$result" --force -i "$perfdata" if [ "$(cat ${result} | wc -l)" -gt "0" ] ; then echo "Perf Data Converter Command to JSON [SUCCESS]" else echo "Perf Data Converter Command to JSON [FAILED]" err=1 - exit + fi +} + +test_json_converter_pipe() +{ + echo "Testing Perf Data Conversion Command to JSON (Pipe mode)" + perf record -o - -F 99 -g -- perf test -w noploop > "$perfdata" + cat "$perfdata" | perf data convert --to-json "$result" --force -i - + if [ "$(cat ${result} | wc -l)" -gt "0" ] ; then + echo "Perf Data Converter Command to JSON (Pipe mode) [SUCCESS]" + else + echo "Perf Data Converter Command to JSON (Pipe mode) [FAILED]" + err=1 fi }
@@ -50,16 +63,18 @@ validate_json_format() else echo "The file does not contain valid JSON format [FAILED]" err=1 - exit fi else echo "File not found [FAILED]" - err=2 - exit + err=1 fi } test_json_converter_command validate_json_format +test_json_converter_pipe +validate_json_format + +cleanup exit ${err}
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 5/5 perf test: perf data --to-ctf testing
In reply to Ian RogersIf babeltrace is detected check that --to-ctf functions with a data file and in pipe mode.
--- .../shell/test_perf_data_converter_ctf.sh | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 tools/perf/tests/shell/test_perf_data_converter_ctf.sh
tools/perf/tests/shell/test_perf_data_converter_ctf.sh new file +104 -0
@@ -0,0 +1,104 @@ +#!/bin/bash +# 'perf data convert --to-ctf' command test +# SPDX-License-Identifier: GPL-2.0 + +set -e + +err=0 + +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) +ctf_dir=$(mktemp -d /tmp/__perf_test.ctf.XXXXX) + +cleanup() +{ + rm -f "${perfdata}" + rm -rf "${ctf_dir}" + trap - exit term int +} + +trap_cleanup() +{ + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit ${err} +} +trap trap_cleanup exit term int + +check_babeltrace_support() +{ + if ! perf check feature libbabeltrace + then + echo "perf not linked with libbabeltrace, skipping test" + exit 2 + fi +} + +test_ctf_converter_file() +{ + echo "Testing Perf Data Conversion Command to CTF (File input)" + # Record some data + if ! perf record -o "$perfdata" -F 99 -g -- perf test -w noploop + then + echo "Failed to record perf data" + err=1 + return + fi + + # Cleanup previous ctf dir + rm -rf "${ctf_dir}" + + # Convert + if ! perf data convert --to-ctf "$ctf_dir" --force -i "$perfdata" + then + echo "Perf Data Converter Command to CTF (File input) [FAILED]" + err=1 + return + fi + + if [ -d "${ctf_dir}" ] && [ "$(ls -A "${ctf_dir}")" ] + then + echo "Perf Data Converter Command to CTF (File input) [SUCCESS]" + else + echo "Perf Data Converter Command to CTF (File input) [FAILED]" + echo " Output directory empty or missing" + err=1 + fi +} + +test_ctf_converter_pipe() +{ + echo "Testing Perf Data Conversion Command to CTF (Pipe mode)" + + # Cleanup previous ctf dir + rm -rf "${ctf_dir}" + + # Record to stdout and pipe to $perfdata file + if ! perf record -o - -F 99 -g -- perf test -w noploop > "$perfdata" + then + echo "Failed to record perf data" + err=1 + return + fi + + if ! perf data convert --to-ctf "$ctf_dir" --force -i "$perfdata" + then + echo "Perf Data Converter Command to CTF (Pipe mode) [FAILED]" + err=1 + return + fi + + if [ -d "${ctf_dir}" ] && [ "$(ls -A "${ctf_dir}")" ] + then + echo "Perf Data Converter Command to CTF (Pipe mode) [SUCCESS]" + else + echo "Perf Data Converter Command to CTF (Pipe mode) [FAILED]" + echo " Output directory empty or missing" + err=1 + fi +} + +check_babeltrace_support +test_ctf_converter_file +test_ctf_converter_pipe + +exit ${err}
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Quoted 10 lines · Ian Rogers
Add pipe mode support to perf data conversion. Add testing to perf data with pipe mode and add --to-ctf testing if libbabeltrace is present.
Ian Rogers (5):
perf check: Add libbabeltrace to the listed features perf json: Pipe mode --to-json support
perf json: Pipe mode --to-ctf support
perf test: Test pipe mode with data conversion --to-json perf test: perf data --to-ctf testing
Thanks, applied to perf-tools-next,
- Arnaldo
Quoted 10 lines
tools/perf/builtin-check.c | 1 + .../shell/test_perf_data_converter_ctf.sh | 104 ++++++++++++++++++ .../shell/test_perf_data_converter_json.sh | 33 ++++-- tools/perf/util/data-convert-bt.c | 54 ++++++++- tools/perf/util/data-convert-json.c | 16 +++ 5 files changed, 197 insertions(+), 11 deletions(-) create mode 100755 tools/perf/tests/shell/test_perf_data_converter_ctf.shSignature · 1 line
2.53.0.239.g8d8fc8a987-goog