Git Product home page Git Product logo

profiler's Introduction

##profiler - A simple Erlang profiler NIF##


###What is profiler?###

profiler is a NIF library that provides a simple interface for basic profiling of erlang/C++ code.


###Usage###

At its most basic, profiler allows you to measure execution time between arbitrary points in erlang/C++ code. Within an erlang process, an arbitrary number of counters can be accumulated, either globally or per-thread, and a simple text file with the counter statistics is output either by command, or by default at process exit.

####Basic Usage####

The primary erlang interface to profiler is the profiler:perf_profile/1 function. This takes a tuple of arguments, controlling a variety of operations.

For example:

Eshell V5.10.3  (abort with ^G)
1> profiler:perf_profile({prefix, './'}).
ok
2> profiler:perf_profile({start, 'tag1'}).

wait a while...

3> profiler:perf_profile({stop, 'tag1'}).
0
4>

The first line tells profiler to create its log file in the current directory, the second starts a counter named tag1, and the last terminates the named counter.

on exit from the erlang shell, profiler will have created a file that looks something like this (the file name is prefixed with the process id):

unix_prompt:>cat 0x20872600_profile.txt

totalcount 2
label 'tag1'
count 0x0 0
usec 0x0 3855829

What do these lines mean?

  • totalcount 2: profiler keeps track of the number of times a start/stop operation was invoked. This can be useful for estimating the total impact of the profiling itself. The first line says that the the total count of profiling operations was 2

  • label 'tag1': This is a whitespace-separated list of all counter tags that profiler has accumulated

  • count 0x0 0: This is a whitespace-separated list of the number of times profiling operations were invoked while the named counter was accumulating. This can be helpful for estimating the contribution of the profiling to each counter.

    NB The first (hex) argument after the label count is a thread id (in this case 0x0). If counters are being accumulated globally, this will always be 0x0, else a separate line is printed for each thread where counters were invoked

  • usec 0x0 3855829: This is a whitespace-separated list of the accumulated time, in micro-seconds, associated with each named counter in the label line. In this case, 3.86 seconds elapsed while the counter was active.

    NB The first (hex) argument after the label usec is a thread id (in this case 0x0). If counters are being accumulated globally, this will always be 0x0, else a separate line is printed for each thread where counters were invoked

####Per-Thread Counters####

An extra boolean argument to the start tuple specifies if the counter should be accumulated on a per-thread basis:

Eshell V5.10.3  (abort with ^G)
1> profiler:perf_profile({prefix, './'}).
ok
2> profiler:perf_profile({start, 'tag1', true}).

wait a while...

3> profiler:perf_profile({stop, 'tag1', true}).
0
4>

The file will now record the thread id as well as the elapsed time:

unix_prompt:>cat 0x205f2600_profile.txt

totalcount 2
label 'tag1'
count 0xb0ac5000 0
usec 0xb0ac5000 6512157 
####Utilities####
  • A simple macro ?FNNAME() is provided in profiler.hrl to return the current function name for use as a counter tag

  • To print the current counter stats interactively, along with other debug information, use profiler:perf_profile({debug}).

  • To dump the current counter stats to disk (in this example to the current directory) at any point interactively, use profiler:perf_profile({dump, './'}).

####Turning Profiling Off####

Profiling can be disabled in-situ in a variety of different ways:

  • Globally, by commenting out the line -define(PROFILE, 1). in profiler.hrl and recompiling the module.

    In this case, all calls to profiler:perf_profile/1 are no-ops, as is the macro ?FNNAME().

    Note however that a separate interface profiler:profile/1 is not controlled by the PROFILE define, so that profiling can be turned off globally, but individual counters can still be activated if desired, by using profiler:profile/1 instead of profiler:perf_profile/1 Note that the status of the no-op flag is shown when profiler:profile({debug}). is issued.

  • Interactively, via a call to profiler:perf_profile({noop, true}).

    This disables all profiling until profiler:perf_profile({noop, false}). is issued.

    Note that the status of the no-op flag is shown when profiler:perf_profile({debug}). is issued.

profiler's People

Stargazers

Doğukan Zorlu avatar Brian McClain avatar

Watchers

Boris Okner avatar James Cloos avatar

profiler's Issues

Does not build under Ubuntu 14.04

Testing 0d934a38af57adf0dd5b68bd739032fd0711e77e on Linux ubuntu-trusty64-riak-test 3.13.0-95-generic #142-Ubuntu SMP Fri Aug 12 17:00:09 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux and am getting the following error:

Compiling c_src/String.cc
c_src/String.cc:293:65: error: ‘std::ostream& gcp::util::operator<<(std::ostream&, gcp::util::String)’ should have been declared inside ‘gcp::util’
 std::ostream& gcp::util::operator<<(std::ostream& os, String str)
                                                                 ^
c_src/String.cc: In static member function ‘static int gcp::util::String::toInt(std::string)’:
c_src/String.cc:525:45: error: ‘strtol’ was not declared in this scope
   int iVal = strtol(str.c_str(), &endPtr, 10);
                                             ^
c_src/String.cc: In member function ‘float gcp::util::String::toFloat()’:
c_src/String.cc:546:44: error: ‘strtof’ was not declared in this scope
   float fVal = strtof(str_.c_str(), &endPtr);
                                            ^
c_src/String.cc: In member function ‘bool gcp::util::String::isValidPowerExpression()’:
c_src/String.cc:593:53: error: ‘strtod’ was not declared in this scope
     double baseVal = strtod(base.str().c_str(), NULL);
                                                     ^
c_src/String.cc:593:12: warning: unused variable ‘baseVal’ [-Wunused-variable]
     double baseVal = strtod(base.str().c_str(), NULL);
            ^
c_src/String.cc:604:12: warning: unused variable ‘expntVal’ [-Wunused-variable]
     double expntVal = strtod(expnt.str().c_str(), NULL);
            ^
c_src/String.cc: In member function ‘double gcp::util::String::getPowerExpression()’:
c_src/String.cc:626:53: error: ‘strtod’ was not declared in this scope
     double baseVal = strtod(base.str().c_str(), NULL);
                                                     ^
c_src/String.cc: In member function ‘double gcp::util::String::toDouble()’:
c_src/String.cc:662:47: error: ‘strtod’ was not declared in this scope
     double dVal = strtod(str_.c_str(), &endPtr);
                                               ^
c_src/String.cc: In member function ‘gcp::util::String gcp::util::String::findNextStringSeparatedByChars(std::string, bool)’:
c_src/String.cc:690:12: warning: unused variable ‘iStart’ [-Wunused-variable]
   unsigned iStart=0, iStop=0;
            ^
c_src/String.cc:690:22: warning: unused variable ‘iStop’ [-Wunused-variable]
   unsigned iStart=0, iStop=0;
                      ^
ERROR: compile failed while processing /usr/local/basho/riak_test_suite/riak_test/deps/profiler: rebar_abort
make: *** [compile] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.