-
Notifications
You must be signed in to change notification settings - Fork 354
/
ngx-backtrace
executable file
·55 lines (39 loc) · 974 Bytes
/
ngx-backtrace
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
#!/usr/bin/env perl
# Copyright (C) Yichun Zhang (agentzh)
use 5.006001;
use strict;
use warnings;
use Getopt::Std qw( getopts );
my %opts;
getopts("hp:", \%opts)
or die usage();
if ($opts{h}) {
print usage();
exit;
}
my $pid = $opts{p}
or die "No nginx master process pid specified by the -p option\n";
if ($pid !~ /^\d+$/) {
die "Bad -p option value \"$pid\": not look like a pid\n";
}
if ($^O ne 'linux') {
die "Only linux is supported but I am on $^O.\n";
}
my $exec_file = "/proc/$pid/exe";
if (!-f $exec_file) {
die "Nginx process $pid is not running or ",
"you do not have enough permissions.\n";
}
my $nginx_path = readlink $exec_file;
exec 'addr2line', '-e', $exec_file, '-f', @ARGV;
sub usage {
return <<'_EOC_';
Usage:
ngx-backtrace [optoins]
Options:
-h Print this usage.
-p <pid> Specify the nginx (worker) process pid.
Examples:
ngx-backtrace -p 12345
_EOC_
}