• Stars
    star
    226
  • Rank 176,514 (Top 4 %)
  • Language
    C++
  • License
    zlib License
  • Created over 11 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

:squirrel: Tracey is a lightweight and simple C++ memory leak finder with no dependencies.

tracey :squirrel:

  • Tracey is a C++ static library that reports memory leaks and provides precise stacktraces with no false positives.
  • Tracey is simple. Just link it.
  • Tracey is easy to integrate. No source modification is required.
  • Tracey is clean. Macroless and callstack based. No new/delete macro hacks.
  • Tracey is lazy. Should work out of the box. Plenty configuration options are provided anyways.
  • Tracey is tiny. One header and one source file.
  • Tracey is handy. Generates HTML logs that can be collapsed per branch in Sublime Text 2 and related editors.
  • Tracey is cross-platform. Builds on Windows/Linux/MacosX. Compiles on g++/clang/msvc.
  • Tracey is stand-alone. OS dependencies only. No third party dependencies.
  • Tracey is zlib/libpng licensed.

cons

  • No hooks for malloc()/free(). Tracey supports new/delete C++ memory operators only (atm).
  • Slower runtime speed than regular builds (but not that much). There is room for improvement though.

sample

// tracey is callstack based. no dirty new/delete macro tricks.
// tracey is a static library. requires no source modification. just link it.

static int *static_cpp_leak = new int;

int main() {
    new int [400];
}

special notes

  • g++ users: both -std=c++0x and -lpthread may be required when compiling tracey.cpp

Possible outputs (msvc/g++/clang)

C:\tracey> rem LINUX: g++ sample.cc tracey.cpp -g -lpthread -std=c++0x
C:\tracey> rem APPLE: clang++ sample.cc tracey.cpp -g -o sample -std=c++11 -stdlib=libc++
C:\tracey> rem WINDOWS following
C:\tracey> cl sample.cc tracey.cpp /Zi
C:\tracey> sample
<tracey/tracey.cpp> says: tracey-0.22.c ready
<tracey/tracey.cpp> says: using realloc (f:\dd\vctools\crt\crtw32\heap\realloc.c, line 62) as realloc
<tracey/tracey.cpp> says: using memset (f:\dd\vctools\crt\crtw32\string\i386\memset.asm, line 61) as memset
<tracey/tracey.cpp> says: using printf (f:\dd\vctools\crt\crtw32\stdio\printf.c, line 49) as printf
<tracey/tracey.cpp> says: using FatalExit as exit
<tracey/tracey.cpp> says: using fopen (f:\dd\vctools\crt\crtw32\stdio\fopen.c, line 124) as fopen
<tracey/tracey.cpp> says: using fclose (f:\dd\vctools\crt\crtw32\stdio\fclose.c, line 43) as fclose
<tracey/tracey.cpp> says: using fprintf (f:\dd\vctools\crt\crtw32\stdio\fprintf.c, line 49) as fprintf
<tracey/tracey.cpp> says: with C++ exceptions=enabled
<tracey/tracey.cpp> says: with kTraceyBudgetOverhead=101.000000%
<tracey/tracey.cpp> says: with kTraceyMaxStacktraces=128 range[0..0]
<tracey/tracey.cpp> says: with kTraceyReportWildPointers=no
<tracey/tracey.cpp> says: with kTraceyDefineMemoryOperators=yes
<tracey/tracey.cpp> says: with kTraceyMemsetAllocations=yes
<tracey/tracey.cpp> says: with kTraceyStacktraceSkipBegin=0
<tracey/tracey.cpp> says: with kTraceyStacktraceSkipEnd=0
<tracey/tracey.cpp> says: with kTraceyReportOnExit=yes
<tracey/tracey.cpp> says: with kTraceyWebserverPort=2001
<tracey/tracey.cpp> says: with kTraceyHookLegacyCRT=0
<tracey/tracey.cpp> says: with kTraceyEnabled=1
<tracey/tracey.cpp> says: summary: highest peak: 1600 bytes total, 1600 bytes greatest peak // -8 allocs in use: 1472 bytes + overhead: 3 GB = total: 948 bytes
<tracey/tracey.cpp> says: creating report: C:\Users\MARIO~1.ROD\AppData\Local\Temp\san4xxx-tracey.html
<tracey/tracey.cpp> says: filtering leaks...
<tracey/tracey.cpp> says: found 2 leaks wasting 1604 bytes
<tracey/tracey.cpp> says: creating trees of frames...
<tracey/tracey.cpp> says: resolving 12 unique frames...
<tracey/tracey.cpp> says: converting tree of frames into tree of symbols...
<tracey/tracey.cpp> says: flattering tree of symbols...
C:\tracey>

