From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C8B7C83013 for ; Wed, 2 Jul 2025 07:28:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDE1B8E0003; Wed, 2 Jul 2025 03:28:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D8DEB8E0002; Wed, 2 Jul 2025 03:28:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7DC38E0003; Wed, 2 Jul 2025 03:28:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B5BEB8E0002 for ; Wed, 2 Jul 2025 03:28:33 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 75174107508 for ; Wed, 2 Jul 2025 07:28:33 +0000 (UTC) X-FDA: 83618496906.01.DF7C1A1 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by imf30.hostedemail.com (Postfix) with ESMTP id A983C80011 for ; Wed, 2 Jul 2025 07:28:31 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=W7ZexnLj; spf=pass (imf30.hostedemail.com: domain of unixbhaskar@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=unixbhaskar@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751441311; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=O0c41L9VTbYMrAm4t2oLCDW8W0XVr26QOniUyuOXhc8=; b=qXdlqV92A5sSlCsMcsp60miJy1nSJod+R5I3jXih0YxemLb6fkgrsdiHawl2D0woK71Oph bOY59ZQy/ncxlPwZ0zkTkhKfd+8g5N0uS2131+tyDIjJ5L/HjvjIGJ0sFOKKqkAvgz6FVY B+6x6e2tuFinWYDqpTzxBL5CJYFMrLk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751441311; a=rsa-sha256; cv=none; b=1Q5bLFDxs/GVu0dF5MZ+v4uIpP+QzSNVA0miYOw+jj1Pq7Uiqo663I/UKeZQe8KCWsD22M MToQIxkD/rANGL7bs8dReZYgFarMwSFXUxgFNBUWAO5V9J2A5YIkiqZyzhXF/6o5sTNhZs 9zYa2VjzazTbeZ349XdVygBA9Hzcwnk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=W7ZexnLj; spf=pass (imf30.hostedemail.com: domain of unixbhaskar@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=unixbhaskar@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6fa980d05a8so69377146d6.2 for ; Wed, 02 Jul 2025 00:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751441311; x=1752046111; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=O0c41L9VTbYMrAm4t2oLCDW8W0XVr26QOniUyuOXhc8=; b=W7ZexnLj1YJmonUBJOW+dQOfPQrfDtt/5sFxZw/b3rCCs02rrmV/AthOfoUQzJ62ll SRDNJ3foePpfsdBLB9DSUvQIGLIZG6cp7diXH3YItZO7zXwzUVnHRO/5pQQiOgKkFcXd Fxqcmr05wxZnX6T5Je+Jbpk6W1/+JbDdyzMv8i915qlttcYnICNNvlJuRl6cOkx+/P11 5v+AYSEYrgdxwW56xTPeTWsc+pYNJOVV3w6NslaTgBrnpGTOTFJtP2f7RZnii1W6e8s9 G6QEwG1z3t8nvf9C6XFeIejemNzv6WzFKMsANDBuu+OmHBAx6eAo+aIopuE+T6wJzjw4 glSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751441311; x=1752046111; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=O0c41L9VTbYMrAm4t2oLCDW8W0XVr26QOniUyuOXhc8=; b=GV/3bw1BC3f5bYtoxPNXzL0AFGgVSTRKzcHYeQUDmD8bPP4J3cvCCTeV8qPs7Gh6+O 8y3FYhKecT4h4s/8YS6DmvEmVJ7fOCiGdQNeCAYupAKCeBUicVTil1wD+9vWZIAOTw7k d3oYLKm6SwQpNroeFa3n+Lml1G3dtbujmK9fgoCUbbizN9ArJJlTHfDIlqyC5PQum/ZM uod1i8P0WRb+YkAcoPzlbL7QEg9u0MofLwDqj3l3YeFhO/1IFzNF9U2FZUp7McD4BtEt dzggJAKSCR3H6QgL/sJmC1BLBoZ7HKjnsq5iXsop2JBVHiueNhK5ED0c1NBSXU8hmdQ8 9Ogg== X-Forwarded-Encrypted: i=1; AJvYcCVUqD/GGMaqOc0rkMn3kaMmPj+H96yqcDvQSfl4/Pzin/4r2FtexzB06aeZizIh/FY78VMhpN6n6A==@kvack.org X-Gm-Message-State: AOJu0Yxl0aj7m5TcYlBzGS+nK6iYMg6vK74nTwmi3IPLTFTMHRqvg8BN LFDHWWAqDh6Wyu7l1HoZwO/YODvK5//P2KQhDqxZtyXaTsQuMv8l8KS+ X-Gm-Gg: ASbGnctFEYZTI9105Ql4g6pfQRDX/yATQpIqYuOQCNzwMsugQbqmaEwmckh3D/ar/2v eviqm+RC94LIEtkm+pRjNfqdBHVoytie+GSOovdd3EsFWbSqFvrF8oEcneVeGVmI4tYB29hALG3 NwrlkJz4g9GUKUxy7h2XFBhlIMceEu9qA2xUhNgU7YwX2pv6y1bA+pmPw41oyvFUsUqpxHDff3g Kf6qd45CKwDObPlnNtJvrIjWyeyeGdBSUUHmwNh8z/tGhxy9Rd6fRHyn7zGEbl0x0ajEY/DOrR/ b7TThvW4zPTACKVw4/1CU9Jk8PAajzlOgPlOYBFRyEQC76nsl4xqtCTGuOwjooMgMOHalCfg X-Google-Smtp-Source: AGHT+IH96QKpHxensxCFYjfvqCsEceqBocyK2U3z8xvgLq5e6wKTGkMZxTJ7mrG1s9+xfl5blen4TQ== X-Received: by 2002:ad4:5948:0:b0:6e8:fe16:4d44 with SMTP id 6a1803df08f44-702b1c04e2dmr24082656d6.31.1751441310668; Wed, 02 Jul 2025 00:28:30 -0700 (PDT) Received: from Gentoo.localdomain ([37.19.198.234]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fd77307918sm96615876d6.101.2025.07.02.00.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 00:28:29 -0700 (PDT) From: Bhaskar Chowdhury To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Bhaskar Chowdhury Subject: [PATCH V2] tools: mm: Added modern version of shell quote and a stanza Date: Wed, 2 Jul 2025 12:19:18 +0530 Message-ID: <20250702072801.10216-1-unixbhaskar@gmail.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A983C80011 X-Stat-Signature: cqrqt14d5xh71w78j7yc8m6xmcohu5xz X-HE-Tag: 1751441311-241363 X-HE-Meta: U2FsdGVkX18FJ1rHpc3r/kJv+geu66qbbxUYNBK8icoEbvb71tRNoWZhFxy+oIC+aVV0ZnPqC2CorXt69yANdhHBo6Q3cG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+UkDhXMCDIWRvyXpcfPEDAJD8UybIZwLOrmv25dZXSKvmpvvuGi8o7wnDdJ2fz7pxqiki4lE7KRUIevl9st5jZe581t0WuXsq/lvSIB2L8+ViT5W6ImgEjRtgvbeQLu7NLAaKdPMnjtGc3MHrysjU1yLif8oB9cx6L5SNkiKRodIV6MOnPlXxjLIunOyvFTWFN+fKKfp5qav/qbtljKI7Z0RFhMiagOG8VYKKcB9JcfVEbCbbIOVeRZNrQcIDvH44tuc0U6X X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Three things precisely: Replaced backquote with dollar-parentheses ...that is modern way of quoting in shell script. Improved readability. Added a stranza of missing/required command for the operation,in this case gnuplot and that too in shell path. And lastly,use "command -v" to search the command i.e gnuplot and the REASON for that : The -v option tell show shell will invoke the command specified as its options.Basically to avoid dependency on something outside of the shell.It is also execute command found in the PATH. Essentially, ignoring other similar name stuff curated somewhere else in the system. Signed-off-by: Bhaskar Chowdhury --- V2: What changes from V1: Verbose changelog, especially using command -v to find the specific program i.e. gnuplot. tools/mm/slabinfo-gnuplot.sh | 44 ++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/tools/mm/slabinfo-gnuplot.sh b/tools/mm/slabinfo-gnuplot.sh index 873a892147e5..6c9add4bb8ad 100644 --- a/tools/mm/slabinfo-gnuplot.sh +++ b/tools/mm/slabinfo-gnuplot.sh @@ -46,6 +46,22 @@ check_file_exist() fi } +# This variable could have space separated value +my_needed_commands="gnuplot" + +missing_counter=0 +for needed_command in $my_needed_commands; do + if ! hash "$needed_command" >/dev/null 2>&1; then + printf "Command not found in PATH: %s\n" "$needed_command" >&2 + ((missing_counter++)) + fi +done + +if ((missing_counter > 0)); then + printf "Minimum %d commands are missing in PATH, aborting\n" "$missing_counter" >&2 + exit 1 +fi + do_slabs_plotting() { local file=$1 @@ -58,13 +74,13 @@ do_slabs_plotting() check_file_exist "$file" - out_file=`basename "$file"` + out_file=$(basename "$file") if [ $xmax -ne 0 ]; then range="$range::$xmax" lines=$((xmax-xmin)) fi - wc_lines=`cat "$file" | wc -l` + wc_lines=$(cat "$file" | wc -l) if [ $? -ne 0 ] || [ "$wc_lines" -eq 0 ] ; then wc_lines=$lines fi @@ -78,7 +94,7 @@ do_slabs_plotting() xtic_rotate=90 fi -gnuplot -p << EOF +$(command -v gnuplot) -p << EOF #!/usr/bin/env gnuplot set terminal png enhanced size $width,$height large @@ -113,14 +129,14 @@ do_totals_plotting() for i in "${t_files[@]}"; do check_file_exist "$i" - file="$file"`basename "$i"` + file="$file"$(basename "$i") gnuplot_cmd="$gnuplot_cmd '$i' $range using 1 title\ '$i Memory usage' with lines," gnuplot_cmd="$gnuplot_cmd '' $range using 2 title \ '$i Loss' with lines," done -gnuplot -p << EOF +$(command -v gnuplot) -p << EOF #!/usr/bin/env gnuplot set terminal png enhanced size $width,$height large @@ -148,26 +164,26 @@ do_preprocess() # use only 'TOP' slab (biggest memory usage or loss) let lines=3 - out=`basename "$in"`"-slabs-by-loss" - `cat "$in" | grep -A "$lines" 'Slabs sorted by loss' |\ + out=$(basename "$in")"-slabs-by-loss" + $(cat "$in" | grep -A "$lines" 'Slabs sorted by loss' |\ grep -E -iv '\-\-|Name|Slabs'\ - | awk '{print $1" "$4+$2*$3" "$4}' > "$out"` + | awk '{print $1" "$4+$2*$3" "$4}' > "$out") if [ $? -eq 0 ]; then do_slabs_plotting "$out" fi let lines=3 - out=`basename "$in"`"-slabs-by-size" - `cat "$in" | grep -A "$lines" 'Slabs sorted by size' |\ + out=$(basename "$in")"-slabs-by-size" + $(cat "$in" | grep -A "$lines" 'Slabs sorted by size' |\ grep -E -iv '\-\-|Name|Slabs'\ - | awk '{print $1" "$4" "$4-$2*$3}' > "$out"` + | awk '{print $1" "$4" "$4-$2*$3}' > "$out") if [ $? -eq 0 ]; then do_slabs_plotting "$out" fi - out=`basename "$in"`"-totals" - `cat "$in" | grep "Memory used" |\ - awk '{print $3" "$7}' > "$out"` + out=$(basename "$in")"-totals" + $(cat "$in" | grep "Memory used" |\ + awk '{print $3" "$7}' > "$out") if [ $? -eq 0 ]; then t_files[0]=$out do_totals_plotting -- 2.49.0