User:Vazhnov/Dirty hacks

Maybe it will help to anybody who wants to do some digging.

Add GNU time to emerge
I want to see "Maximum resident set size" for ebuild compile, to get some memory usage info for problem User:Vazhnov/Knowledge Base:emerge out of memory. I use "/usr/bin/time -v" (GNU time) for this.

How compile process looks: $ ps -eF --forest … root    30385 25074 27 37937 144860  0 19:39 pts/4    00:00:12  |           \_ /usr/bin/python3.6 -b /usr/lib/python-exec/python3.6/emerge -n gnome-extra/gnome-calculator root     1776 30385  0  3928  9696   1 19:40 pts/4    00:00:00  |               \_ /usr/bin/python3.6m /usr/lib/portage/python3.6/pid-ns-init 1777 root     1777  1776  0  3928  9784   4 19:40 pts/6    00:00:00  |                   \_ /usr/bin/python3.6m /usr/lib/portage/python3.6/pid-ns-init 250 250 250 18 0,1,2 /usr/bi portage  1780  1777  0   593  1692   5 19:40 pts/6    00:00:00  |                       \_ [x11-libs/gtksourceview-4.2.0] sandbox /usr/lib/portage/python3.6/ebuild.sh compile portage  1781  1780  0  3217  7612   3 19:40 pts/6    00:00:00  |                           \_ /bin/bash /usr/lib/portage/python3.6/ebuild.sh compile portage  1803  1781  0  3219  6728   2 19:40 pts/6    00:00:00  |                               \_ /bin/bash /usr/lib/portage/python3.6/ebuild.sh compile portage  1808  1803  0  2395  4112   0 19:40 pts/6    00:00:00  |                                   \_ /bin/bash /usr/lib/portage/python3.6/ebuild-helpers/emake portage  1810  1808  0  1972  2684   1 19:40 pts/6    00:00:00  |                                       \_ make -j6 portage  1813  1810  0  1970  2724   4 19:40 pts/6    00:00:00  |                                           \_ make all-recursive

Iteration one: /usr/bin/ebuild
First I tried to replace which is symlink to.

I can't replace original /usr/lib/python-exec/python-exec2 and call it from bash wrapper because of error: /usr/lib/python-exec/python-exec2: python-exec2 is a wrapper, it must not be run directly.

It needs to be pointed by symlink, but not by bash script wrapper.

I did it successfully by:

But then I realized that not uses.

Fail!

uses some python code to run :

Iteration two: /usr/lib/portage/python3.6/ebuild.sh
Save original file:

Create file:

I tried to save information I need to, but unfortunately it is sandboxed (I had to add rules into ):

* ACCESS DENIED: open_wr:      /var/log/emerge-time.log /usr/lib/portage/python3.6/ebuild.sh: line 8: /var/log/emerge-time.log: Permission denied * ACCESS DENIED: fopen_wr:     /var/log/emerge-time.log /usr/bin/time: /var/log/emerge-time.log: Permission denied * ACCESS DENIED: open_wr:      /var/log/emerge-time.log /usr/lib/portage/python3.6/ebuild.sh: line 10: /var/log/emerge-time.log: Permission denied * --- ACCESS VIOLATION SUMMARY --- * LOG FILE: "/var/tmp/portage/gnome-extra/gnome-calculator-3.32.2/temp/sandbox.log"

So I can write into.

Then I found PORTAGE_LOGDIR allows to save build logs, with all STDOUT and STDERR output of.

Result
Final output example : >>> Compiling source in /var/tmp/portage/gnome-extra/gnome-calculator-3.32.2/work/gnome-calculator-3.32.2 ... ninja -v -j6 -l0 -C /var/tmp/portage/gnome-extra/gnome-calculator-3.32.2/work/gnome-calculator-3.32.2-build … >>> Source compiled. Command being timed: "/usr/lib/portage/python3.6/ebuild.sh.ORIG compile" User time (seconds): 29.38 System time (seconds): 2.63 Percent of CPU this job got: 403% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:07.93 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set size (kbytes): 145368 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 0 Minor (reclaiming a frame) page faults: 735962 Voluntary context switches: 2626 Involuntary context switches: 9964 Swaps: 0 File system inputs: 0 File system outputs: 20312 Socket messages sent: 0 Socket messages received: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0