Skip to content

heyfluke/gen-trace

 
 

Repository files navigation

Profiler Based On GCC & Chrome

Goal

To provide a tracer and a profiler based on the Chromium browser. Using the feature "chrome://tracing" of the browser as the view of tracer/profiler, this project aims to collect the data feeding the browser in a fairly easy way.

What it output

enter image description here

How to use

  1. Compile my plugin.

    Like this:

    g++ -I <where your plugin includes reside> -fno-rtti -fPIC -shared -o gentrace.so plugin.cpp

To find where the plugin includes reside, you needs to install the dev header of your GCC. This plugin requires the header of GCC 5.0 To do that on Ubuntu:

apt-get install gcc-5.0-plugin-dev

But 5.0 may not in the apt of Ubuntu, so you may still need to download the source and compile GCC. After make install phase, you will get all the plugin headers that required. 2. Compile the runtime of the profiler. Currently the runtime is tested on android machines. So you may define your own output path.

 g++ -fPIC -fno-rtti -fno-exceptions -O2 -g3 -DCTRACE_FILE_NAME=<your output path including file name> -c runtime_sigprof.cpp
  1. Compile your source using this plugin. Like this:
    gcc -fplugin=./gentrace.so xxx.c
  1. Link your program with the runtime
 gcc -o <your program> xxx.o runtime_sigprof.o
  1. Run your program until it ends. Collect the output file from . Open chrome://tracing, and press the "Load" button to load the file. You may see the result.

Why GCC plugin

Well, no one wants to add a C++ auto variable with constructor/destructor to collect data, especially a big project will thousands of functions may need to trace/profile. And there may be C source file that you can't use this technique. The plugin approach is an automatic resort to add start/end point. It does not require to change the source. Moreover it is exception safe.

FAQ

  1. Q: Why not just use -finstrument-functions option, and implement __cyg_profile_func_enter/__cyg_profile_func_exit? A: I need to collect the function name without having to query the symbol files.
  2. Q: Can I collect the result without waiting for the termination of my program. A: Yes. Just copy yout file back, and complete the file:
    echo ']}' >> <yout file>

Just Enjoy It.

About

gen trace that chrome://tracing understands

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 98.3%
  • Shell 1.1%
  • Vim Script 0.6%