tracetool

by froglogic

froglogic / tracetool

An efficient and configurable logging framework for C++

127 Stars 11 Forks Last release: almost 2 years ago (3.1.1) GNU Lesser General Public License v3.0 1.2K Commits 48 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

tracetool - a configurable and efficient logging framework for C++

tracetool is a framework created by froglogic for tracing the execution of a C or C++ program and inspecting its state. This is achieved by instrumenting the source code of the target program and linking the recompiled sources against a shared

tracelib
library.

Image Of TraceTool GUI

License

tracetool is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Installation

Building the framework requires

The actual build is the merely a matter of running the commands

cmake -DCMAKE_PREFIX_PATH=
make

On Windows, you may want to pass

-G "NMake Makefiles"
to cmake to generate Makefiles and then use
nmake
to use those Makefiles.

Quick Start

Here's a quick step by step guide on how to instrument a basic program so that it generates trace information. Here's the initial source code of the sample program:

#include 
#include 

int main() { using namespace std;

string name;
cout << "Please enter your name: ";
cin >> name;

cout << "Hello, " << name << "!" << endl;

}

First, instrument the above source code so that the

tracelib.h
header is included and insert a few calls to various tracelib macros into the source code. Here's the instrumented code:
#include 
#include 

#include "tracelib.h"

int main() { fTrace(0) << "main() entered";

using namespace std;

string name;
cout &lt;&lt; "Please enter your name: ";
cin &gt;&gt; name;

fWatch(0) &lt;&lt; fVar(name);

cout &lt;&lt; "Hello, " &lt;&lt; name &lt;&lt; "!" &lt;&lt; endl;

fTrace(0) &lt;&lt; "main() finished";

}

Save the resulting file to e.g.

hello\_instrumented.cpp
.

Here's a sample compile line for use with

cl.exe
(the compiler which comes with Microsoft Visual Studio):
cl /EHsc hello_instrumented.cpp /I \include\tracelib
    \lib\tracelib.lib
    ws2_32.lib

The resulting binary (

hello\_instrumented.exe
in the above case) will behave as before. The tracing (and the resulting change to runtime performance) is only activated in case a special configuration file was detected.

Creating a configuration file is a matter of writing some XML. Save the following file as

tracelib.xml
and store it in the same directory as
hello\_instrumented.exe
which was built above:
  hello_instrumented
  
  


Now, running the program will generate quite a bit of additional output:

03.09.2010 16:00:56: Process 2524 [started at 03.09.2010 16:00:56] (Thread 468): [LOG] 'main() entered' hello_instrumented.cpp:8: int __cdecl main(void)
Please enter your name: Max
03.09.2010 16:00:57: Process 2524 [started at 03.09.2010 16:00:56] (Thread 468): [WATCH] hello_instrumented.cpp:16: int __cdecl main(void)
Hello, Max!
03.09.2010 16:00:57: Process 2524 [started at 03.09.2010 16:00:56] (Thread 468): [LOG] 'main() finished' hello_instrumented.cpp:20: int __cdecl main(void)
03.09.2010 16:00:57: Process 2524 [started at 03.09.2010 16:00:56] finished

Components

The tracetool framework consists of multiple components:

  • tracelib.dll
    (resp.
    libtracelib.so
    on Linux) is a dynamic library (plus accompanying header files) which has to be linked into any application which wishes to use the tracing functionality.
  • tracegui
    is a GUI for reviewing previously recorded traces as well as recording and watching the trace generated by running applications live.
  • traced
    is a daemon process which collects and stores trace data in the background without running a GUI.Traced applications can be configured to send their output over a network connection to
    traced.exe
    . The recorded traces can be sent to other people and reviewed later using
    tracegui
    .
  • trace2xml
    is a utility program for dumping a trace database generated by
    tracegui
    or
    traced
    into an XML file which can then be processed by other scripts.
  • xml2trace
    performs the reverse operation of
    trace2xml
    : given an XML file, a
    .trace
    file is generated which can be loaded by
    tracegui
    .
  • convertdb
    is a helper utility for converting earlier versions of databases with tracelib traces.

Acknowledgements

This project is really just standing on the shoulders of giants. It was made possible by and takes advantage of a few other open source projects:

  • The PCRE library is used for matching function names to include in the execution trace via regular expressions.
  • For matching functionn names to include in the execution trace via wildcard patterns, the wildcmp function is used.
  • Reading the
    tracelib.xml
    file is done using the TinyXML parser.
  • Stack traces logged for selected trace points are generated by StackWalker.
  • Efficient storage of execution traces is implemented using SQLite.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.