End-to-End Tracing of Ajax/Java Applications Using DTrace
Written by on July 25th, 2007 in Ajax News.
We posted about using DTrace to profile Firefox in the past, and today Amit Hurvitz published a piece on Ajax, DTrace and Where They Meet.
The article walks you through setting up dtrace on an an Ajax tracing example and then goes into detail on tracing Ajax and Java call flow where they are tracing the call flow of the JavaScript functions and the Java servlet methods, which responds to the Ajax calls using the script:
-
-
#!/usr/sbin/dtrace -Zs
-
-
#pragma D option quiet
-
#pragma D option switchrate=10
-
-
dtrace:::BEGIN
-
{
-
jsIndent = 0;
-
jsFile = “ajax-validation”;
-
javaMethodBoundary= “doGet”;
-
startTimestamp = timestamp;
-
}
-
-
*mozilla$1:::js_function-entry
-
/basename(copyinstr(arg0)) == jsFile/
-
{
-
jsIndent += 2;
-
printf(”%*s -> %s:%s (JavaScript)(elapsed ms: %d)\n”, jsIndent, “”,
-
jsFile, copyinstr(arg2), (timestamp - startTimestamp) / 1000);
-
}
-
-
*mozilla$1:::js_function-return
-
/basename(copyinstr(arg0)) == jsFile/
-
{
-
printf(”%*s <- %s:%s (JavaScript)(elapsed ms: %d)\n”, jsIndent, “”,
-
jsFile, copyinstr(arg2), (timestamp - startTimestamp) / 1000);
-
jsIndent -= 2;
-
}
-
-
-
hotspot$2:::method-entry
-
{
-
self->strPtr = (char *)copyin(arg1, args[2]+1);
-
self->strPtr[(int)args[2]] = ”;
-
self->classStr = (string)self->strPtr;
-
self->strPtr = (char *)copyin(arg3, (int)args[4]+1);
-
self->strPtr[(int)args[4]] = ”;
-
self->methodStr = (string)self->strPtr;
-
}
-
-
hotspot$2:::method-entry
-
/javaMethodBoundary == self->methodStr/
-
{
-
self->interested = 1;
-
self->indent = 0;
-
}
-
-
hotspot$2:::method-entry
-
/self->interested/
-
{
-
self->indent += 2;
-
printf(”%*s -> %s:%s (Java)(elapsed ms: %d)\n”, self->indent, “”,
-
self->classStr, self->methodStr, (timestamp - startTimestamp) / 1000);
-
}
-
-
hotspot$2:::method-return
-
{
-
self->strPtr = (char *)copyin(arg1, args[2]+1);
-
self->strPtr[(int)args[2]] = ”;
-
self->classStr = (string)self->strPtr;
-
self->strPtr = (char *)copyin(arg3, (int)args[4]+1);
-
self->strPtr[(int)args[4]] = ”;
-
self->methodStr = (string)self->strPtr;
-
}
-
-
hotspot$2:::method-return
-
/self->interested/
-
{
-
printf(”%*s <- %s:%s (Java)(elapsed ms: %d)\n”, self->indent, “”,
-
self->classStr, self->methodStr, (timestamp - startTimestamp) / 1000);
-
self->indent -= 2;
-
}
-
-
hotspot$2:::method-return
-
/javaMethodBoundary == self->methodStr/
-
{
-
self->interested = 0;
-
/* exit(0); */
-
}
-
It then continues to show timings of methods and such. This may not be the simplest solution for debugging, but at least you can get inside the black box when you need too.
Source: Ajaxian
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/137298716/end-to-end-tracing-of-ajaxjava-applications-using-dtrace