linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Add support for firefox gecko converter test and commands
@ 2023-07-20 14:22 Anup Sharma
  2023-07-20 14:23 ` [PATCH 1/2] perf scripts python: Add command execution for firefox gecko converter script Anup Sharma
  2023-07-20 14:24 ` [PATCH 2/2] perf test: Add support for testing " Anup Sharma
  0 siblings, 2 replies; 3+ messages in thread
From: Anup Sharma @ 2023-07-20 14:22 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 patchset adds support for firefox gecko converter test and commands.
The firefox gecko converter is a python script which converts the
perf.data file into firefox gecko profile format. The script is
available at tools/perf/scripts/python/firefox-gecko-converter.py

Anup Sharma (2):
  perf scripts python: Add command execution for converter
  perf test: Add support for testing firefox-gecko-converter script

 .../python/bin/firefox-gecko-converter-record |   2 +
 .../python/bin/firefox-gecko-converter-report |   3 +
 .../shell/test_firefox-gecko-converter.sh     | 190 ++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100755 tools/perf/scripts/python/bin/firefox-gecko-converter-record
 create mode 100755 tools/perf/scripts/python/bin/firefox-gecko-converter-report
 create mode 100755 tools/perf/tests/shell/test_firefox-gecko-converter.sh

-- 
2.34.1


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

* [PATCH 1/2] perf scripts python: Add command execution for firefox gecko converter script
  2023-07-20 14:22 [PATCH 0/2] Add support for firefox gecko converter test and commands Anup Sharma
@ 2023-07-20 14:23 ` Anup Sharma
  2023-07-20 14:24 ` [PATCH 2/2] perf test: Add support for testing " Anup Sharma
  1 sibling, 0 replies; 3+ messages in thread
From: Anup Sharma @ 2023-07-20 14:23 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 will enable the execution of firefox-gecko-converter.py script
using record and report commands.

Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>
---
 tools/perf/scripts/python/bin/firefox-gecko-converter-record | 2 ++
 tools/perf/scripts/python/bin/firefox-gecko-converter-report | 3 +++
 2 files changed, 5 insertions(+)
 create mode 100755 tools/perf/scripts/python/bin/firefox-gecko-converter-record
 create mode 100755 tools/perf/scripts/python/bin/firefox-gecko-converter-report

diff --git a/tools/perf/scripts/python/bin/firefox-gecko-converter-record b/tools/perf/scripts/python/bin/firefox-gecko-converter-record
new file mode 100755
index 000000000000..7df5a19c0163
--- /dev/null
+++ b/tools/perf/scripts/python/bin/firefox-gecko-converter-record
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -g "$@"
diff --git a/tools/perf/scripts/python/bin/firefox-gecko-converter-report b/tools/perf/scripts/python/bin/firefox-gecko-converter-report
new file mode 100755
index 000000000000..2405c6b26446
--- /dev/null
+++ b/tools/perf/scripts/python/bin/firefox-gecko-converter-report
@@ -0,0 +1,3 @@
+#!/bin/bash
+# description: create firefox gecko profile json format from perf.data
+perf script -s "$PERF_EXEC_PATH"/scripts/python/firefox-gecko-converter.py -- "$@"
-- 
2.34.1


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

* [PATCH 2/2] perf test: Add support for testing firefox gecko converter script
  2023-07-20 14:22 [PATCH 0/2] Add support for firefox gecko converter test and commands Anup Sharma
  2023-07-20 14:23 ` [PATCH 1/2] perf scripts python: Add command execution for firefox gecko converter script Anup Sharma
@ 2023-07-20 14:24 ` Anup Sharma
  1 sibling, 0 replies; 3+ messages in thread
From: Anup Sharma @ 2023-07-20 14:24 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 add support for testing firefox-gecko-converter script.
This test checks for the presence of required sections such as "meta,"
"threads," "samples," "frameTable," "stackTable," "stringTable,"
and "pausedRanges" which are few essential parameter to be present
in output file. It also tests for user-defined color changes using
the --user-color flag, and verifies the validity of the JSON format
using Python's JSON library if available.

Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>
---
 .../shell/test_firefox-gecko-converter.sh     | 190 ++++++++++++++++++
 1 file changed, 190 insertions(+)
 create mode 100755 tools/perf/tests/shell/test_firefox-gecko-converter.sh

