]>
Commit | Line | Data |
---|---|---|
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 | ||
12 | use strict; | |
13 | use warnings; | |
14 | ||
15 | die("usage: $0 <CodeContext id> [log filename]\n") unless @ARGV; | |
16 | my $ContextId = shift; | |
17 | ||
18 | my $GroupSeparator = "--\n"; | |
19 | ||
20 | my $inside = 0; | |
21 | my $currentGroup = 0; | |
22 | my $lastReportedGroup = undef(); | |
23 | while (<>) { | |
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 | ||
49 | exit(0); |