Skip to content

Commit bf543df

Browse files
author
Harald Weppner
committed
Enable profiling / leak detection in FreeBSD
* Assumes procfs is mounted at /proc, cf. <http://www.freebsd.org/doc/en/articles/linux-users/procfs.html>
1 parent 9e20df1 commit bf543df

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

bin/pprof

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,8 +4197,12 @@ sub FindLibrary {
41974197
# For libc libraries, the copy in /usr/lib/debug contains debugging symbols
41984198
sub DebuggingLibrary {
41994199
my $file = shift;
4200-
if ($file =~ m|^/| && -f "/usr/lib/debug$file") {
4201-
return "/usr/lib/debug$file";
4200+
if ($file =~ m|^/|) {
4201+
if (-f "/usr/lib/debug$file") {
4202+
return "/usr/lib/debug$file";
4203+
} elsif (-f "/usr/lib/debug$file.debug") {
4204+
return "/usr/lib/debug$file.debug";
4205+
}
42024206
}
42034207
return undef;
42044208
}
@@ -4360,6 +4364,19 @@ sub ParseLibraries {
43604364
$finish = HexExtend($2);
43614365
$offset = $zero_offset;
43624366
$lib = $3;
4367+
}
4368+
# FreeBSD 10.0 virtual memory map /proc/curproc/map as defined in
4369+
# function procfs_doprocmap (sys/fs/procfs/procfs_map.c)
4370+
#
4371+
# Example:
4372+
# 0x800600000 0x80061a000 26 0 0xfffff800035a0000 r-x 75 33 0x1004 COW NC vnode /libexec/ld-elf.s
4373+
# o.1 NCH -1
4374+
elsif ($l =~ /^(0x$h)\s(0x$h)\s\d+\s\d+\s0x$h\sr-x\s\d+\s\d+\s0x\d+\s(COW|NCO)\s(NC|NNC)\svnode\s(\S+\.so(\.\d+)*)/) {
4375+
$start = HexExtend($1);
4376+
$finish = HexExtend($2);
4377+
$offset = $zero_offset;
4378+
$lib = FindLibrary($5);
4379+
43634380
} else {
43644381
next;
43654382
}
@@ -4382,6 +4399,7 @@ sub ParseLibraries {
43824399
}
43834400
}
43844401

4402+
if($main::opt_debug) { printf STDERR "$start:$finish ($offset) $lib\n"; }
43854403
push(@{$result}, [$lib, $start, $finish, $offset]);
43864404
}
43874405

src/prof.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#include <unwind.h>
1212
#endif
1313

14+
#ifdef __FreeBSD__
15+
#define PROCESS_VMEM_MAP "/proc/curproc/map"
16+
#else
17+
#define PROCESS_VMEM_MAP "/proc/%d/maps"
18+
#endif
19+
1420
/******************************************************************************/
1521
/* Data. */
1622

@@ -936,7 +942,7 @@ prof_dump_maps(bool propagate_err)
936942

937943
cassert(config_prof);
938944

939-
malloc_snprintf(filename, sizeof(filename), "/proc/%d/maps",
945+
malloc_snprintf(filename, sizeof(filename), PROCESS_VMEM_MAP,
940946
(int)getpid());
941947
mfd = open(filename, O_RDONLY);
942948
if (mfd != -1) {

0 commit comments

Comments
 (0)