Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More D scripts. Example using ruby-dtrace.
- Loading branch information
Philippe Hanrigou
committed
Nov 14, 2008
1 parent
6ad5eb7
commit 37a9588
Showing
6 changed files
with
210 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/sbin/dtrace -s | ||
#pragma D option quiet | ||
#pragma D option aggsortrev | ||
#pragma D option dynvarsize=64m | ||
#pragma D option ustackframes=64 | ||
#pragma D option strsize=2048 | ||
|
||
profile-997 | ||
/pid == $target/ | ||
{ | ||
@num[ustack()] = count(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/sbin/dtrace -s | ||
#pragma D option quiet | ||
#pragma D option dynvarsize=64m | ||
|
||
dtrace:::BEGIN | ||
{ | ||
printf("Tracing... Hit Ctrl-C to end.\n"); | ||
depth = 0; | ||
} | ||
|
||
|
||
profile-997 | ||
{ | ||
@kernel[stack(20)]=count(); | ||
} | ||
|
||
|
||
|
||
profile-997 | ||
/arg1/ /* user level PC. Make sure that we are in user space */ | ||
{ | ||
printf("%d\n", arg1); | ||
@userspace[execname, ustack(10)]=count(); | ||
} | ||
|
||
END { | ||
trunc(@kernel, 10); | ||
trunc(@userspace, 10); | ||
|
||
printf("%s", "\n =========== Top 10 Busiest Kernel Path =============\n"); | ||
printa(@kernel); | ||
|
||
printf("%s", "\n =========== Top 10 Busiest User Path =============\n"); | ||
printa(@userspace); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
examples/dtrace/custom_dtrace_instumentation_using_usdt_probes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env ruby -w | ||
# | ||
# Define how you can create custom DTrace probes on the fly from | ||
# Ruby program using the ruby-dtrace gem (USDT provider). | ||
# | ||
# Trace all flight search probes with: | ||
# | ||
# sudo dtrace -n 'find-available-flights { printf("%s", copyinstr(arg0)); }' | ||
# | ||
# Trace all the flight booking probes with: | ||
# | ||
# sudo dtrace -n 'book { printf("%s %d", copyinstr(arg0), arg1); }' | ||
# | ||
require 'rubygems' | ||
gem "ruby-dtrace" | ||
require 'dtrace/provider' | ||
|
||
# | ||
# Define custom DTrace USDT probes on the fly using ruby-dtrace | ||
# native extensions. | ||
# | ||
|
||
Dtrace::Provider.create :booking_engine do |p| | ||
p.probe :boot | ||
p.probe :find_available_flights, :string | ||
p.probe :book, :string, :integer | ||
end | ||
|
||
# | ||
# Use these custom probes in your application | ||
# | ||
|
||
|
||
class BookingEngine | ||
|
||
def find_available_flights(destination) | ||
Dtrace::Probe::BookingEngine.find_available_flights do |p| | ||
p.fire(destination) | ||
end | ||
sleep 1 # Some business logic ;-) | ||
["AF98", "JB24"] | ||
end | ||
|
||
def book(flight_number, number_of_seats) | ||
Dtrace::Probe::BookingEngine.book do |p| | ||
p.fire(flight_number, number_of_seats) | ||
end | ||
sleep 3 # Very slow business logic | ||
end | ||
|
||
def book_all_available_flights | ||
find_available_flights("SFO").collect do |flight_number| | ||
book flight_number, rand(10) | ||
end | ||
end | ||
|
||
end | ||
|
||
class Application | ||
|
||
def self.boot | ||
# Fire a custom DTrace probe without a block (no start/end concept) | ||
Dtrace::Probe::BookingEngine.boot do |p| | ||
p.fire | ||
end | ||
|
||
booking_engine = BookingEngine.new | ||
loop do | ||
booking_engine.book_all_available_flights | ||
end | ||
end | ||
|
||
end | ||
|
||
Application.boot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env ruby -w | ||
# | ||
# Simple Ruby script simulating a flight booking engine | ||
# before we add any custon DTrace instrumentation | ||
# | ||
class BookingEngine | ||
|
||
def find_available_flights(destination) | ||
sleep 1 # Some business logic ;-) | ||
["AF98", "JB24"] | ||
end | ||
|
||
def book(flight_number, number_of_seats) | ||
sleep 3 # Very slow business logic | ||
end | ||
|
||
def book_all_available_flights | ||
book flight_number, rand(10) | ||
end | ||
|
||
end | ||
|
||
class Application | ||
|
||
def self.boot | ||
booking_engine = BookingEngine.new | ||
loop do | ||
booking_engine.book_all_available_flights | ||
end | ||
end | ||
|
||
end | ||
|
||
Application.boot |
52 changes: 52 additions & 0 deletions
52
examples/dtrace/simple_ruby_script_with_tracer_custom_dtrace_instrumentation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env ruby -w | ||
# | ||
# Simple Ruby script demonstrating use of Tracer to install custom | ||
# (application specific) Dtrace probes. | ||
# | ||
# Run the script, then watch your customn probes fire in another terminal with: | ||
# | ||
# sudo dtrace -n'ruby-probe { printf("%s %s", copyinstr(arg0), copyinstr(arg1)); }' | ||
# | ||
require "rubygems" | ||
require "xray/dtrace/tracer" | ||
|
||
class BookingEngine | ||
include XRay::DTrace::Tracer | ||
|
||
def find_available_flights(destination) | ||
firing "find_available_flights", destination do | ||
sleep 1 # Some business logic ;-) | ||
["AF98", "JB24"] | ||
end | ||
end | ||
|
||
def book(flight_number) | ||
firing "book", flight_number do | ||
sleep 3 # Very slow business logic | ||
end | ||
end | ||
|
||
def book_all_available_flights | ||
find_available_flights("SFO").collect do |flight_number| | ||
book flight_number | ||
end | ||
end | ||
|
||
end | ||
|
||
class Application | ||
extend DTracer | ||
|
||
def self.boot | ||
# Fire a custom DTrace probe without a block (no start/end concept) | ||
fire "boot", Process.pid.to_s | ||
|
||
booking_engine = BookingEngine.new | ||
loop do | ||
booking_engine.book_all_available_flights | ||
end | ||
end | ||
|
||
end | ||
|
||
Application.boot |