Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. function cputime call count
  2. foo 500 1
  3. bar 1500 3
  4.  
  5. #!/usr/sbin/dtrace -s
  6.  
  7. pid$1:$2::entry
  8. {
  9. ++self->call_depth[probefunc];
  10.  
  11. self->start[probefunc, self->call_depth[probefunc]] = timestamp;
  12. self->vstart[probefunc, self->call_depth[probefunc]] = vtimestamp;
  13. }
  14.  
  15. pid$1:$2::return
  16. /self->start[probefunc, self->call_depth[probefunc]]/
  17. {
  18. @function_walltime[probefunc] = sum(timestamp - self->start[probefunc, self->call_depth[probefunc]]);
  19. self->start[probefunc, self->call_depth[probefunc]] = 0;
  20. @function_cputime[probefunc] = sum(vtimestamp - self->vstart[probefunc, self->call_depth[probefunc]]);
  21. self->vstart[probefunc, self->call_depth[probefunc]] = 0;
  22.  
  23. --self->call_depth[probefunc];
  24. }
  25.  
  26. #!/usr/sbin/dtrace -qs
  27.  
  28. pid$1:$2::entry
  29. {
  30. self->vstart[probefunc] = vtimestamp;
  31. }
  32.  
  33. pid$1:$2::return
  34. {
  35. this->cputime = vtimestamp - self->vstart[probefunc];
  36. /* Sub the caller function CPU time */
  37. @function_cputime[ufunc(ucaller)] = sum(-(this->cputime));
  38. /* Add the callee function (current function) CPU time */
  39. @function_cputime[ufunc(uregs[R_PC])] = sum(this->cputime);
  40. /* Add the callee function (current function) count */
  41. @function_count[ufunc(uregs[R_PC])] = sum(1);
  42. }
  43.  
  44. #!/usr/sbin/dtrace -s
  45. #pragma option quiet
  46.  
  47. pid$1:$2::entry
  48. /self->start[probefunc] == 0/
  49. {
  50. this->call_depth = self->call_depth++;
  51. self->func_pcs[this->call_depth] = uregs[R_PC];
  52.  
  53. self->start[probefunc] = timestamp;
  54. self->vstart[probefunc] = vtimestamp;
  55.  
  56. @function_entry_count[ufunc(uregs[R_PC])] = count();
  57. }
  58.  
  59. pid$1:$2::return
  60. /self->start[probefunc]/
  61. {
  62. this->call_depth = --self->call_depth;
  63.  
  64. this->wall_elapsed = timestamp - self->start[probefunc];
  65. self->start[probefunc] = 0;
  66. this->cpu_elapsed = vtimestamp - self->vstart[probefunc];
  67. self->vstart[probefunc] = 0;
  68.  
  69. @function_walltime_inc[ufunc(uregs[R_PC])] = sum(this->wall_elapsed);
  70. @function_walltime_exc[ufunc(uregs[R_PC])] = sum(this->wall_elapsed);
  71. @function_cputime_inc[ufunc(uregs[R_PC])] = sum(this->cpu_elapsed);
  72. @function_cputime_exc[ufunc(uregs[R_PC])] = sum(this->cpu_elapsed);
  73. @function_return_count[ufunc(uregs[R_PC])] = count();
  74. }
  75.  
  76. pid$1:$2::return
  77. /this->call_depth > 0/
  78. {
  79. this->caller_pc = self->func_pcs[this->call_depth - 1];
  80. @function_walltime_exc[ufunc(this->caller_pc)] = sum(-(this->wall_elapsed));
  81. @function_cputime_exc[ufunc(this->caller_pc)] = sum(-(this->cpu_elapsed));
  82. }
  83.  
  84. dtrace:::END
  85. {
  86. /* normalize to millisecons */
  87. normalize(@function_walltime_inc, 1000000);
  88. normalize(@function_walltime_exc, 1000000);
  89. normalize(@function_cputime_inc, 1000000);
  90. normalize(@function_cputime_exc, 1000000);
  91.  
  92. printf("n");
  93. printf("%-60s %21s %21s %25sn", "", "INCLUSIVE", "EXCLUSIVE", "CALL COUNT");
  94. printf("%-60s %10s %10s %10s %10s %12s %12sn",
  95. "MODULE`FUNCTION", "WALL [ms]", "CPU [ms]", "WALL [ms]", "CPU [ms]", "ENTRY", "RETURN");
  96. printa("%-60A %@10d %@10d %@10d %@10d %@12d %@12dn",
  97. @function_walltime_inc, @function_cputime_inc,
  98. @function_walltime_exc, @function_cputime_exc,
  99. @function_entry_count, @function_return_count);
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement