linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] perf: test: Add support for testing JSON generated by perf data command
@ 2023-05-19  7:41 Anup Sharma
  2023-05-22 18:10 ` Ian Rogers
  0 siblings, 1 reply; 5+ messages in thread
From: Anup Sharma @ 2023-05-19  7:41 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Anup Sharma, linux-perf-users,
	linux-kernel

This commit adds support for testing the JSON output generated
by the perf data command's conversion to JSON functionality.
The test script now includes a validation step to ensure that
the resulting JSON file is contain valid data.

Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>

Changes:
V1 -> V2: Added a check for the existence of the result output file.
          Replaced the usage of jq with json.load for validating the JSON format.
          Checks using ShellCheck and checkpatch, addressing and resolving warnings.
          Removed the unnecessary root permission check.
          Modified the perf record command to avoid requiring root permissions.
---
 .../shell/test_perf_data_converter_json.sh    | 78 +++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100755 tools/perf/tests/shell/test_perf_data_converter_json.sh

diff --git a/tools/perf/tests/shell/test_perf_data_converter_json.sh b/tools/perf/tests/shell/test_perf_data_converter_json.sh
new file mode 100755
index 000000000000..54b7a19962fa
--- /dev/null
+++ b/tools/perf/tests/shell/test_perf_data_converter_json.sh
@@ -0,0 +1,78 @@
+#!/bin/bash
+# perf data json converter command test
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+
+if [ "$PYTHON" = "" ]
+then
+	if which python3 > /dev/null
+	then
+		PYTHON=python3
+	elif which python > /dev/null
+	then
+		PYTHON=python
+	else
+		echo Skipping test, python not detected please set environment variable PYTHON.
+		exit 2
+	fi
+fi
+
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+result=$(mktemp /tmp/__perf_test.output.json.XXXXX)
+
+cleanup()
+{
+	rm -f "${perfdata}"
+	rm -f "${result}"
+	trap - exit term int
+}
+
+trap_cleanup()
+{
+	cleanup
+	exit ${err}
+}
+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
+	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
+}
+
+validate_json_format()
+{
+    echo "Validating Perf Data Converted JSON file"
+    if [ -f "$result" ]
+    then
+        if $PYTHON -c  "import json; json.load(open('$result'))" >/dev/null 2>&1
+	then
+            echo "The file contains valid JSON format [SUCCESS]"
+        else
+            echo "The file does not contain valid JSON format [FAILED]"
+            err=1
+	    exit
+        fi
+    else
+        echo "File not found [FAILED]"
+        err=2
+        exit
+    fi
+}
+
+test_json_converter_command
+validate_json_format
+
+exit ${err}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] perf: test: Add support for testing JSON generated by perf data command
  2023-05-19  7:41 [PATCH v2] perf: test: Add support for testing JSON generated by perf data command Anup Sharma
@ 2023-05-22 18:10 ` Ian Rogers
  2023-05-22 18:28   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Rogers @ 2023-05-22 18:10 UTC (permalink / raw)
  To: Anup Sharma
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Adrian Hunter, linux-perf-users, linux-kernel

