Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: add small tool for debug log analysis #3145

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions tests/debug_extract.sh
@@ -0,0 +1,42 @@
#!/bin/bash
# This is primarily a tool to extract relevant parts of large debug
# files
# usage:
# $1 - file to search
# $2 - search term
# $3 - number of lines before first match (optional, default 5000)
# $4 - number of lines after first match (optional, default 10000)
# output is directed to stdout - use redirection if desired
#
# Copyright (C) 2018 by Rainer Gerhards, released under ASL 2.0

if [ "$1" == "" ]; then
echo file name must be given
exit 1
fi
if [ "$2" == "" ]; then
echo search term must be given
exit 1
fi
FILE="$1"
SEARCH_TERM="$2"
if [ "$3" == "" ]; then
LINES_BEFORE=5000
else
LINES_BEFORE="$3"
fi
if [ "$4" == "" ]; then
LINES_AFTER=5000
else
LINES_AFTER="$4"
fi
line=$(cat -n $FILE | grep "$SEARCH_TERM" |cut -f1 |head -1)
if [ "$line" == "" ]; then
echo search term not found!
exit 1
fi
startline=$((line-LINES_BEFORE))
numlines=$((LINES_AFTER + LINES_BEFORE+1)) # +1 for search term line itself!
printf "file %s lines %d to %d, arround first occurence of '%s':\n" \
$FILE $startline $((startline+numlines)) $SEARCH_TERM
tail -n +$startline $FILE | head -n $numlines