File: trace-job.pl

package info (click to toggle)
squid 7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,440 kB
  • sloc: cpp: 184,513; ansic: 12,442; sh: 5,688; makefile: 5,247; perl: 2,560; sql: 326; python: 240; awk: 141; sed: 1
file content (55 lines) | stat: -rwxr-xr-x 1,565 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl -w
#
## Copyright (C) 1996-2025 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 async job.
#
# If job entering/exiting line format changes, the script must be updated.
# Keep the old RE around for a while because they may be handy for working
# with folks running older Squids.

use strict;
use warnings;

my $XactId = shift or die("usage: $0 <xaction id> [log file]\n");

# Squid uses asyncNNN, jobNNN, icapxNNN for the same job/transaction
# TODO: use jobNNN everywhere
$XactId =~ s/^(?:async|job|icapx)(\d+)$/(async|job|icapx)$1/ and
    warn("Replacing xaction ID with $XactId\n");

my $inside = 0;

my $entering;

while (<>) {
    $entering = $_ if !$inside && /[|:] entering\b/;
    undef $entering if /[|:] leaving\b/;

    # if (!$inside && /\bcalled\b.*\b$XactId\b/o) {
    if (!$inside && /\bstatus in\b.*\b$XactId\b/o) {
        print $entering if defined $entering;
        $inside = 1;
    }

    my $external = !$inside && /\b$XactId\b/o;

    print $_ if $inside || $external;
    print "\n" if $external;

    next unless $inside;

    # if (/\bended\b.*\b$XactId\b/o || /\bswan\s+sang\b.*\b$XactId\b/o) {
    # if (/\bstatus out\b.*\b$XactId\b/o || /\bswan\s+sang\b.*\b$XactId\b/o ||
    if (/[|:] leaving\b/) {
        print "\n";
        $inside = 0;
    }
}

exit(0);