On Fri, May 19, 2023 at 12:41 AM Anup Sharma <anupnewsmail@gmail.com> wrote:
>
> This commit adds support for testing the JSON output generated
> by the perf data command's conversion to JSON functionality.
> The test script now includes a validation step to ensure that
> the resulting JSON file is contain valid data.
>
> Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> Changes:
> V1 -> V2: Added a check for the existence of the result output file.
>           Replaced the usage of jq with json.load for validating the JSON format.
>           Checks using ShellCheck and checkpatch, addressing and resolving warnings.
>           Removed the unnecessary root permission check.
>           Modified the perf record command to avoid requiring root permissions.
> ---
>  .../shell/test_perf_data_converter_json.sh    | 78 +++++++++++++++++++
>  1 file changed, 78 insertions(+)
>  create mode 100755 tools/perf/tests/shell/test_perf_data_converter_json.sh
>
> diff --git a/tools/perf/tests/shell/test_perf_data_converter_json.sh b/tools/perf/tests/shell/test_perf_data_converter_json.sh
> new file mode 100755
> index 000000000000..54b7a19962fa
> --- /dev/null
> +++ b/tools/perf/tests/shell/test_perf_data_converter_json.sh
> @@ -0,0 +1,78 @@
> +#!/bin/bash
> +# perf data json converter command test
> +# SPDX-License-Identifier: GPL-2.0
> +
> +set -e
> +
> +err=0
> +
> +if [ "$PYTHON" = "" ]
> +then
> +       if which python3 > /dev/null
> +       then
> +               PYTHON=python3
> +       elif which python > /dev/null
> +       then
> +               PYTHON=python
> +       else
> +               echo Skipping test, python not detected please set environment variable PYTHON.
> +               exit 2
> +       fi
> +fi
> +
> +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
> +result=$(mktemp /tmp/__perf_test.output.json.XXXXX)
> +
> +cleanup()
> +{
> +       rm -f "${perfdata}"
> +       rm -f "${result}"
> +       trap - exit term int
> +}
> +
> +trap_cleanup()
> +{
> +       cleanup
> +       exit ${err}
> +}
> +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
> +       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
> +}
> +
> +validate_json_format()
> +{
> +    echo "Validating Perf Data Converted JSON file"
> +    if [ -f "$result" ]
> +    then
> +        if $PYTHON -c  "import json; json.load(open('$result'))" >/dev/null 2>&1
> +       then
> +            echo "The file contains valid JSON format [SUCCESS]"
> +        else
> +            echo "The file does not contain valid JSON format [FAILED]"
> +            err=1
> +           exit
> +        fi
> +    else
> +        echo "File not found [FAILED]"
> +        err=2
> +        exit
> +    fi
> +}
> +
> +test_json_converter_command
> +validate_json_format
> +
> +exit ${err}
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] perf: test: Add support for testing JSON generated by perf data command
  2023-05-22 18:10 ` Ian Rogers
@ 2023-05-22 18:28   ` Arnaldo Carvalho de Melo
  2023-05-22 18:31     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-05-22 18:28 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Anup Sharma, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	linux-perf-users, linux-kernel

Em Mon, May 22, 2023 at 11:10:43AM -0700, Ian Rogers escreveu:
> On Fri, May 19, 2023 at 12:41 AM Anup Sharma <anupnewsmail@gmail.com> wrote:
> >
> > This commit adds support for testing the JSON output generated
> > by the perf data command's conversion to JSON functionality.
> > The test script now includes a validation step to ensure that
> > the resulting JSON file is contain valid data.
> >
> > Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>
> 
> Acked-by: Ian Rogers <irogers@google.com>

I'm fixing these and some other identation minor issues:

[acme@quaco perf-tools-next]$ b4 am -ctsl --cc-trailers CAP-5=fXyqWYgR0M0rqG8a2j0sL1WThNX8r49T7EfvkOG32-UqA@mail.gmail.com
Grabbing thread from lore.kernel.org/all/CAP-5%3DfXyqWYgR0M0rqG8a2j0sL1WThNX8r49T7EfvkOG32-UqA%40mail.gmail.com/t.mbox.gz
Checking for newer revisions
Grabbing search results from lore.kernel.org
Analyzing 2 messages in the thread
Checking attestation on all messages, may take a moment...
---
  [PATCH v2] perf: test: Add support for testing JSON generated by perf data command
    + Acked-by: Ian Rogers <irogers@google.com>
    + Link: https://lore.kernel.org/r/ZGcoJBAGlknjsA/n@yoga
    + Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  ---
  NOTE: install dkimpy for DKIM signature verification
---
Total patches: 1
---
 Link: https://lore.kernel.org/r/ZGcoJBAGlknjsA/n@yoga
 Base: not specified
       git am ./v2_20230519_anupnewsmail_perf_test_add_support_for_testing_json_generated_by_perf_data_command.mbx
