File: trace.awk

package info (click to toggle)
haproxy 1.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,364 kB
  • ctags: 8,494
  • sloc: ansic: 92,976; xml: 1,754; sh: 1,227; python: 1,005; makefile: 831; perl: 550
file content (70 lines) | stat: -rwxr-xr-x 1,785 bytes parent folder | download | duplicates (7)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
#
# trace.awk - Fast trace symbol resolver - w@1wt.eu - 2012/05/25
#
# Principle: this program launches reads pointers from a trace file and if not
# found in its cache, it passes them over a pipe to addr2line which is forked
# in a coprocess, then stores the result in the cache.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# usage: $0 exec_file < trace.out
#

if [ $# -lt 1 ]; then
  echo "Usage:   ${0##*/} exec_file < trace.out"
  echo "Example: ${0##*/} ./haproxy < trace.out"
  echo "Example: HAPROXY_TRACE=/dev/stdout ./haproxy -f cfg | ${0##*/} ./haproxy"
  exit 1
fi

if [ ! -s "$1" ]; then
  echo "$1 is not a valid executable file"
  exit 1
fi

exec awk -v prog="$1" \
'
BEGIN {
  if (cmd == "")
    cmd=ENVIRON["ADDR2LINE"];
  if (cmd == "")
    cmd="addr2line";

  if (prog == "")
    prog=ENVIRON["PROG"];

  cmd=cmd " -f -e " prog;

  for (i = 1; i < 100; i++) {
    indents[">",i] = indents[">",i-1] "->"
    indents[">",i-1] = indents[">",i-1] " "
    indents["<",i] = indents["<",i-1] "  "
    indents["<",i-1] = indents["<",i-1] " "
  }
}

function getptr(ptr)
{
  loc=locs[ptr];
  name=names[ptr];
  if (loc == "" || name == "") {
    print ptr |& cmd;
    cmd |& getline name;
    cmd |& getline loc;
    names[ptr]=name
    locs[ptr]=loc
  }
}

{
  # input format: <timestamp> <level> <caller> <dir> <callee>
  getptr($3); caller_loc=loc; caller_name=name
  getptr($5); callee_loc=loc; callee_name=name
  printf "%s %s  %s %s %s [%s:%s] %s [%s:%s]\n",
    $1, indents[$4,$2], caller_name, $4, callee_name, caller_loc, $3, $4, callee_loc, $5
}
'