profile what you care, monitor how it goes

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:

consumed time per execution



'footprint' debug message per execution



Difference with other profiling tools?

Profile 'semantically' Each call to the same function plays its individual role within profiling. Normal 'syntactic' profilers are good in other aspects but fail to achieve this.



Each call to the same function plays its individual role within profiling. Normal 'syntactic' profilers are good in other aspects but fail to achieve this. Lightweight The profiled program gives little run-time overhead. The viewer is compact that targets to provide only necessary information without fancy visual effect. It gives profile result in widespread PNG and XML format.



The profiled program gives little run-time overhead. The viewer is compact that targets to provide only necessary information without fancy visual effect. It gives profile result in widespread PNG and XML format. Message-embedded profile Custom information can be left within profile elements. It then also provides the ability to help reveal internal state/decision inside the program.



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



(PNG format)



(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

Choose the statements to be profiled

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)



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:

SEMILE_BEGIN , where profile resource is allocated



, where profile resource is allocated SEMILE_END , where profile resource is released



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 :

compile time: -DSEMILE_DISABLE in compiler option



run time: setenv SEMILE_ENABLE 0



Contact

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