Skip to content

Instantly share code, notes, and snippets.

View ordian's full-sized avatar
:octocat:
💙💛

ordian

:octocat:
💙💛
View GitHub Profile
@ordian
ordian / README.md
Last active March 21, 2024 14:44
HOWTO: heap profiling with jemallocator
  1. Make sure your rust application uses https://github.com/gnzlbg/jemallocator as the global memory allocator (when in doubt, grep jemallocator in your Cargo.lock).
  2. Install jemalloc (we'll only need jeprof), dot, ps2pdf and libunwind on your system. Enable jemallocator's profiling feature (if jemallocator is an indirect dependency, one trick to do is to add a dependency jemallocator = { version = "*", features = ["profiling"] } to your app and let cargo select the || of features for you).
  3. export _RJEM_MALLOC_CONF=prof:true,lg_prof_interval:32,lg_prof_sample:19. lg_prof_interval sets how often profile dump should be written to disk measured in allocated bytes. The value is passed as a power of two, which is 2^32 in our case, i.e. every 4 GiB of allocations of long-lived objects (see https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Heap-Profiling). lg_prof_sample:19 tells jemalloc to take a profiling sample every 2^19 = 512 KiB.
  4. Running your binary should produce a bun
@ordian
ordian / segment_tree.cpp
Created December 28, 2016 17:49
Too much templates for today...
#include <vector>
#include <functional>
#include <iostream>
using std::vector;
template<typename T = int, template <typename> class Combiner = std::plus>
class SegmentTree {
==2192== Thread 3 btree::map::test_split_off_large_random:
==2192== Invalid write of size 8
==2192== at 0x4C2F30B: memcpy@@GLIBC_2.14 (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2192== by 0x20E2D6: collections::btree::node::copy_edges::h5a2e4f41299918c8 (node.rs:1451)
==2192== by 0x20DA1E: _$LT$collections..btree..node..Handle$LT$collections..btree..node..NodeRef$LT$collections..btree..node..marker..Mut$LT$$u27$a$GT$$C$$u20$K$C$$u20$V$C$$u20$collections..btree..node..marker..LeafOrInternal$GT$$C$$u20$collections..btree..node..marker..Edge$GT$$GT$::cut_right::h133ac9fb606a05e7 (node.rs:1515)
==2192== by 0x20D2D1: _$LT$collections..BTreeMap$LT$K$C$$u20$V$GT$$GT$::split_off::h75b5a759780e3f01 (map.rs:903)
==2192== by 0x20ABAF: lib::btree::map::test_split_off_large_random::h43a45c594a8c996a (map.rs:539)
==2192== by 0x4E8A602: fn$LP$$RP$::fn_pointer_shim.12071::h6eb974d203364a46 (in /home/ordian/Downloads/sandbox/rust/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux
Debugger entered--Lisp error: (error "Required feature `srefactor' was not provided")
require(srefactor nil noerror)
(not (require (quote srefactor) nil (quote noerror)))
(if (not (require (quote srefactor) nil (quote noerror))) (ignore (message (format "Could not load %s" (quote srefactor)))))
(progn (condition-case err (progn (require (quote cc-mode)) (semantic-mode 1) (let* ((name "M-RET") (key (if (vectorp name) name (read-kbd-macro name))) (kdesc (cons (if ... name ...) (quote c-mode-map))) (binding (lookup-key (or c-mode-map global-map) key))) (add-to-list (quote personal-keybindings) (list kdesc (quote srefactor-refactor-at-point) (if (numberp binding) nil binding))) (define-key (or c-mode-map global-map) key (quote srefactor-refactor-at-point))) (let* ((name "M-RET") (key (if (vectorp name) name (read-kbd-macro name))) (kdesc (cons (if ... name ...) (quote c++-mode-map))) (binding (lookup-key (or c++-mode-map global-map) key))) (add-to-list (quote personal-keybindings) (list kdesc (quote srefa