]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/trace-job.pl
SourceFormat Enforcement
[thirdparty/squid.git] / scripts / trace-job.pl
1 #!/usr/bin/perl -w
2 #
3 ## Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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 async job.
11 #
12 # If job entering/exiting line format changes, the script must be updated.
13 # Keep the old RE around for a while because they may be handy for working
14 # with folks running older Squids.
15
16 use strict;
17 use warnings;
18
19 my $XactId = shift or die("usage: $0 <xaction id> [log file]\n");
20
21 # Squid uses asyncNNN, jobNNN, icapxNNN for the same job/transaction
22 # TODO: use jobNNN everywhere
23 $XactId =~ s/^(?:async|job|icapx)(\d+)$/(async|job|icapx)$1/ and
24 warn("Replacing xaction ID with $XactId\n");
25
26 my $inside = 0;
27
28 my $entering;
29
30 while (<>) {
31 $entering = $_ if !$inside && /[|:] entering\b/;
32 undef $entering if /[|:] leaving\b/;
33
34 # if (!$inside && /\bcalled\b.*\b$XactId\b/o) {
35 if (!$inside && /\bstatus in\b.*\b$XactId\b/o) {
36 print $entering if defined $entering;
37 $inside = 1;
38 }
39
40 my $external = !$inside && /\b$XactId\b/o;
41
42 print $_ if $inside || $external;
43 print "\n" if $external;
44
45 next unless $inside;
46
47 # if (/\bended\b.*\b$XactId\b/o || /\bswan\s+sang\b.*\b$XactId\b/o) {
48 # if (/\bstatus out\b.*\b$XactId\b/o || /\bswan\s+sang\b.*\b$XactId\b/o ||
49 if (/[|:] leaving\b/) {
50 print "\n";
51 $inside = 0;
52 }
53 }
54
55 exit(0);