Menu

Tree [a20b97] master /
 History

HTTPS access


File Date Author Commit
 include 5 days ago Björn Ganster Björn Ganster [a20b97] Let libinstrumentation create a report of alloc...
 source 5 days ago Björn Ganster Björn Ganster [a20b97] Let libinstrumentation create a report of alloc...
 test 5 days ago Björn Ganster Björn Ganster [a20b97] Let libinstrumentation create a report of alloc...
 test-pascal 2023-05-16 Björn Ganster Björn Ganster [abdd0a] Profiling support added
 .gitignore 2024-05-16 Björn Ganster Björn Ganster [9beba3] Fix corrupt string written by stGetCurrentThrea...
 CMakeLists.txt 2025-04-22 Björn Ganster Björn Ganster [006617] Added pointer whitelists
 Compiling with msvc.txt 2025-04-22 Björn Ganster Björn Ganster [006617] Added pointer whitelists
 Readme.txt 6 days ago Björn Ganster Björn Ganster [57d287] Improve memory tracker with a function to query...
 libinstrumentation.def 5 days ago Björn Ganster Björn Ganster [a20b97] Let libinstrumentation create a report of alloc...
 make_linux.sh 2022-12-19 bjoern bjoern [e65337] Linux port
 make_msvc_2017_x64.bat 2023-03-22 Björn Ganster Björn Ganster [175d23] Add scripts for building with MSVC 2022
 make_msvc_2017_x86.bat 2023-03-22 Björn Ganster Björn Ganster [175d23] Add scripts for building with MSVC 2022
 make_msvc_2022_x64.bat 2023-07-05 Björn Ganster Björn Ganster [06e1d9] cmake updates
 make_msvc_2022_x86.bat 2024-03-05 Björn Ganster Björn Ganster [a71504] It is good practice to delete objects after use...
 make_msys2_gcc_x64.bat 2023-07-03 Björn Ganster Björn Ganster [e55ee0] Rename startProfiling -> stStartProfiling, stop...
 make_msys2_gcc_x86.bat 2023-07-03 Björn Ganster Björn Ganster [e55ee0] Rename startProfiling -> stStartProfiling, stop...

Read Me

Use libinstrumentation to add stack traces to your code.  Usage:

- Add libinstrumentation to your project (details depend on the compiler used)
- Define a list of file numbers in a central location
- Add include: #include "libinstrumentation.h"
- Below the include, add a line like #define FILE_NUMBER FILE_NO_ARCHIVE_ACCESS_CPP
- Before any other call to the library, place a call to stInitialize()
- At the start of a function, add the macro SET_SCOPE;
- Before dangerous/long/critical operations, add a call to SET_OP;
- Replace any return statements with the RETURN macro
- Since RETURN is a macro, return statements after if need braces:

if (condition) return value;

becomes

if (condition) { RETURN value; }

- Any time you need a stacktrace, call stGetCurrentThreadStackTrace. This will get you a string composed of pairs a:b, where a is a file number you defined and b is a line number for that file

Please check out the latest version from git and please check the code samples.

Short rules about SET_SCOPE/SET_OP/RETURN:
- A function that does not throw and has no operations that can fail does not need SET_SCOPE/SET_OP/RETURN
- Functions that call other functions should use SET_SCOPE/SET_OP/RETURN to produce a call stack
- Simple argument checks do not need SET_SCOPE/SET_OP/RETURN. However, dereferencing this can already cause problems.
- Before SET_SCOPE is placed in a function, use return. All returns after SET_SCOPE must be RETURN to update the stacktrace.
- SET_OP may be placed in long functions to update the line counter in the stack frame.
- If RETURN is placed after if, RETURN must be wrapped in braces, because it is a macro, like this:

if(condition) {
	RETURN retVal;
}