Bug 219909 - Userland dtrace in ports / compiling with poudriere
Summary: Userland dtrace in ports / compiling with poudriere
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Ports Framework (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Matthew Seaman
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-10 16:07 UTC by Matthew Seaman
Modified: 2018-02-19 15:22 UTC (History)
1 user (show)

See Also:


Attachments
postgresql9{2,6}-server patches (2.01 KB, patch)
2017-06-19 11:00 UTC, Matthew Seaman
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Seaman freebsd_committer 2017-06-10 16:07:49 UTC
About 30-ish ports provide some sort of dtrace SDT probes, with many 
enabling those conditionally on a DTRACE option.

Compiling dtrace-enabled ports via poudriere runs into some hurdles:

  * dtrace(1) expects the dtrace kernel modules to be loaded
  * invocations of dtrace frequently examine kernel objects under /boot
  * generating probes.h out of probes.d and compiling the probes does not 
    fit very well into many build systems
  * in order for dtrace probes to work at runtime, the process needs to be
    able to access /dev/dtrace/helper 

poudriere's use of jails to compile means that the first two of these assumptions aren't necessarily true.  The need to examine kernel objects
can often be avoided by adding -xnolibs to 'gtrace -G' (generate ELF object file) and 'dtrace -h' (generate C/C++ header file)
Comment 1 Matthew Seaman freebsd_committer 2017-06-10 16:15:42 UTC
Fixing permissions.  Choosing group 141 as the next available gid from /usr/ports/GIDs, create a dtrace group and add the userids used by dtrace-able programs to it.  I shall use postgresql96 as the example:

```
# pw group add -n dtrace -g 141 -M postgres
# cat /etc/devfs.rules
[userdtrace=10]
add path dtrace/helper mode 0660 group dtrace
# sysrc devfs_system_ruleset="userdtrace"
```
Will result in ownership/permissions like so (may need a reboot):

```
# ls -la /dev/dtrace/
total 1
dr-xr-xr-x   2 root  wheel   512 Jun  3 11:42 ./
dr-xr-xr-x  13 root  wheel   512 Jun  3 11:42 ../
crw-------   1 root  wheel   0x9 Jun  3 11:42 dtmalloc
crw-------   1 root  wheel   0x4 Jun  3 11:42 dtrace
crw-------   1 root  wheel   0x7 Jun  3 11:42 fasttrap
crw-------   1 root  wheel   0x8 Jun  3 11:42 fbt
crw-rw----   1 root  dtrace  0x5 Jun  3 11:42 helper
crw-------   1 root  wheel   0x6 Jun  3 11:42 profile
```
Resulting in:

```
# dtrace -l -m postgres | head -10
   ID   PROVIDER            MODULE                          FUNCTION NAME
69078 postgresql79451          postgres                 CheckPointBuffers buffer-checkpoint-done
69079 postgresql79451          postgres                 CheckPointBuffers buffer-checkpoint-start
69080 postgresql79451          postgres                 CheckPointBuffers buffer-checkpoint-sync-start
69081 postgresql79451          postgres                       FlushBuffer buffer-flush-done
69082 postgresql79451          postgres                       FlushBuffer buffer-flush-start
69083 postgresql79451          postgres                 ReadBuffer_common buffer-read-done
69084 postgresql79451          postgres                 ReadBuffer_common buffer-read-start
69085 postgresql79451          postgres                 CheckPointBuffers buffer-sync-done
69086 postgresql79451          postgres                 CheckPointBuffers buffer-sync-start
```
Comment 2 Matthew Seaman freebsd_committer 2017-06-10 16:17:43 UTC
Fixing permissions.  Choosing group 141 as the next available gid from /usr/ports/GIDs, create a dtrace group and add the userids used by dtrace-able programs to it.  I shall use postgresql96 as the example:

```
# pw group add -n dtrace -g 141 -M postgres
# cat /etc/devfs.rules
[userdtrace=10]
add path dtrace/helper mode 0660 group dtrace
# sysrc devfs_system_ruleset="userdtrace"
```
Will result in ownership/permissions like so (may need a reboot):

```
# ls -la /dev/dtrace/
total 1
dr-xr-xr-x   2 root  wheel   512 Jun  3 11:42 ./
dr-xr-xr-x  13 root  wheel   512 Jun  3 11:42 ../
crw-------   1 root  wheel   0x9 Jun  3 11:42 dtmalloc
crw-------   1 root  wheel   0x4 Jun  3 11:42 dtrace
crw-------   1 root  wheel   0x7 Jun  3 11:42 fasttrap
crw-------   1 root  wheel   0x8 Jun  3 11:42 fbt
crw-rw----   1 root  dtrace  0x5 Jun  3 11:42 helper
crw-------   1 root  wheel   0x6 Jun  3 11:42 profile
```
Resulting in:

```
# dtrace -l -m postgres | head -10
   ID   PROVIDER            MODULE                          FUNCTION NAME
69078 postgresql79451          postgres                 CheckPointBuffers buffer-checkpoint-done
69079 postgresql79451          postgres                 CheckPointBuffers buffer-checkpoint-start
69080 postgresql79451          postgres                 CheckPointBuffers buffer-checkpoint-sync-start
69081 postgresql79451          postgres                       FlushBuffer buffer-flush-done
69082 postgresql79451          postgres                       FlushBuffer buffer-flush-start
69083 postgresql79451          postgres                 ReadBuffer_common buffer-read-done
69084 postgresql79451          postgres                 ReadBuffer_common buffer-read-start
69085 postgresql79451          postgres                 CheckPointBuffers buffer-sync-done
69086 postgresql79451          postgres                 CheckPointBuffers buffer-sync-start
```
Comment 4 Matthew Seaman freebsd_committer 2017-06-19 11:00:12 UTC
Created attachment 183624 [details]
postgresql9{2,6}-server patches

These patches allow poudriere to build postgresql+dtrace probes
for amd64 11.0 and 10.3 on an amd64 11.0 host with dtraceall kmod
loaded.

Fails when trying to build i386 binaries.
Comment 5 Matthew Seaman freebsd_committer 2017-06-19 11:16:09 UTC
Same result when building without and dtrace kernel modules loaded.
Comment 6 Jan Beich freebsd_committer 2018-02-19 15:22:56 UTC
-lelf isn't necessary after base r278934
-xnolibs isn't necessary after base r283025