and then in C:\Users\MARIO~1.ROD\AppData\Local\Temp\san4xxx-tracey.html log file...

<tracey/tracey.cpp> says: generated with tracey-0.22.c (https://github.com/r-lyeh/tracey)
<tracey/tracey.cpp> says: best viewed on foldable text editor (like SublimeText2) with tabs=2sp and no word-wrap
<tracey/tracey.cpp> says: error, 2 leaks found; 1604 bytes wasted ('lame' score)
<tracey/tracey.cpp> says: summary: highest peak: 1600 bytes total, 1600 bytes greatest peak // -8 allocs in use: 1472 bytes + overhead: 3 GB = total: 948 bytes
<tracey/tracey.cpp> says: report filename: C:\Users\MARIO~1.ROD\AppData\Local\Temp\san4xxx-tracey.html
[2] (100% .. 1604 bytes) begin
  [1] (100% .. 1604 bytes) RtlInitializeExceptionChain
    [1] (100% .. 1604 bytes) RtlInitializeExceptionChain
      [1] (100% .. 1604 bytes) BaseThreadInitThunk
        [2] (099% .. 1600 bytes) __tmainCRTStartup (f:\dd\vctools\crt\crtw32\startup\crt0.c, line 255)
          [1] (099% .. 1600 bytes) main (C:\tracey\sample.cc, line 7)
            [1] (099% .. 1600 bytes) operator new (C:\tracey\tracey.cpp, line 3319)
              [1] (099% .. 1600 bytes) tracey::watch (C:\tracey\tracey.cpp, line 3162)
                [1] (099% .. 1600 bytes) tracey::`anonymous namespace'::tracer (C:\tracey\tracey.cpp, line 3139)
        [2] (000% .. 4 bytes) __tmainCRTStartup (f:\dd\vctools\crt\crtw32\startup\crt0.c, line 237)
          [1] (000% .. 4 bytes) _cinit (f:\dd\vctools\crt\crtw32\startup\crt0dat.c, line 321)
            [1] (000% .. 4 bytes) _initterm (f:\dd\vctools\crt\crtw32\startup\crt0dat.c, line 954)
              [1] (000% .. 4 bytes) `dynamic initializer for 'static_cpp_leak'' (C:\tracey\sample.cc, line 4)
                [1] (000% .. 4 bytes) operator new (C:\tracey\tracey.cpp, line 3319)
                  [1] (000% .. 4 bytes) tracey::watch (C:\tracey\tracey.cpp, line 3162)
                    [1] (000% .. 4 bytes) tracey::`anonymous namespace'::tracer (C:\tracey\tracey.cpp, line 3139)
[2] (100% .. 1604 bytes) end
  [1] (100% .. 1604 bytes) tracey::`anonymous namespace'::tracer (C:\tracey\tracey.cpp, line 3139)
    [1] (100% .. 1604 bytes) tracey::watch (C:\tracey\tracey.cpp, line 3162)
      [1] (100% .. 1604 bytes) operator new (C:\tracey\tracey.cpp, line 3319)
        [2] (099% .. 1600 bytes) main (C:\tracey\sample.cc, line 7)
          [1] (099% .. 1600 bytes) __tmainCRTStartup (f:\dd\vctools\crt\crtw32\startup\crt0.c, line 255)
            [1] (099% .. 1600 bytes) BaseThreadInitThunk
              [1] (099% .. 1600 bytes) RtlInitializeExceptionChain
                [1] (099% .. 1600 bytes) RtlInitializeExceptionChain
        [2] (000% .. 4 bytes) `dynamic initializer for 'static_cpp_leak'' (C:\tracey\sample.cc, line 4)
          [1] (000% .. 4 bytes) _initterm (f:\dd\vctools\crt\crtw32\startup\crt0dat.c, line 954)
            [1] (000% .. 4 bytes) _cinit (f:\dd\vctools\crt\crtw32\startup\crt0dat.c, line 321)
              [1] (000% .. 4 bytes) __tmainCRTStartup (f:\dd\vctools\crt\crtw32\startup\crt0.c, line 237)
                [1] (000% .. 4 bytes) BaseThreadInitThunk
                  [1] (000% .. 4 bytes) RtlInitializeExceptionChain
                    [1] (000% .. 4 bytes) RtlInitializeExceptionChain

API implementation (optional)

Backend implementation in tracey.hpp. Tweak these if needed.

/*/ Default report logger
/*/ #define kTraceyPrintf           std::printf
/*/ Default memory allocator
/*/ #define kTraceyRealloc          std::realloc
/*/ Default memory setter
/*/ #define kTraceyMemset           std::memset
/*/ Default filling character
/*/ #define kTraceyMemsetChar       '\0'
/*/ All fatal exits converge to this symbol
/*/ #define kTraceyDie              $windows(FatalExit) $welse( $cpp11(std::quick_exit) $cpp03(std::exit) )
/*/ All out-of-memory runtime asserts converge to this symbol.
/*/ #define kTraceyAssert           assert
/*/ All out-of-memory runtime exceptions converge to this sysmbol.
/*/ #define kTraceyBadAlloc         std::bad_alloc
/*/ Default wrapper to std::FILE
/*/ #define kTraceyfFile            std::FILE
/*/ Default wrapper to fopen()
/*/ #define kTraceyfOpen            std::fopen
/*/ Default wrapper to fclose()
/*/ #define kTraceyfClose           std::fclose
/*/ Default wrapper to fprintf()
/*/ #define kTraceyfPrintf          std::fprintf

API configuration (optional)

Backend options in tracey.hpp. Tweak these until happy.

/*/ Tracey uses this value to simulate increased memory simulations (should be >= 1.0)
/*/ #define kTraceyBudgetOverhead          1.0
/*/ Tracey retrieves up to 128 traces by default. The longer the slower, though.
/*/ #define kTraceyMaxStacktraces          128
/*/ Tracey head position on every stacktrace. It does not skip backtraces by default.
/*/ #define kTraceyStacktraceSkipBegin     0 // $windows(4) $welse(0)
/*/ Tracey tail position on every stacktrace. It does not skip backtraces by default.
/*/ #define kTraceyStacktraceSkipEnd       0 // $windows(4) $welse(0)
/*/ Tracey linefeed character when logging.
/*/ #define kTraceyCharLinefeed            "\n"
/*/ Tracey tab character when logging.
/*/ #define kTraceyCharTab                 "\t"
/*/ When enabled, Tracey warns about deallocations on pointers that have been not allocated by Tracey (wild pointers)
/*/ #define kTraceyReportWildPointers      0
/*/ When enabled, Tracey warns about double allocations on same pointer
/*/ #define kTraceyReportDoubleAllocations 0
/*/ When enabled, Tracey memsets memory on mallocs()
/*/ #define kTraceyMemsetAllocations       1
/*/ When enabled, Tracey shows a report automatically on application exit.
/*/ #define kTraceyReportOnExit            1
/*/ When enabled, Tracey is enabled
/*/ #define kTraceyEnabled                 1
/*/ When >0, Tracey web service is enabled. Note: requires C++11
/*/ #define kTraceyWebserverPort           2001
/*/ When enabled, Tracey will hook up C CRT as well (@todo)
/*/ #define kTraceyHookLegacyCRT           0
/*/ When >0, Tracey will ignore branches of leaks that are smaller than given percentage. It does not ignore branches by default.
/*/ #define kTraceyTruncateBranchesSmallerThan 0.0 // 5.0%
/*/ When enabled, Tracey implements all new/delete operators; else user must use runtime API manually (see below).
/*/ #define kTraceyDefineMemoryOperators       1

API C++ runtime (optional)

  • tracey::watch(ptr,size) tells Tracey to watch a memory address.
  • tracey::forget(ptr) tells Tracey to forget about a memory address.
  • tracey::clear() tells Tracey to forget whole execution.
  • tracey::report() creates a report and returns its physical address.
  • tracey::view(log) views given report log.
  • tracey::badalloc() throws a bad_alloc() exception, if possible.
  • tracey::fail(msg) shows given error then fail.
  • tracey::nop() does allocate/watch/forget/free some memory.
  • tracey::summary() returns a brief summary.
  • tracey::version() returns current version.
  • tracey::url() returns project repository.
  • tracey::settings() returns current settings.
  • tracey::scope() raii scope monitoring.

API C runtime (optional)

  • tracey_watch(ptr,size) tells Tracey to watch a memory address.
  • tracey_forget(ptr) tells Tracey to forget about a memory address.
  • tracey_clear() tells Tracey to forget whole execution.
  • tracey_report() creates a report and returns its physical address.
  • tracey_view(log) views given report log.
  • tracey_badalloc() throws a bad_alloc() exception, if possible.
  • tracey_fail(msg) shows given error then fail.
  • tracey_nop() does allocate/watch/forget/free some memory.
  • tracey_summary() returns a brief summary.
  • tracey_version() returns current version.
  • tracey_url() returns project repository.
  • tracey_settings() returns current settings.
  • tracey_view_report() make report & view.

API C runtime (optional)

  • @todoc

Changelog

  • v1.0.0 (2015/11/04)
    • Initial semantic versioning adherence
    • Fix 64-bit
  • 0.24-c
    • Upgraded submodules
  • 0.23-c
    • Webserver support (w/ C++03)
  • 0.22-c
    • Source code clean up.
    • Faster implementation.
    • Better (more) documentation.
    • Safer behavior on any /MT /MTd /MD /MDd combination (MSVC).
    • Deprecated tinythread mutexes in favor of boost (only in C++03).
    • Simplified mutex locking. Requires compiler with thread-local storage support.
    • Amalgamated distribution made of code from different sublibraries: heal, oak, route66
    • Bugfixed wrong branch size on reports.
  • 0.21-b
    • Tracey requires less memory now.
    • Memory usage shown on tree reports now.
  • 0.20-b
    • Tracey behaves better in many aspects now.
    • Support for /MT and /MTd on Windows.
    • iOS support.
    • A more compatible symbol demangling on MacOs/iOS.
    • Faster report generation.
    • New smaller hierarchical tree reports that provide also more information than before.
    • Bugfixed symbol retrieval when other memory managers are present.
    • Improved symbol retrieval on windows.
    • Experimental webserver (to be improved).
    • New compiler tweaks.
    • Many new options and settings (unwinding stack size, truncation, etc...)
    • Bugfixed recursive deadlocks on tinythread.
    • A bunch of other minor bugfixes and tweaks.
    • Tracey throws exceptions only if they are enabled on your compiler now.
    • API upgraded.
    • Many things I have forgotten.

More Repositories

1

bundle

📦 Bundle, an embeddable compression library: DEFLATE, LZMA, LZIP, BZIP2, ZPAQ, LZ4, ZSTD, BROTLI, BSC, CSC, BCM, MCM, ZMOLLY, ZLING, TANGELO, SHRINKER, CRUSH, LZJB and SHOCO streams in a ZIP file (C++03)(C++11)
C++
623
star
2

scriptorium

📜 Game Scripting Languages benchmarked
C
486
star
3

statvs

Hopefully updated status of all my github repositories
344
star
4

AVA

A tiny unlicensed 3D game engine in C; with C++ and Lua interfaces. Written in 32 random ̷d̷a̷y̷s̷ m̷o̷n̷t̷h̷s̷ years.
C
336
star
5

getopt

Simple command-line options handler (C++11)
C++
327
star
6

sole

🍩 Sole is a lightweight C++11 library to generate universally unique identificators (UUID), both v1 and v4.
C++
296
star
7

fsm

📑 Simple and lightweight Hierarchical/Finite-State Machine (H-FSM) class (C++11)
C++
229
star
8

ltalloc

LightweighT Almost Lock-Less Oriented for C++ programs memory allocator
C++
164
star
9

spot

🌀 Compact and embeddable RGBA/HSLA library that supports WEBP, JPG, progressive JPG, PNG, TGA, DDS DXT1/2/3/4/5, BMP, PSD, GIF, PVR2/3 (ETC1/PVRTC), KTX (ETC1/PVRTC), PKM (ETC1), HDR, PIC, PNM (PPM/PGM), CRN, PUG, FLIF, CCZ, EXR and vectorial SVG files (C++11)
C
134
star
10

kult

🔮 Lightweight entity/component/system library (C++11)
C++
127
star
11

dessert

🍰 Lightweight unit-testing framework (C++11).
C++
87
star
12

img2sky

🌒 A vertex-color mesh builder tool for skyboxes and static geometry, as seen in HomeWorld 2 .HOD files
C
76
star
13

dollar

💰 A portable CPU profiler with ASCII,CSV,TSV,Markdown,chrome://tracing support (C++11)
C++
64
star
14

base

Base91 / Base85 / Base64 de/encoders (C++03)
C++
61
star
15

trie

Trie is a lightweight and simple autocompletion data structure written in C++11.
C++
43
star
16

attila

🔥 Attila is a tiny atlas texture-packer (tool)
C++
40
star
17

quant

🍥 Tiny quantization suite supporting conversion to/from half-floats, s/unorm bytes, quaternions and vectors (C++03).
C++
39
star
18

wire

🔌 Wire is a drop-in std::string replacement with extended functionality and safe C/C++ formatters (C++11).
C++
39
star
19

tween

👯 Tween is a lightweight easing library. Written in C++03
C++
35
star
20

apathy

💾 Apathy is a lightweight path/file/mstream/mmap IO library (C++03)
C++
35
star
21

pug

🐶 pug, png with a twist: lossy image format
33
star
22

malloc-survey

📈 Allocation benchmarks
C++
30
star
23

mINI

▫️ A very minimal .INI reader/writer (C++11)
C++
29
star
24

id

:suspect: ID, a compile-time string hasher and sequential ID generator (C++11)
C++
27
star
25

LRU

A lightweight LRU cache structure for list<T> and map<K,V> containers. Written in C++11
C++
27
star
26

bubble

💬 A simple and lightweight C++11 dialog library (for Windows)
C++
25
star
27

knot

Knot is a lightweight and simple TCP networking C++ library with no dependencies.
C++
25
star
28

sqlight

🔦 SQLight is a lightweight MySQL client written in C++11. Based on code by Ladislav Nevery
C++
25
star
29

DrEcho

💊 Dr Echo spices your terminal up (C++11)
C++
24
star
30

cocoa

🍫 Cocoa is an uniform hashing library with no dependencies that provides interface for CRC32, CRC64, GCRC, RS, JS, PJW, ELF, BKDR, SBDM, DJB, DJB2, BP, FNV, FNV1a, AP, BJ1, MH2, SHA1, SFH (C++11)
C++
24
star
31

fmt11

Tiny format/mustache templating library (C++11)
C++
22
star
32

auth

Simple, lightweight and safe client-server authentication system. Written in C++
C++
22
star
33

bundler

📦 Command-line archiver: DEFLATE, LZMA, LZIP, BZIP2, ZPAQ, LZ4, ZSTD, BROTLI, BSC, CSC, BCM, MCM, ZMOLLY, ZLING, TANGELO, SHRINKER, CRUSH, LZJB and SHOCO streams in a ZIP file.
C++
21
star
34

moon9

a game framework. warning: wip, dev, unstable, radiation hazard, defcon 3
C++
21
star
35

assume

🙈 Assume is a smarter assert replacement (C++03)
C++
21
star
36

bourne

😏 Bourne is a lightweight JSON de/serializer (C++11).
C++
21
star
37

unify

🔗 A C++11 function to normalize resource identificators
C++
20
star
38

collage

✂️ A lightweight C++ library to diff and patch arbitrary data
C++
20
star
39

metrics

📊 Pretty table metrics w/ benchmarking, unit conversions in CSV,TSV,ASCII,markdown (C++11)
C++
19
star
40

sand

⌛ Sand is a lightweight time controller (C++11)
C++
19
star
41

hertz

⌚ Hertz, simple framerate locker (C++11)
C++
18
star
42

frodo

💍 A lightweight ring dependency system (C++11)
C++
18
star
43

giant

🗿 Giant is a tiny C++11 library to handle little/big endianness.
C++
18
star
44

vle

Simple variable-length encoder/decoder (C99)(C++03)
C++
15
star
45

heal

💉 Heal is a lightweight C++ library to aid and debug applications. Heal requires C++11 (or C++03 with boost at least).
C++
15
star
46

live

🎭 Automatic reloader of constants during runtime, featuring type inference. Written in C++11.
C++
15
star
47

crawler

Crawler, a quick prototiping platform for Windows (C++11)
C
14
star
48

units

fork of http://calumgrant.net/units (unavailable) + new units + c++0x support + markdown documentation (C++03)
C++
14
star
49

unifont

Embeddable console 1bpp font that supports many european/eastern unicode codepoints. Aimed to gamedev (C++11).
C
13
star
50

warp

♻️ A handy string interpolator (C++11)
C++
13
star
51

flow

🎈 Lightweight C++ network downloader with native fallbacks. Aimed to gamedev.
C++
13
star
52

burg

Simple burg linear predictor (C++11)
C++
13
star
53

oak

🌳 A simple and lightweight tree container (C++03)
C++
13
star
54

memo

📌 Simple and lightweight factory class, featuring automatic type casting. Written in C++11
C++
12
star
55

journey

🐫 Lightweight append-only, header-less, journaling file format (C++11)
C++
12
star
56

route66

⛽ Lightweight embeddable HTTP server. Written in C++11 (or C++03 w/boost).
C++
12
star
57

duty

Duty is a lightweight C++11 task manager for parallel coroutines and serial jobs. Duty requires no dependencies.
C++
10
star
58

unlzma

A very compact LZMA decoder (C++03)
C++
9
star
59

sentry

Sentry is a lightweight data monitor (C++11)
C++
9
star
60

vitae

📄 My self-compilable C++ resume
C++
9
star
61

codex

Codex is a lightweight and simple C++ library to escape, unescape, read, write and convert from/to different encoding charsets. Codex requires no dependencies.
C++
8
star
62

flare

✨ Lightweight C++ API to deal with digital signals/logical buttons (C++03).
C++
7
star
63

solace-wip

Solace is a modern console replacement. Written in C++03
C++
6
star
64

error64

Handle custom 64-bit error codes, with extended meta-info (C, C++)
C
6
star
65

fortfont

💱 Collection of western, CJK and iconographic fonts free for commercial usage
CSS
5
star
66

cash-of-clans

a free re-implementation of a working game economy system
C++
5
star
67

gpulib

C++
4
star
68

rgb332

custom uniform RGB332 palette
C++
4
star
69

hyde

🎮 Hyde is a lightweight and simple Human Inferface Device (HID) C++ framework with no dependencies.
C++
4
star
70

bridge

A standard C++11 <--> C++03/boost compatibility layer, plus a few utils
C++
3
star
71

pitch

📒 A forkable game pitch template (CC0, Markdown)
3
star
72

unordered_map

Portable header for std::unordered_map<K,V> template
C++
3
star
73

variant

Variant is a varying C++11 class that clones javascript behaviour as much as possible
C++
2
star
74

emojis

:octocat: Emojis, atlased and indexed
2
star
75

CLDR

Compact data from the Unicode Common Locale Data Repository
C++
2
star
76

blender-wip

An agnostic keyframe interpolation and animation controller. Written in C++11.
C++
2
star
77

atom-wip

A small library to multiplex, to interweave, to sort, to split and to join (sub)streams of binary data (C++11).
C++
2
star
78

depot

asset depository for all my repos
C++
2
star
79

vision

a few assorted premises and thoughts
2
star
80

jabba-wip

jabba, the hud engine. yet another generic hud/ui engine
C++
2
star
81

JXMLex

JXMLex description format
1
star
82

watchmen-wip

Dependency system for your libraries of game assets in run-time
C++
1
star
83

JXML

JXML is a loss-less representation of JSON in XML, so data can be reused with XML tools.
1
star
84

rescle

Automatically exported from code.google.com/p/rescle
C++
1
star
85

tint-wip

Colorful logging tool
C++
1
star
86

stringbase

Stringbase is a collaborative effort aimed to translate common texts found in videogames and regular apps. Free to use. Commits welcome!
1
star