[PATCH V2] tools: rcu: Added check for argument and usage function

From: Bhaskar Chowdhury
Date: Tue Jan 10 2023 - 06:21:08 EST


Thought it would be good to have some formatted way of letting user know
about, how to use this script properly and added some checking too for missing
argument.


cc: paulmck@xxxxxxxxxx

Signed-off-by: Bhaskar Chowdhury <unixbhaskar@xxxxxxxxx>
---
Changes from V1 : Flip the code blocks of function for logical evaluation
and strip off the path from script when displaying help
tools/rcu/extract-stall.sh | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/tools/rcu/extract-stall.sh b/tools/rcu/extract-stall.sh
index e565697c9f90..6ea76230f72f 100644
--- a/tools/rcu/extract-stall.sh
+++ b/tools/rcu/extract-stall.sh
@@ -1,11 +1,24 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0+
#
-# Extract any RCU CPU stall warnings present in specified file.
-# Filter out clocksource lines. Note that preceding-lines excludes the
-# initial line of the stall warning but trailing-lines includes it.
-#
-# Usage: extract-stall.sh dmesg-file [ preceding-lines [ trailing-lines ] ]
+# This is a usage function to spit out information about properly use this
+# script
+
+usage() {
+
+ echo Extract any RCU CPU stall warnings present in specified file.
+ echo Filter out clocksource lines. Note that preceding-lines excludes the
+ echo initial line of the stall warning but trailing-lines includes it.
+
+ echo Usage: $(basename $0) dmesg-file [ preceding-lines [ trailing-lines ] ]
+}
+
+# Terminate the script, if the argument is missing
+
+if [ $# -eq 0 ];then
+ usage
+ exit 1
+fi

echo $1
preceding_lines="${2-3}"
--
2.38.2