xref: /openbmc/linux/tools/rcu/extract-stall.sh (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
12010776fSPaul E. McKenney#!/bin/sh
22010776fSPaul E. McKenney# SPDX-License-Identifier: GPL-2.0+
3*236bdb88SBhaskar Chowdhury
4*236bdb88SBhaskar Chowdhuryusage() {
5*236bdb88SBhaskar Chowdhury	echo Extract any RCU CPU stall warnings present in specified file.
6*236bdb88SBhaskar Chowdhury	echo Filter out clocksource lines.  Note that preceding-lines excludes the
7*236bdb88SBhaskar Chowdhury	echo initial line of the stall warning but trailing-lines includes it.
8*236bdb88SBhaskar Chowdhury	echo
9*236bdb88SBhaskar Chowdhury	echo Usage: $(basename $0) dmesg-file [ preceding-lines [ trailing-lines ] ]
10*236bdb88SBhaskar Chowdhury	echo
11*236bdb88SBhaskar Chowdhury	echo Error: $1
12*236bdb88SBhaskar Chowdhury}
13*236bdb88SBhaskar Chowdhury
14*236bdb88SBhaskar Chowdhury# Terminate the script, if the argument is missing
15*236bdb88SBhaskar Chowdhury
16*236bdb88SBhaskar Chowdhuryif test -f "$1" && test -r "$1"
17*236bdb88SBhaskar Chowdhurythen
18*236bdb88SBhaskar Chowdhury	:
19*236bdb88SBhaskar Chowdhuryelse
20*236bdb88SBhaskar Chowdhury	usage "Console log file \"$1\" missing or unreadable."
21*236bdb88SBhaskar Chowdhury	exit 1
22*236bdb88SBhaskar Chowdhuryfi
232010776fSPaul E. McKenney
242010776fSPaul E. McKenneyecho $1
252010776fSPaul E. McKenneypreceding_lines="${2-3}"
262010776fSPaul E. McKenneytrailing_lines="${3-10}"
272010776fSPaul E. McKenney
282010776fSPaul E. McKenneyawk -v preceding_lines="$preceding_lines" -v trailing_lines="$trailing_lines" '
292010776fSPaul E. McKenneysuffix <= 0 {
302010776fSPaul E. McKenney	for (i = preceding_lines; i > 0; i--)
312010776fSPaul E. McKenney		last[i] = last[i - 1];
322010776fSPaul E. McKenney	last[0] = $0;
332010776fSPaul E. McKenney}
342010776fSPaul E. McKenney
352010776fSPaul E. McKenneysuffix > 0 {
362010776fSPaul E. McKenney	print $0;
372010776fSPaul E. McKenney	suffix--;
382010776fSPaul E. McKenney	if (suffix <= 0)
392010776fSPaul E. McKenney		print "";
402010776fSPaul E. McKenney}
412010776fSPaul E. McKenney
422010776fSPaul E. McKenneysuffix <= 0 && /detected stall/ {
432010776fSPaul E. McKenney	for (i = preceding_lines; i >= 0; i--)
442010776fSPaul E. McKenney		if (last[i] != "")
452010776fSPaul E. McKenney			print last[i];
462010776fSPaul E. McKenney	suffix = trailing_lines;
472010776fSPaul E. McKenney}' < "$1" | tr -d '\015' | grep -v clocksource
482010776fSPaul E. McKenney
49