End-to-End Tracing of Ajax/Java Applications Using DTrace

End-to-End Tracing of Ajax/Java Applications Using DTrace

Category: UtilityView the technorati tag: Utility

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.

 

 
JAVASCRIPT
 
  1. #!/usr/sbin/dtrace -Zs
  2.  
  3. #pragma D option quiet
  4. #pragma D option switchrate=10
  5.  
  6. dtrace:::BEGIN
  7. {
  8.         jsIndent = 0;
  9.         jsFile = "ajax-validation";
  10.         javaMethodBoundary= "doGet";
  11.         startTimestamp = timestamp;
  12. }
  13.  
  14. *mozilla$1:::js_function-entry
  15. /basename(copyinstr(arg0)) == jsFile/
  16. {
  17.         jsIndent += 2;
  18.         printf("%*s -> %s:%s (JavaScript)(elapsed ms: %d)\n", jsIndent, "",
  19.             jsFile, copyinstr(arg2), (timestamp - startTimestamp) / 1000);
  20. }
  21.  
  22. *mozilla$1:::js_function-return
  23. /basename(copyinstr(arg0)) == jsFile/
  24. {
  25.         printf("%*s < - %s:%s (JavaScript)(elapsed ms: %d)\n", jsIndent, "",
  26.             jsFile, copyinstr(arg2), (timestamp - startTimestamp) / 1000);
  27.         jsIndent -= 2;
  28. }
  29.  
  30.  
  31. hotspot$2:::method-entry
  32. {
  33.         self->strPtr = (char *)copyin(arg1, args[2]+1);
  34.         self->strPtr[(int)args[2]] = '\0';
  35.         self->classStr = (string)self->strPtr;
  36.         self->strPtr = (char *)copyin(arg3, (int)args[4]+1);
  37.         self->strPtr[(int)args[4]] = '\0';
  38.         self->methodStr = (string)self->strPtr;
  39. }
  40.  
  41. hotspot$2:::method-entry
  42. /javaMethodBoundary == self->methodStr/
  43. {
  44.         self->interested = 1;
  45.         self->indent = 0;
  46. }
  47.  
  48. hotspot$2:::method-entry
  49. /self->interested/
  50. {
  51.         self->indent += 2;
  52.         printf("%*s -> %s:%s (Java)(elapsed ms: %d)\n", self->indent, "",
  53.             self->classStr, self->methodStr, (timestamp - startTimestamp) / 1000);
  54. }
  55.  
  56. hotspot$2:::method-return
  57. {
  58.         self->strPtr = (char *)copyin(arg1, args[2]+1);
  59.         self->strPtr[(int)args[2]] = '\0';
  60.         self->classStr = (string)self->strPtr;
  61.         self->strPtr = (char *)copyin(arg3, (int)args[4]+1);
  62.         self->strPtr[(int)args[4]] = '\0';
  63.         self->methodStr = (string)self->strPtr;
  64. }
  65.  
  66. hotspot$2:::method-return
  67. /self->interested/
  68. {
  69.         printf("%*s < - %s:%s (Java)(elapsed ms: %d)\n", self->indent, "",
  70.             self->classStr, self->methodStr, (timestamp - startTimestamp) / 1000);
  71.         self->indent -= 2;
  72. }
  73.  
  74. hotspot$2:::method-return
  75. /javaMethodBoundary == self->methodStr/
  76. {
  77.         self->interested = 0;
  78.         /* exit(0); */
  79. }

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.

转载于:https://www.cnblogs.com/zengkefu/p/7502498.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值