All Projects → finaldie → ftracer

finaldie / ftracer

Licence: MIT license
A toolkit for tracing C/C++ program, to generate a time-line based callgraph

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects
c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language
HTML
75241 projects
Makefile
30231 projects

Projects that are alternatives of or similar to ftracer

profiler
A tool to trace java method dynamically for android application.
Stars: ✭ 32 (-15.79%)
Mutual labels:  tracer
shield-dubbo-tracer
基于dubbo2.6.4的Dubbo TraceId的设置/获取/传递工具包
Stars: ✭ 28 (-26.32%)
Mutual labels:  tracer
AppDynamics.DEXTER
Turn your APM data store into a Data Warehouse with advanced reporting, including entities, configuration, metrics, flowmaps, events, snapshots and call graph flame graphs
Stars: ✭ 79 (+107.89%)
Mutual labels:  callgraph
rtl2dot
C call graph generator
Stars: ✭ 48 (+26.32%)
Mutual labels:  callgraph
gen-callgraph
gen-callgraph is a script to generate call graph from elf binary
Stars: ✭ 47 (+23.68%)
Mutual labels:  callgraph
Lambda
Physically based renderer written in C++
Stars: ✭ 26 (-31.58%)
Mutual labels:  tracer
Uftrace
Function graph tracer for C/C++/Rust
Stars: ✭ 1,986 (+5126.32%)
Mutual labels:  tracer
node-wasm-trace
Instruments wasm files and traces execution
Stars: ✭ 24 (-36.84%)
Mutual labels:  tracer
FuSeBMC
FuSeBMC is a novel Energy-Efficient Test Generator that exploits fuzzing and BMC engines to detect security vulnerabilities in real-world C programs.
Stars: ✭ 26 (-31.58%)
Mutual labels:  tracer
dnf-automatic-restart
Restart machine or services after dnf-automatic installed updates
Stars: ✭ 34 (-10.53%)
Mutual labels:  tracer
http4s-tracer
📊 End-to-end tracing system for Http4s
Stars: ✭ 112 (+194.74%)
Mutual labels:  tracer
uniprof
A stack tracer/profiler for Xen domains
Stars: ✭ 29 (-23.68%)
Mutual labels:  tracer
barectf
Generator of ANSI C tracers which output CTF data streams
Stars: ✭ 50 (+31.58%)
Mutual labels:  tracer
peekaboo
An standalone execution trace library built on DynamoRIO.
Stars: ✭ 17 (-55.26%)
Mutual labels:  tracer
opentracing-metrics-tracer
Exports cross-process metrics via OpenTracing to Prometheus.
Stars: ✭ 13 (-65.79%)
Mutual labels:  tracer
Go Callvis
Visualize call graph of a Go program using Graphviz
Stars: ✭ 3,692 (+9615.79%)
Mutual labels:  callgraph
Javascript-Explorer-Callgraph
Call graph based on Abstract Syntax Tree in Javascript
Stars: ✭ 33 (-13.16%)
Mutual labels:  callgraph
custom-bytecode-analyzer
Java bytecode analyzer customizable via JSON rules
Stars: ✭ 66 (+73.68%)
Mutual labels:  callgraph
callGraph
A multi-language tool which parses source code for function definitions and calls
Stars: ✭ 50 (+31.58%)
Mutual labels:  callgraph
TypeScript-Call-Graph
CLI to generate an interactive graph of functions and calls from your TypeScript files
Stars: ✭ 139 (+265.79%)
Mutual labels:  callgraph

Build Status

ftracer

A toolkit for tracing C/C++ program(including multi-thread program), it's used to generate a time-line based callgraph, which will guide us to understand the core of the program extremely fast at the beginning.

The devil is in the details...

Imagine that, if there is a 10 years old and huge project will be transferred to us, and the corresponding requirements will come soon as well (like the new features, bug fix..), how can we locate to the core path in a very limited time? So we need a powerful tool to help us. This time-line based callgraph will save us a lot of time to deal with the complex details, we can focus on the more important things, and make the life easier.

And also we can use it as a source code index in the entire working cycles, especially for a very complex program. Everytime we want to remember something from the high level, we can use it, just follow the callgraph flow, to see how it works, as well as we might identify some problems from it :)

There are some existing Callgraphs for the RocksDB, Lua and Redis, we can use them directly without any addtional efforts.

ftracer demo

