]> git.ipfire.org Git - thirdparty/squid.git/blame - scripts/trace-job.pl
SourceFormat Enforcement
[thirdparty/squid.git] / scripts / trace-job.pl
CommitLineData
e83fd259 1#!/usr/bin/perl -w
a151895d 2#
4ac4a490 3## Copyright (C) 1996-2017 The Squid Software Foundation and contributors
a151895d
AJ
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##
e83fd259
AR
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
16use strict;
17use warnings;
18
19my $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
26my $inside = 0;
27
28my $entering;
29
30while (<>) {
4ce9bb90
AR
31 $entering = $_ if !$inside && /[|:] entering\b/;
32 undef $entering if /[|:] leaving\b/;
e83fd259
AR
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 ||
4ce9bb90 49 if (/[|:] leaving\b/) {
e83fd259
AR
50 print "\n";
51 $inside = 0;
52 }
53}
54
55exit(0);