Profiling Aspect
[CodeInstrumentation Group]

This aspect is defined in file: ../../AspectXLib/CodeInstrumentation/Profiling/aspects/Profiling.ax

Aspect Description

Sample aspect program to insert profiling instructions to the base code. Profiling a system means collecting the information about the time spent by each operation in the system. This sample aspect demonstrates how profiling instructions can be added to the base code. For each method, the time that the program spend executing the method body is computed and reported to the user at the end of the program execution.
Author:
A. Pasetti, O. Rohlik

Pointcuts

constructortargetConstructor
 Points to all constructors in the base code
classtargetClass
 Points to all classes
unittargetClassImplementationUnit
 Points to all the units (source files) that contain implementations of the methods defined in the classes specified by the targetClass pointcut
functiontargetMethod
 Points to all method definitions that are in the units (source files) specified by the pointcut targetClassImplementationUnit
returntargetMethodReturn
 Points to the return statements that must be modified
functiontargetMainFunction
 Points to the main() function
returntargetMainReturn
  Points to return statements in the main() function

Advices

addaddProfilingVariables
  Insert declarations to each class
beforeinsertReporterCall
  Insert call of method _profilingReport() at the end of execution of the main() function
begininsertVariableDeclaration
 Insert the code that reads the current time and saves it to the local variable _profilingMethodStart
beforeinsertBeforeReturn
  Insert code that computes the time the program spent executing the current method
endinsertTraceAtEnd
  Insert code that computes the time the program spent executing the current method
addaddInclude
  Add the necessary #include statements
addaddProfilingReportMethod
  Insert the definition of _profilingReport() method
beginaddProfilingVariableInitialization
  Insert the initialization code of all profiling member variables to the class constructor

Pointcut Documentation

constructor targetConstructor (source)
Points to all constructors in the base code.
class targetClass (source)
Points to all classes.
unit targetClassImplementationUnit (source)
Points to all the units (source files) that contain implementations of the methods defined in the classes specified by the targetClass pointcut.
function targetMethod (source)
Points to all method definitions that are in the units (source files) specified by the pointcut targetClassImplementationUnit. Thus, it points to all method definitions (but not to definitions of constructors, destructors and C functions).
return targetMethodReturn (source)
Points to the return statements that must be modified. It only target the return statements of methods.
function targetMainFunction (source)
Points to the main() function.
return targetMainReturn (source)
Points to return statements in the main() function.

Advice Documentation

add addProfilingVariables (source)

Triplet: class add declaration declaration

Insert declarations to each class.

Set of new private member variables is added to the declaration of every class. For each method one member variable is defined. Its name is derived from the name of the method. Member variables have form _profiling_XXX where XXX stands for the method name. For example, the name of _profiling_test member variable is derived from the name of the test() method.

Two constructs of the XSL language are used to insert the variables: xsl:for-each and xsl:value-of. The xsl:for-each instruction locates all method declarations. Then the xsl:value-of instruction is used to extract the names of the methods and to write them to the base code.

The advice also inserts the declaration of the public method _profilingReport().

Refers to global pointcut: class targetClass

before insertReporterCall (source)

Triplet: return before codeFragment

Insert call of method _profilingReport() at the end of execution of the main() function. More precisely, it inserts the function call before every return statement of the main() function.

Refers to global pointcut: return targetMainReturn

begin insertVariableDeclaration (source)

Triplet: function begin codeFragment

Insert the code that reads the current time and saves it to the local variable _profilingMethodStart.

Refers to global pointcut: function targetMethod

before insertBeforeReturn (source)

Triplet: return before codeFragment

Insert code that computes the time the program spent executing the current method. It uses the current time and the value of the local variable _profilingMethodStart. The computed amount of time is added to the respective member variable _profiling_XXX where XXX stands for the name of the current method. This code is inserted before every return statement.

Refers to global pointcut: return targetMethodReturn

end insertTraceAtEnd (source)

Triplet: function end codeFragment

Insert code that computes the time the program spent executing the current method. It uses the current time and the value of the local variable _profilingMethodStart. The computed amount of time is added to the respective member variable _profiling_XXX where XXX stands for the name of the current method. This code is inserted at the very end of every class method.

Refers to global pointcut: function targetMethod

add addInclude (source)

Triplet: unit add include

Add the necessary #include statements. It adds the header file of MicroTime class that is used to measure time with accuracy of one microsecond. It also includes the iostream library and declares the std namespace needed for I/O operations.

Refers to global pointcut: unit targetClassImplementationUnit

add addProfilingReportMethod (source)

Triplet: unit add definition

Insert the definition of _profilingReport() method. The method lists all methods defined in the class. For every method it outputs the total execution time in microseconds.

Two constructs of the XSL language are used to access the member variables that stores the execution time for each method: xsl:for-each and xsl:value-of. The xsl:for-each instruction locates all method definitions. Then the xsl:value-of instruction is used to extract the local names of the methods and to write them to the base code.

Refers to global pointcut: unit targetClassImplementationUnit

begin addProfilingVariableInitialization (source)

Triplet: constructor begin codeFragment

Insert the initialization code of all profiling member variables to the class constructor. The two XSL constructs (xsl:for-each and xsl:value-of) are used to set all profiling member variables to zero.

Refers to global pointcut: constructor targetConstructor