semile

profile what you care, monitor how it goes

View the Project on GitHub r-kan/semile

semile :)

Why semile?
We semile bcoz it helps overcome the flaw/bottleneck of our programs


What is semile?

A profiling framework that provides the ability to monitor programs, in general of any programming language, by the following two pieces of information:

Difference with other profiling tools?

P.S. The user-provided semantic specifications (via the profile library) is necessary for semantic profile

System Requirement

python3 (viewer)
g++ (c/cpp profile library)

Dependent Library

dot (graphviz)


Viewer Demonstration

semile viewer PNG format sample
(PNG format)

semile viewer PNG format sample
(XML format, browse by codebeautify.org/xmlviewer))


Profile Library

semile does not aim to profile all program execution, it only profile the execution specified via the profile library. Currently, cpp profile library is provided.

Tutorial: profile a cpp program

  1. Choose the statements to be profiled
  2. Have a SEMILE in same scope of the statements

And that's it!

In particular, a helpful way diagnosing is use SEMILE_MSG to leave custom footprint message.

Code example

void quicksort(vector<int>& x, int start_pos, int end_pos)
{
  SEMILE; // profile at beginning of the scope
  // SEMILE_N(abc); // or profile with custom name
  ...
}

Here, every quicksort execution will be profiled.
Nested, or recursive SEMILE is also possible.

void quicksort(vector<int>& x, int start_pos, int end_pos)
{
  SEMILE;
  SEMILE_MSG(GetStr(x, start_pos, end_pos));
  ...
  int pivot = start_pos;
  SEMILE_MSG("pivot: " + GetStr(x[pivot]) + "\\n");
  ...
  Swap(x, i, j);  
  SEMILE_MSG(GetStr(x[i]) + " <=> " + GetStr(x[j]) + "\\n");
}

After SEMILE, we can have SEMILE_MSG at any time to log profile message.
Here, internal flow of quicksort is revealed and combined to resulted profile.

One possible viewer generated PNG is then as follows:
(run quicksort 3 times with random inputs)
the viewer generated PNG for quicksort


Except c++, semile also profiles c sources via the c interface.

Tutorial: exploit the c interface

Due to the lack of RAII, semile support in c requires a pair of profile specifications:

Code example

void quicksort(int* x, int start_pos, int end_pos)
{
  void* inst = SEMILE_BEGIN;
  SEMILE_MSG_C(inst, GetStr(x, start_pos, end_pos));
  ...
  SEMILE_END(inst);
}

It takes much care to handle SEMILE_END. However, be able to control directly the profile instance also gives much flexibility, e.g., conditional profile:

void* inst = NULL;
if (is_cared_run) {
  inst = SEMILE_BEGIN;
}
...
SEMILE_END(inst);

Finally, there are two ways to disable semile:


Contact

Please contact Rodney Kan by its_right@msn.com for any question/request/bug without hesitation.