[acme@quaco perf-tools-next]$        git am ./v2_20230519_anupnewsmail_perf_test_add_support_for_testing_json_generated_by_perf_data_command.mbx
Applying: perf: test: Add support for testing JSON generated by perf data command
.git/rebase-apply/patch:59: trailing whitespace.
	else
warning: 1 line adds whitespace errors.
tools/perf/tests/shell/test_perf_data_converter_json.sh:48: trailing whitespace.
+	else
[acme@quaco perf-tools-next]$


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] perf: test: Add support for testing JSON generated by perf data command
  2023-05-22 18:28   ` Arnaldo Carvalho de Melo
@ 2023-05-22 18:31     ` Arnaldo Carvalho de Melo
  2023-05-22 18:43       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-05-22 18:31 UTC (permalink / raw)
  To: Anup Sharma
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	linux-perf-users, linux-kernel

Em Mon, May 22, 2023 at 03:28:20PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, May 22, 2023 at 11:10:43AM -0700, Ian Rogers escreveu:
> > On Fri, May 19, 2023 at 12:41 AM Anup Sharma <anupnewsmail@gmail.com> wrote:
> > >
> > > This commit adds support for testing the JSON output generated
> > > by the perf data command's conversion to JSON functionality.
> > > The test script now includes a validation step to ensure that
> > > the resulting JSON file is contain valid data.
> > >
> > > Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>
> > 
> > Acked-by: Ian Rogers <irogers@google.com>
> 
> I'm fixing these and some other identation minor issues:

The ones below, using 'set list' on vim, look at the mix of tabs with
spaces:

+validate_json_format()$
+{$
+    echo "Validating Perf Data Converted JSON file"$
+    if [ -f "$result" ]$
+    then$
+        if $PYTHON -c  "import json; json.load(open('$result'))" >/dev/null 2>&1$
+^Ithen$
+            echo "The file contains valid JSON format [SUCCESS]"$
+        else$
+            echo "The file does not contain valid JSON format [FAILED]"$
+            err=1$
+^I    exit$
+        fi$
+    else$
+        echo "File not found [FAILED]"$
+        err=2$
+        exit$
+    fi$
+}$
+$
+test_json_converter_command$
 
