Advertisement
Guest User

Untitled

a guest
Aug 29th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.52 KB | None | 0 0
  1. #!/usr/sbin/dtrace -Zs
  2.  
  3. #pragma D option quiet
  4.  
  5. dtrace:::BEGIN
  6. {
  7.         printf("Tracing... Hit Ctrl-C to end.\n");
  8. }
  9.  
  10. ruby*:::function-entry
  11. {
  12.         self->depth++;
  13.         self->exclude[self->depth] = 0;
  14.         self->function[self->depth] = timestamp;
  15. }
  16.  
  17. ruby*:::function-return
  18. /self->function[self->depth]/
  19. {
  20.         this->elapsed_incl = timestamp - self->function[self->depth];
  21.         this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];
  22.         self->function[self->depth] = 0;
  23.         self->exclude[self->depth] = 0;
  24.         this->file = basename(copyinstr(arg2));
  25.         this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1));
  26.  
  27.         @num[this->file, "func", this->name] = count();
  28.         @num["-", "total", "-"] = count();
  29.         @types_incl[this->file, "func", this->name] = sum(this->elapsed_incl);
  30.         @types_excl[this->file, "func", this->name] = sum(this->elapsed_excl);
  31.         @types_excl["-", "total", "-"] = sum(this->elapsed_excl);
  32.  
  33.         self->depth--;
  34.         self->exclude[self->depth] += this->elapsed_incl;
  35. }
  36.  
  37. ruby*:::object-create-start
  38. {
  39.         self->object = timestamp;
  40. }
  41.  
  42. ruby*:::object-create-done
  43. /self->object/
  44. {
  45.         this->elapsed = timestamp - self->object;
  46.         self->object = 0;
  47.         this->file = basename(copyinstr(arg1));
  48.         this->file = this->file != NULL ? this->file : ".";
  49.         this->name = copyinstr(arg0);
  50.  
  51.         @num[this->file, "obj-new", this->name] = count();
  52.         @types[this->file, "obj-new", this->name] = sum(this->elapsed);
  53.  
  54.         self->exclude[self->depth] += this->elapsed;
  55. }
  56.  
  57. ruby*:::gc-begin
  58. {
  59.         self->gc = timestamp;
  60. }
  61.  
  62. ruby*:::gc-end
  63. /self->gc/
  64. {
  65.         this->elapsed = timestamp - self->gc;
  66.         self->gc = 0;
  67.         @num[".", "gc", "-"] = count();
  68.         @types[".", "gc", "-"] = sum(this->elapsed);
  69.         self->exclude[self->depth] += this->elapsed;
  70. }
  71.  
  72. dtrace:::END
  73. {
  74.         printf("\nCount,\n");
  75.         printf("   %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
  76.         printa("   %-20s %-10s %-32s %@8d\n", @num);
  77.  
  78.         normalize(@types, 1000);
  79.         printf("\nElapsed times (us),\n");
  80.         printf("   %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
  81.         printa("   %-20s %-10s %-32s %@8d\n", @types);
  82.  
  83.         normalize(@types_excl, 1000);
  84.         printf("\nExclusive function elapsed times (us),\n");
  85.         printf("   %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
  86.         printa("   %-20s %-10s %-32s %@8d\n", @types_excl);
  87.  
  88.         normalize(@types_incl, 1000);
  89.         printf("\nInclusive function elapsed times (us),\n");
  90.         printf("   %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
  91.         printa("   %-20s %-10s %-32s %@8d\n", @types_incl);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement