Skip to content

CallTracer is an instrument tool, which is able to be linked to a C/C++ program via shared lib, then record the program call stack history, as well as a utility to convert the call stack into multiples vitualizaters, including: seqdiag, diagrams and flamegraph.

Notifications You must be signed in to change notification settings

leezhenghui/calltracer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CallTracer

CallTracer is an instrument toolkit and aimed to provide an easy way for native(C/C++) program debugging, in particular, it can work as an utility to record and layout the program execution details in various straight-forward representation ways.(e.g: sequencing diagram, flamegraph)

It is compiled as a shared-lib and linked into a C/C++ program to enable the tracer. So far, it provides an user-friendly integration features for the program which is built upon gyp or waf, and also provides an out-of-box utility tool to convert the call stack into file names and source code line, finally be converted and presented by an appropriate visualizer, including: seqdiag, diagrams and flamegraph(default).

Features

  • Executable ELF (non-pie)

  • Static library

  • Dynamic linking library

  • Dynamic loading library

  • Tracing forked process

  • Multiple threads

  • Flamegraph

  • Seqdiag

  • Diagrams

If you are familiar with flamegraph, you might know about it originally is used for sampling data without an order guarantee. In calltracer, the generated flamegraph are for tracer data, and we will ensure the call stack sequencing following the tracer generated order.

Notable, turning on the func-trace will introduce significant performance impact, please avoid using it on a production environment.

TODO

  • Dynamic Tracer support, enable/disable the tracer on-the-fly

  • Support dlclose

  • Code refine/refactor

Prerequisites for run the example

  • Linux OS (Tested on Ubuntu variants)

  • Have addr2line command installed on your system

  • Have node.js runtime on your environment

  • Have seqdiag command installed if you want to generate seqdiag style sequencing diagram

Example

The sample is just used to demonstrate the usages of the tool. To make the sample cover mores situations, e.g: executable ELF, static-lib, dynamic linking shared-lib, dynamic loading shared-lib, forked process and multiple-threads, I am trying to split the sample into various modules with different lib types, this definitely does not make a sense in a real-life program.

Sample Components

How to run

The project is using GYP as the compile tool.

git clone https://github.com/leezhenghui/calltracer.git 
git submodule update --init

make clean
make 
make run-debug 

Using below command to conver the trace log into a visualizer view:

  cd ./tools/iseq/ 
  npm install 
  ./tools/iseq/iseq

Visualizer

FlameGraph (default)

FlameGraph Example

Open the original image and click(zoon in) the flame block you are interested in and get more detailed invocation information followed by that point, e.g: invocation seq, invocation occurs timestamp, file name and source code line.

Seqdiag

Diagrams

Waf

A WAF script is provided in this tool, which aim to enable the tool on a program using waf compiler framework, e.g: the early(initial) phase of node.js and node.js bindings implements. Here is some example flamegraph images, which I ever used for node v0.1.15(a quite old node.js impl based on waf, provides a very simple C/C++ binding extension, the event-loop is still running under libev and libeio) implementation debugging. Since the trace size a little bit large, I generate these diagrams by cutting down most of V8 trace points.

Node.js v0.1.15 Init

Node.js v0.1.15 Init

Node.js v0.1.15 HelloWorld Async-Binding

Download the orignal svg file for a detailed info via zoom-in/zoom-out.

Node.js v0.1.15 HelloWorld Sync-Binding

Download the orignal svg file for a detailed info via zoom-in/zoom-out.

Node.js v0.1.15 HelloWorld JS Http Server

Download the orignal svg file for a detailed info via zoom-in/zoom-out.

Node.js v0.1.15 HelloWorld FS

Download the orignal svg file for a detailed info via zoom-in/zoom-out.

About

CallTracer is an instrument tool, which is able to be linked to a C/C++ program via shared lib, then record the program call stack history, as well as a utility to convert the call stack into multiples vitualizaters, including: seqdiag, diagrams and flamegraph.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published