]> git.ipfire.org Git - thirdparty/squid.git/blame - scripts/trace-context.pl
Source Format Enforcement (#1234)
[thirdparty/squid.git] / scripts / trace-context.pl
CommitLineData
a0f5ead6
AR
1#!/usr/bin/perl -w
2#
b8ae064d 3## Copyright (C) 1996-2023 The Squid Software Foundation and contributors
a0f5ead6
AR
4##
5## Squid software is distributed under GPLv2+ license and includes
6## contributions from numerous individuals and organizations.
7## Please see the COPYING and CONTRIBUTORS files for details.
8##
9
10# Reads cache.log and displays lines that correspond to a given CodeContext.
11
12use strict;
13use warnings;
14
15die("usage: $0 <CodeContext id> [log filename]\n") unless @ARGV;
16my $ContextId = shift;
17
18my $GroupSeparator = "--\n";
19
20my $inside = 0;
21my $currentGroup = 0;
22my $lastReportedGroup = undef();
23while (<>) {
24 if (/\bCodeContext.*?\bEntering: (.*)/) {
25 my $wasInside = $inside;
26 $inside = $1 eq $ContextId;
27
28 # detect no-Leaving switches from our CodeContext to another
29 ++$currentGroup if $wasInside && !$inside;
30 }
31
32 my $external = !$inside && /\b$ContextId\b/o;
33
34 if ($inside || $external) {
35 ++$currentGroup if $external;
36 print $GroupSeparator if defined($lastReportedGroup) && $currentGroup != $lastReportedGroup;
37 print $_;
38 $lastReportedGroup = $currentGroup;
39 } else {
40 ++$currentGroup;
41 }
42
43 if ($inside && /\bCodeContext.*?\bLeaving: /) {
44 $inside = 0;
45 ++$currentGroup;
46 }
47}
48
49exit(0);