1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0+ 3# 4# Extract any RCU CPU stall warnings present in specified file. 5# Filter out clocksource lines. Note that preceding-lines excludes the 6# initial line of the stall warning but trailing-lines includes it. 7# 8# Usage: extract-stall.sh dmesg-file [ preceding-lines [ trailing-lines ] ] 9 10echo $1 11preceding_lines="${2-3}" 12trailing_lines="${3-10}" 13 14awk -v preceding_lines="$preceding_lines" -v trailing_lines="$trailing_lines" ' 15suffix <= 0 { 16 for (i = preceding_lines; i > 0; i--) 17 last[i] = last[i - 1]; 18 last[0] = $0; 19} 20 21suffix > 0 { 22 print $0; 23 suffix--; 24 if (suffix <= 0) 25 print ""; 26} 27 28suffix <= 0 && /detected stall/ { 29 for (i = preceding_lines; i >= 0; i--) 30 if (last[i] != "") 31 print last[i]; 32 suffix = trailing_lines; 33}' < "$1" | tr -d '\015' | grep -v clocksource 34 35