diff --git a/tools/perf/tests/shell/test_firefox-gecko-converter.sh b/tools/perf/tests/shell/test_firefox-gecko-converter.sh
new file mode 100755
index 000000000000..7c30191efb91
--- /dev/null
+++ b/tools/perf/tests/shell/test_firefox-gecko-converter.sh
@@ -0,0 +1,190 @@
+#!/bin/bash
+# perf script firefox-gecko-converter tests
+# SPDX-License-Identifier: GPL-2.0
+
+#set -x
+
+err=0
+
+if [ "$PYTHON" = "" ] ; then
+	if which python3 > /dev/null ; then
+		PYTHON=python3
+	elif which python > /dev/null ; then
+		PYTHON=python
+	else
+		echo Skipping JSON format check, python not detected please set environment variable PYTHON.
+		PYTHON_NOT_AVAILABLE=1
+	fi
+fi
+
+# set PERF_EXEC_PATH to find scripts in the source directory
+perfdir=$(dirname "$0")/../..
+if [ -e "$perfdir/scripts/python/Perf-Trace-Util" ]; then
+  export PERF_EXEC_PATH=$perfdir
+fi
+
+tmpdir=$(mktemp -d /tmp/perf-script-firefox-gecko-converter-XXXXX)
+
+cleanup() {
+  rm -f perf.data
+  rm -f perf.data.old
+  rm -rf "$tmpdir"
+  trap - exit term int
+}
+
+trap_cleanup() {
+  cleanup
+  exit 1
+}
+trap trap_cleanup exit term int
+
+report() {
+	if [ "$1" = 0 ]; then
+		echo "PASS: \"$2\""
+	else
+		echo "FAIL: \"$2\" Error message: \"$3\""
+		err=1
+	fi
+}
+
+check_exec_0() {
+	if [ $? != 0 ]; then
+		report 1 "invocation of $1 command failed"
+	fi
+}
+
+find_str_or_fail() {
+	#echo "\"$1"\"
+	#echo "\"$2"\"
+	grep -q "$1" "$2"
+	if [ "$?" != 0 ]; then
+		report 1 "$3" "Failed to find required string:'${1}'."
+	else
+		report 0 "$3"
+	fi
+}
+
+prepare_perf_data() {
+	# 3s should be sufficient to catch few samples
+	perf record -g -- sleep 3 > /dev/null 2>&1
+	# check if perf data file got created in above step.
+	if [ ! -e "perf.data" ]; then
+		printf "FAIL: perf record failed to create \"perf.data\" \n"
+		return 1
+	fi
+}
+
+# check execution of command
+test_firefox-gecko_converter_command()
+{
+	echo "Testing Firefox Gecko Converter Command"
+	out="$tmpdir/perf.out"
+	perf script report firefox-gecko-converter > "$out"
+	check_exec_0 "perf script report firefox-gecko-converter"
+	if [ $(cat "${out}" | wc -l) -gt "0" ] ; then
+		echo "PASS: \"Firefox Gecko Converter Command\""
+	else
+		echo "FAIL: \"Firefox Gecko Converter Command\""
+		err=1
+		exit
+	fi
+}
+
+# with the help of python json libary validate the json output
+if [ "$PYTHON_NOT_AVAILABLE" != "0" ]; then
+	validate_json_format()
+	{
+		out="$tmpdir/perf.out"
+		if [ -f "$out" ] ; then
+			if $PYTHON -c  "import json; json.load(open('$out'))" >/dev/null 2>&1 ; then
+				echo "PASS: \"The file contains valid JSON format\""
+			else
+				echo "FAIL: \"The file does not contain valid JSON format\""
+				err=1
+				exit
+			fi
+		else
+			echo "FAIL: \"File not found\""
+			err=2
+			exit
+		fi
+	}
+fi
+
+# validate output for the presence of "meta".
+test_meta() {
+	out="$tmpdir/perf.out"
+	perf script report firefox-gecko-converter > "$out"
+	check_exec_0 "perf script report firefox-gecko-converter"
+	find_str_or_fail "meta" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "threads".
+test_threads() {
+	out="$tmpdir/perf.out"
+	perf script report firefox-gecko-converter > "$out"
+	check_exec_0 "perf script report firefox-gecko-converter"
+	find_str_or_fail "threads" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "samples".
+test_samples() {
+	out="$tmpdir/perf.out"
+	perf script report firefox-gecko-converter > "$out"
+	check_exec_0 "perf script report firefox-gecko-converter"
+	find_str_or_fail "samples" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "frameTable".
+test_frametable() {
+	out="$tmpdir/perf.out"
+	perf script report firefox-gecko-converter > "$out"
+	check_exec_0 "perf script report firefox-gecko-converter"
+	find_str_or_fail "frameTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stackTable".
+test_stacktable() {
+	out="$tmpdir/perf.out"
+	perf script report firefox-gecko-converter > "$out"
+	check_exec_0 "perf script report firefox-gecko-converter"
+	find_str_or_fail "stackTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stringTable"
+test_stringtable() {
+	out="$tmpdir/perf.out"
+	perf script report firefox-gecko-converter > "$out"
+	check_exec_0 "perf script report firefox-gecko-converter"
+	find_str_or_fail "stringTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "pausedRanges".
+test_pauseranges(){
+	out="$tmpdir/perf.out"
+	perf script report firefox-gecko-converter > "$out"
+	check_exec_0 "perf script report firefox-gecko-converter"
+	find_str_or_fail "pausedRanges" "$out" "${FUNCNAME[0]}"
+}
+
+# validate user-defined color presence in output "green"
+test_categorycolorchange(){
+	out="$tmpdir/perf.out"
+	perf script report firefox-gecko-converter --user-color="green"> "$out"
+	check_exec_0 "perf script report firefox-gecko-converter --user-color"
+	find_str_or_fail "green" "$out" "${FUNCNAME[0]}"
+}
+
+prepare_perf_data
+test_firefox-gecko_converter_command
+validate_json_format
+test_meta
+test_threads
+test_samples
+test_frametable
+test_stacktable
+test_stringtable
+test_pauseranges
+test_categorycolorchange
+cleanup
+exit $err
-- 
2.34.1


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

end of thread, other threads:[~2023-07-20 14:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-20 14:22 [PATCH 0/2] Add support for firefox gecko converter test and commands Anup Sharma
2023-07-20 14:23 ` [PATCH 1/2] perf scripts python: Add command execution for firefox gecko converter script Anup Sharma
2023-07-20 14:24 ` [PATCH 2/2] perf test: Add support for testing " Anup Sharma

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).