vendredi 31 décembre 2021

See what takes time in kernel compilation

Makefile projects can be profiled and debugged with the remake project. You need a recent version of remake that supports --profile=json (see --help).

This works with parallel builds as well (I've use -j8 here but use whatever you have).

  • "name" is the makefile target
  • "len" is the duration in seconds


$ cd linux-git
$ mkdir -p json && remake --profile=json --profile-directory=$PWD/json -j8
$ cd json
 
# Look at items sorted by total time (time taken by all dependencies + the recipe length)
$ jq -s '[.[] |.targets[]|select(.recipe!=null)|{ name: .name, len: (.end-.start) }]|sort_by(-.len)' *.json
[
{
"name": "bzImage",
"len": 77.26787257194519
},
{
"name": "vmlinux",
"len": 76.33200693130493
},
{
"name": "arch/x86/kernel/vmlinux.lds",
"len": 75.16884279251099
},
{
"name": "drivers",
"len": 75.013343334198
},
{
"name": "arch/x86/lib/lib.a",
"len": 75.01327657699585
},
....


# Or look at item sorted by recipe time only (without the dependencies)
$ jq -s '[.[] |.targets[]|select(.recipe!=null)|{ name: .name, len: (.end-.recipe) }]|sort_by(-.len)' *json
[
{
"name": "drivers",
"len": 47.737035512924194
},
{
"name": "fs",
"len": 45.02375769615173
},
{
"name": "net",
"len": 40.28609848022461
},
{
"name": "net/ipv4",
"len": 31.197179794311523
},
...



mercredi 9 octobre 2019

AdressSanitizer link error and autoconf configure script

If you get linking errors like the following when trying to use AddressSanitizer in an autoconf project:
spnego.c:(.text+0x3c): undefined reference to `__asan_option_detect_stack_use_after_return'
/bin/ld: spnego.c:(.text+0x49): undefined reference to `__asan_stack_malloc_1'
/bin/ld: spnego.c:(.text+0xfd): undefined reference to `__asan_report_load16'
/bin/ld: spnego.c:(.text+0x180): undefined reference to `__asan_report_load8'
/bin/ld: spnego.c:(.text+0x1ad): undefined reference to `__asan_report_load8'
/bin/ld: spnego.c:(.text+0x1ff): undefined reference to `__asan_report_load8'
/bin/ld: spnego.c:(.text+0x22e): undefined reference to `__asan_report_load8'


It's because the configure guesses something wrong. You can work around it by providing the answer via an env var like so:

CFLAGS='-fsanitize=address' \
LDFLAGS='-fsanitize=address' \
ac_cv_func_malloc_0_nonnull=yes \
./configure

mercredi 2 mai 2018

notmuch mark as spam

Adds a keybinding that applies/removes tags to the currently viewed email or --when looking at search results-- the thread under point.
(defun mark-spam ()
  (interactive)
  (let ((tlist '("+spam" "-unread" "-inbox" "-new")))
    (if (eq major-mode 'notmuch-show-mode)
 (progn
   (let ((id (notmuch-show-get-message-id)))
     (notmuch-tag id tlist)
     (notmuch-show-next-thread)))
      (notmuch-search-tag tlist)
      (notmuch-search-next-thread))))

(define-key 'notmuch-search-mode-map (kbd "S") 'mark-spam)
(define-key 'notmuch-show-mode-map (kbd "S") 'mark-spam)

vendredi 17 février 2017

_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build

_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build


If you are pulling your hair and wondering why your kernel does not have a /sys/kernel/debug/dynamic_debug directory despite having CONFIG_DYNAMIC_DEBUG enabled and debugfs mounted, the issue could be that you built the kernel using GOLD linker. You can simply switch through the LD Makefile variable (make LD=ld.bfd)

lundi 16 janvier 2017

Extracting and applying a clean git patchset from an email thread with notmuch

I just wrote a quick python script to filter the actual patches from a email thread send with git send-email (those "[PATCH 1/15] xyz" threads). The script assumes you use notmuch. Give it a search expression that returns a list of messages that includes all the patches like the thread-id (C-u c i while looking at the thread in emacs).

You can get it on github. There is a small elisp snippet in the README to run the script and apply the patchset from emacs.

vendredi 13 janvier 2017

Copy current buffer absolute file path to the OS clipboard

(defun copy-full-path ()
  (interactive)
  (let ((path (buffer-file-name)))
    (when path
      (setq path (expand-file-name path))
      (funcall interprogram-cut-function path)
      (message "copied %s in clipboard" path))))

Quick-and-dirty email template for notmuch

(defun prepare-report ()
  (interactive)
  (notmuch-mua-new-mail)
  (insert "foo@example.com")
  (search-forward "Subject: ")
  (insert "work report week " (format-time-string "%W"))
  (search-forward "\n\n")
  (backward-char)
  (insert "my super email content\n"))