blob: 8c8854a906880f5f9ed9916eb51fa78e37f08a95 [file] [log] [blame]
Willy Tarreau7de211c2012-05-25 23:53:16 +02001#!/bin/sh
2#
3# trace.awk - Fast trace symbol resolver - w@1wt.eu - 2012/05/25
4#
5# Principle: this program launches reads pointers from a trace file and if not
6# found in its cache, it passes them over a pipe to addr2line which is forked
7# in a coprocess, then stores the result in the cache.
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation; either version
12# 2 of the License, or (at your option) any later version.
13#
14# usage: $0 exec_file < trace.out
15#
16
17if [ $# -lt 1 ]; then
18 echo "Usage: ${0##*/} exec_file < trace.out"
19 echo "Example: ${0##*/} ./haproxy < trace.out"
20 echo "Example: HAPROXY_TRACE=/dev/stdout ./haproxy -f cfg | ${0##*/} ./haproxy"
21 exit 1
22fi
23
24if [ ! -s "$1" ]; then
25 echo "$1 is not a valid executable file"
26 exit 1
27fi
28
29exec awk -v prog="$1" \
30'
31BEGIN {
32 if (cmd == "")
33 cmd=ENVIRON["ADDR2LINE"];
34 if (cmd == "")
35 cmd="addr2line";
36
37 if (prog == "")
38 prog=ENVIRON["PROG"];
39
40 cmd=cmd " -f -e " prog;
41
42 for (i = 1; i < 100; i++) {
43 indents[">",i] = indents[">",i-1] "->"
44 indents[">",i-1] = indents[">",i-1] " "
45 indents["<",i] = indents["<",i-1] " "
46 indents["<",i-1] = indents["<",i-1] " "
47 }
48}
49
50function getptr(ptr)
51{
52 loc=locs[ptr];
53 name=names[ptr];
54 if (loc == "" || name == "") {
55 print ptr |& cmd;
56 cmd |& getline name;
57 cmd |& getline loc;
58 names[ptr]=name
59 locs[ptr]=loc
60 }
61}
62
63{
64 # input format: <timestamp> <level> <caller> <dir> <callee>
65 getptr($3); caller_loc=loc; caller_name=name
66 getptr($5); callee_loc=loc; callee_name=name
67 printf "%s %s %s %s %s [%s:%s] %s [%s:%s]\n",
68 $1, indents[$4,$2], caller_name, $4, callee_name, caller_loc, $3, $4, callee_loc, $5
69}
70'