Information Technology Reference
In-Depth Information
array of techniques can be used to generate this
information, applied at different stages of the
program code lifecycle, as shown in call-outs A
to D in Figure 2.
For example, to measure the wait times of threads
that are processing HTTP packets received from a
network in a given application, developers could
instrument only those wait calls that exist in a
particular function, as opposed to all wait calls
across the complete program. Definition of the
context (function and condition) is straightforward
in a metaprogramming or aspect-programming
language. The following excerpt illustrates an
AspectC++ (Spinczyk et al., 2005) rule for such
an example.
Given the original code:
Source-code instrumentation
Instrumenting source code manually is imprac-
tical in large systems. Instrumentation can be
automated, however, through source-to-source
transformation. Metaprogramming frameworks,
such as Proteus (Waddington & Yao, 2005), TXL
(Cordy, Halpern, & Promislow, 1991), Stratego
(Visser, 2001) and DMS (Baxter, 2004), enable
modifications to source code before it is com-
piled or preprocessed (Figure 2, label A). These
metaprogramming frameworks provide a pro-
gramming lan guage that can be used to define
context-sensitive modifications to source code.
Transformation programs are compiled into ap-
plications that perform rewriting and instrumen-
tation of source, which is given as input. Source
code can also be instrumented just before it is
compiled in a form of preprocessing (Figure 2,
label B). Aspect-oriented programming (Spinc-
zyk, Lohmann, & Urban, 2005; Kiczale, Hilsdale,
Hugunin, Kersten, Palm, & Griswold, 2001) is an
example of preprocessed code modification.
Applying instrumentation to source code—as
opposed to applying it to binary code—makes it
easier to align trace functionality with higher-
level, domain-specific abstractions, which mini-
mizes instrumentation because the placement of
additional code is limited to only what is necessary.
#include <stdio.h>
#include <pthread.h>
pthread_mutex_t * mute;
int count = 0;
int main() {
pthread_mutex_init(mute, NULL);
pthread_mutex_lock(mute);
count = 1;
pthread_mutex_unlock(mute);
ReadPacket();
return 0;
}
void ReadPacket() {
/* code that we wish to instrument */
pthread_mutex_lock(mute);
pthread_mutex_unlock(mute);
}
The following AspectC++ aspect defines a
rule that inserts calls to function TraceEvent()
after each call to pthread_mutex_lock that exists
within function ReadPacket (expressed through
a join-point filter). (Box 1)
Box 1.
aspect TraceAspect {
advice call(“% pthread_mutex_lock(...)”) && within(“% ReadPacket(...)”) : after()
{
TraceEvent();
}
};
 
Search WWH ::




Custom Search