Before Start

Please note that, the tracer works for us in the following scenarios:

  • We can touch the source code, and easy to re-compile it in our dev environment
  • We need a time-line based call graph

If NOT, we might need some other callgraph tools.

Exceptions

  • The program has core dump issue, it may not help us, currently we should use gdb to fix it first

How to Use it

Check out

git clone [email protected]:finaldie/ftracer.git

Compile ftracer

make

Re-Compile Target Program

To make the tracer working, we should re-compile the application with -g -finstrument-functions flags

make CFLAGS+="-g -finstrument-functions -O0"

NOTE: Make sure there is no optimization option like -O2, if exist, replace it with -O0 or just drop it. Btw, we can try the examples in ftracer

Generate Call Graph Report

  • PRELOAD ftracer.so in the wrapper script

    bash $ cat run.sh
    #!/bin/sh
    export LD_PRELOAD=/path/to/ftracer.so:libdl.so
    
    ./yourapp
  • Run it

    ./run.sh
  • Generate the Report

    cd tools
    ./gen_report.sh -e yourapp -f /tmp/trace.txt

Advanced

env variables

  • Start tracer when entering into a specific function address

    export FTRACER_FUNC_ENTRY=xxx  # xxx is the function address, like 0000123
    
  • Start tracer when receiving a specific signal

    export FTRACER_SIG_NUM=10 # 10 is SIGUSR1, kill -s SIGUSR1 PID to start tracer
    
  • Specific a output tracer file

    export FTRACER_FILE=/tmp/your_tracer_file
    

NOTE: About the two features signal and function address entrance, they can not enable in the same time, if that, the signal feature will not be take effect.

gen_report Options

  • -e Program Location

    The absolute program path, for example /bin/ls

  • -f Raw trace file dumped by the program

    By default, the raw trace file is at /tmp/trace.txt, use -f /tmp/trace.txt all the time should be OK

  • -s Regex Symbol Filter

    Sometimes, we deal with C++ programs, there are a lot of noises in there, like std, boost... so we should filter them out.
    For this, we should use -s arg, for example:

    gen_report.sh -e app -f /tmp/trace.txt -s "^std::"
  • -S Filter by file/path

    For this, the -S arg will help us, for example, if we want to filter all the c++ related information out:

    gen_report.sh -e app -f /tmp/trace.txt -S /include/c++
  • -p Keep at most N level of path

    If a path is too long, it will be a noise for us, so the -p parameter will help to keep at most N level of path, for example, there is a path /path/a/b/c/d.c, use -p 1 the path in the report will be c/d.c.
    If no -p or -p value is a negative number, this feature will be ignored

  • -o Specific output folder

    The default output folder is /tmp, but if we want to specific another folder, -o output will help us.

  • -d Don't cleanup the temporay data

    If we get some wrong data when running gen_report.sh, the temporay data will help us to debug what's happened, so if we want to debug it, pass the -d paramter.

  • -r Read symbols from the dynamic libraries

    Most of the time, we only care about the symbols from the program itself, but in case we want to read the symbols from the dynamic libraries, enable this flag then. Please note, enable this flag will slow down the report generation.

  • -v Show debug info

    If we need more information during the report generating, pass -v in

  • -t Start N process to generate report

    The addr2line is slow, sometimes we need to start N processes to generate the report in parallel, it will reduce the generating time. For example -t 4

  • -F output format

    Default output format is plain, and we also can specific html format, for example -F html, this will be greatly helpful when we are dealing with a very big call graph. Lua5.3.3 Callgraph

Enjoy and Analyze the Report

For now, open the /tmp/trace_report.txt.threadid and enjoy it. The example like:

 1x main(/home/username/github/ftracer/example/test.c:44) - (called from ??:0)
.. 3x a(/home/username/github/ftracer/example/test.c:36) - (called from test.c:45)
.... 1x b(/home/username/github/ftracer/example/test.c:21) - (called from test.c:39)
...... 1x c(/home/username/github/ftracer/example/test.c:16) - (called from test.c:25)
.... 1x b(/home/username/github/ftracer/example/test.c:21) - (called from test.c:39)
...... 2x d(/home/username/github/ftracer/example/test.c:11) - (called from test.c:27)
...... 1x e(/home/username/github/ftracer/example/test.c:6) - (called from test.c:31)

More detail see the example, and Contact Me, let's do it better :D

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].