]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added a debugging tool: scripts/trace-context.pl (#1039)
authorAlex Rousskov <rousskov@measurement-factory.com>
Mon, 9 May 2022 13:20:26 +0000 (13:20 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 9 May 2022 18:03:56 +0000 (18:03 +0000)
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
scripts/trace-context.pl [new file with mode: 0755]

index 2e8b47cc97de35862e2a9baae92211f40b6eb8b9..e40d0542c6956af09d67b15e26e873b3ca9e7d9e 100644 (file)
@@ -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 (executable)
index 0000000..7732878
--- /dev/null
@@ -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 <CodeContext id> [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);