Skip to content

Instantly share code, notes, and snippets.

Using Erlang tracer with rabbitmq

Erlang has a powerful trace utility, similar to strace. Instead of tracing system calls, you can trace any piece of Erlang code. RabbitMQ is written in Erlang, so we can use Erlang trace to see what its doing. The extra load may flood the system, so be very careful running this in prod.

In this example we will see how Rabbit is invoking mnesia. Mnesia is the database rabbit is using.

Steps

% example code how to get dbg to run
% you can even run this remotely with "erl -remsh ..."
dbg:tracer().
dbg:p(all, c).
dbg:tpl(mnesia, x). % x means "everything", its probably supposed to represent a *
mnesia:info().
% example code how to get dbg to run
% you can even run this remotely with "erl -remsh ..."
dbg:tracer().
dbg:p(all, c).
dbg:tpl(mnesia, x). % x means "everything", its probably supposed to represent a *
mnesia:info().
@benhsu
benhsu / multiyank.el
Created August 24, 2013 18:12
Change (yank) to yank the same piece of text repeatedly based on a prefix argument. useful for repetitive tasks
(defun multiyank (times) (interactive "p") (loop for i from 1 to times do (yank)))
(global-set-key (kbd "C-y") 'multiyank)
@benhsu
benhsu / gist:4591417
Created January 22, 2013 02:03
closes the s-expression at point
(defun close-sexp ()
;; closes the s-expression at point
;; by computing how many open parens and close parens
;; there are and inserting the appropriate number
;; bug: doesnt handle backquoted parens like \( \) properly
(interactive)
(let ((pt (point))
(numopen 0)
(numclose 0))
(save-excursion
@benhsu
benhsu / collect-ips.el
Created January 17, 2013 04:33
code to grab all the strings matching a given regex and put them in a buffer, along with sample use for IPs
(defun collect-regexp-results (regex)
;;; collects all the matches of regex in a buffer called *collect-result*
;;; then switches to that buffer
;;; TODO refactor this to take the region as a parameter
(interactive "Mregex to search for: ")
(let ((curmin (region-or-buffer-beginning))
(curmax (region-or-buffer-end)))
(save-excursion
(goto-char curmin)
;; (goto-char (region-or-buffer-beginning))
(defun use-theme (theme &optional no-confirm no-enable)
(interactive
(list
(intern (completing-read "Load custom theme: "
(mapcar 'symbol-name
(custom-available-themes))))
nil nil))
(progn
(dolist (curtheme (custom-available-themes))
(disable-theme curtheme))
@benhsu
benhsu / tree.md
Created September 26, 2012 14:50 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@benhsu
benhsu / region-or-line.el
Created February 18, 2012 14:40
emacs code to operate on a region or line
;; stab at generalizing this
(defun line-or-region-wrapper (func)
(interactive)
(if (region-active-p)
(funcall func (region-beginning) (region-end))
(funcall func (line-beginning-position) (line-end-position))))