End-to-End Tracing of Ajax/Java Applications Using DTrace
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.
-
#!/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) ", jsIndent, "",
-
jsFile, copyinstr(arg2), (timestamp - startTimestamp) / 1000);
-
}
-
-
*mozilla$1:::js_function-return
-
/basename(copyinstr(arg0)) == jsFile/
-
{
-
printf("%*s < - %s:%s (JavaScript)(elapsed ms: %d) ", 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) ", 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) ", 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.