> [acme@quaco perf-tools-next]$ b4 am -ctsl --cc-trailers CAP-5=fXyqWYgR0M0rqG8a2j0sL1WThNX8r49T7EfvkOG32-UqA@mail.gmail.com
> Grabbing thread from lore.kernel.org/all/CAP-5%3DfXyqWYgR0M0rqG8a2j0sL1WThNX8r49T7EfvkOG32-UqA%40mail.gmail.com/t.mbox.gz
> Checking for newer revisions
> Grabbing search results from lore.kernel.org
> Analyzing 2 messages in the thread
> Checking attestation on all messages, may take a moment...
> ---
>   [PATCH v2] perf: test: Add support for testing JSON generated by perf data command
>     + Acked-by: Ian Rogers <irogers@google.com>
>     + Link: https://lore.kernel.org/r/ZGcoJBAGlknjsA/n@yoga
>     + Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>   ---
>   NOTE: install dkimpy for DKIM signature verification
> ---
> Total patches: 1
> ---
>  Link: https://lore.kernel.org/r/ZGcoJBAGlknjsA/n@yoga
>  Base: not specified
>        git am ./v2_20230519_anupnewsmail_perf_test_add_support_for_testing_json_generated_by_perf_data_command.mbx
> [acme@quaco perf-tools-next]$        git am ./v2_20230519_anupnewsmail_perf_test_add_support_for_testing_json_generated_by_perf_data_command.mbx
> Applying: perf: test: Add support for testing JSON generated by perf data command
> .git/rebase-apply/patch:59: trailing whitespace.
> 	else
> warning: 1 line adds whitespace errors.
> tools/perf/tests/shell/test_perf_data_converter_json.sh:48: trailing whitespace.
> +	else
> [acme@quaco perf-tools-next]$
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] perf: test: Add support for testing JSON generated by perf data command
  2023-05-22 18:31     ` Arnaldo Carvalho de Melo
@ 2023-05-22 18:43       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-05-22 18:43 UTC (permalink / raw)
  To: Anup Sharma
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	linux-perf-users, linux-kernel

Em Mon, May 22, 2023 at 03:31:06PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, May 22, 2023 at 03:28:20PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Mon, May 22, 2023 at 11:10:43AM -0700, Ian Rogers escreveu:
> > > On Fri, May 19, 2023 at 12:41 AM Anup Sharma <anupnewsmail@gmail.com> wrote:
> > > >
> > > > This commit adds support for testing the JSON output generated
> > > > by the perf data command's conversion to JSON functionality.
> > > > The test script now includes a validation step to ensure that
> > > > the resulting JSON file is contain valid data.
> > > >
> > > > Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>
> > > 
> > > Acked-by: Ian Rogers <irogers@google.com>
> > 
> > I'm fixing these and some other identation minor issues:
> 
I have this on top, making the indentation to be consistent, using tabs,
as the other .sh files in that directory and also having the 'then' be
on the 'if' line, separated by ;

diff --git a/tools/perf/tests/shell/test_perf_data_converter_json.sh b/tools/perf/tests/shell/test_perf_data_converter_json.sh
index 8f4d6575f34fa82e..72ac6c83231c03d5 100755
--- a/tools/perf/tests/shell/test_perf_data_converter_json.sh
+++ b/tools/perf/tests/shell/test_perf_data_converter_json.sh
@@ -1,18 +1,15 @@
 #!/bin/bash
-# perf data json converter command test
+# 'perf data convert --to-json' command test
 # SPDX-License-Identifier: GPL-2.0
 
 set -e
 
 err=0
 
-if [ "$PYTHON" = "" ]
-then
-	if which python3 > /dev/null
-	then
+if [ "$PYTHON" = "" ] ; then
+	if which python3 > /dev/null ; then
 		PYTHON=python3
-	elif which python > /dev/null
-	then
+	elif which python > /dev/null ; then
 		PYTHON=python
 	else
 		echo Skipping test, python not detected please set environment variable PYTHON.
@@ -42,8 +39,7 @@ 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
-	if [ $(cat "${result}" | wc -l) -gt "0" ]
-	then
+	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]"
@@ -54,22 +50,20 @@ test_json_converter_command()
 
 validate_json_format()
 {
-    echo "Validating Perf Data Converted JSON file"
-    if [ -f "$result" ]
-    then
-        if $PYTHON -c  "import json; json.load(open('$result'))" >/dev/null 2>&1
-	then
-            echo "The file contains valid JSON format [SUCCESS]"
-        else
-            echo "The file does not contain valid JSON format [FAILED]"
-            err=1
-	    exit
-        fi
-    else
-        echo "File not found [FAILED]"
-        err=2
-        exit
-    fi
+	echo "Validating Perf Data Converted JSON file"
+	if [ -f "$result" ] ; then
+		if $PYTHON -c  "import json; json.load(open('$result'))" >/dev/null 2>&1 ; then
+			echo "The file contains valid JSON format [SUCCESS]"
+		else
+			echo "The file does not contain valid JSON format [FAILED]"
+			err=1
+			exit
+		fi
+	else
+		echo "File not found [FAILED]"
+		err=2
+		exit
+	fi
 }
 
 test_json_converter_command

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-22 18:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-19  7:41 [PATCH v2] perf: test: Add support for testing JSON generated by perf data command Anup Sharma
2023-05-22 18:10 ` Ian Rogers
2023-05-22 18:28   ` Arnaldo Carvalho de Melo
2023-05-22 18:31     ` Arnaldo Carvalho de Melo
2023-05-22 18:43       ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).