From a0f5ead6fc4591b52dc14ee5d9ea3a1eaf28ba39 Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Mon, 9 May 2022 13:20:26 +0000 Subject: [PATCH] Added a debugging tool: scripts/trace-context.pl (#1039) This debugging script finds cache.log lines that belong to the given CodeContext, identified by its gist (e.g., "conn123" or "master42"). Like other debugging scripts added in commit e83fd25, this one requires maintenance as the cache.log format changes. --- scripts/Makefile.am | 1 + scripts/trace-context.pl | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 scripts/trace-context.pl diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 2e8b47cc97..e40d0542c6 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -9,6 +9,7 @@ EXTRA_DIST = AnnounceCache.pl access-log-matrix.pl cache-compare.pl \ cachetrace.pl check_cache.pl convert.configure.to.os2 \ fileno-to-pathname.pl flag_truncs.pl icp-test.pl \ find-alive.pl trace-job.pl trace-master.pl \ + trace-context.pl \ icpserver.pl tcp-banger.pl udp-banger.pl upgrade-1.0-store.pl \ calc-must-ids.pl calc-must-ids.sh diff --git a/scripts/trace-context.pl b/scripts/trace-context.pl new file mode 100755 index 0000000000..7732878795 --- /dev/null +++ b/scripts/trace-context.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl -w +# +## Copyright (C) 1996-2022 The Squid Software Foundation and contributors +## +## Squid software is distributed under GPLv2+ license and includes +## contributions from numerous individuals and organizations. +## Please see the COPYING and CONTRIBUTORS files for details. +## + +# Reads cache.log and displays lines that correspond to a given CodeContext. + +use strict; +use warnings; + +die("usage: $0 [log filename]\n") unless @ARGV; +my $ContextId = shift; + +my $GroupSeparator = "--\n"; + +my $inside = 0; +my $currentGroup = 0; +my $lastReportedGroup = undef(); +while (<>) { + if (/\bCodeContext.*?\bEntering: (.*)/) { + my $wasInside = $inside; + $inside = $1 eq $ContextId; + + # detect no-Leaving switches from our CodeContext to another + ++$currentGroup if $wasInside && !$inside; + } + + my $external = !$inside && /\b$ContextId\b/o; + + if ($inside || $external) { + ++$currentGroup if $external; + print $GroupSeparator if defined($lastReportedGroup) && $currentGroup != $lastReportedGroup; + print $_; + $lastReportedGroup = $currentGroup; + } else { + ++$currentGroup; + } + + if ($inside && /\bCodeContext.*?\bLeaving: /) { + $inside = 0; + ++$currentGroup; + } +} + +exit(0); -- 2.47.2