Skip to content
Browse files

Initial calls strategy + cleanups

  • Loading branch information...
1 parent caabd86 commit e7bea4f09d167579218a6f2e3f7956b4088a0acd @methodmissing committed
View
1 lib/instrumentation.rb
@@ -23,6 +23,7 @@ module Strategy
autoload :Calltime, 'mri/instrumentation/strategy/calltime'
autoload :Interval, 'mri/instrumentation/strategy/interval'
autoload :Flow, 'mri/instrumentation/strategy/flow'
+ autoload :Calls, 'mri/instrumentation/strategy/calls'
end
View
6 lib/mri/instrumentation/probe.rb
@@ -31,6 +31,12 @@ def argument_size
def length
@length ||= self.name.size
end
+
+ # Function declaration
+ #
+ def function
+ @function ||= "pid$target*:::#{self.name}"
+ end
# Entry declaration
#
View
17 lib/mri/instrumentation/strategy/base.rb
@@ -39,6 +39,15 @@ def entry( contents = '' )
}\n ]
end
+ # Probe function definition
+ #
+ def function( contents = '' )
+ %[ #{@probe.function}
+ {
+ #{contents}
+ }\n ]
+ end
+
# Any predicate conditions
#
def predicate
@@ -73,6 +82,14 @@ def build
#{report} ]
end
+ # The function definitions to build out
+ #
+ def functions
+ fncs = [:entry]
+ fncs << :return unless void?
+ fncs
+ end
+
# Respect methods on the probe collection first, then cascade down to the
# current probe definition if any.
#
View
5 lib/mri/instrumentation/strategy/builder.rb
@@ -37,8 +37,9 @@ def build
def build_each( buf = '' )
@probes.each do |probe|
strategy_instance = strategy.new( probe, @probes )
- @buffer << strategy_instance.entry
- @buffer << strategy_instance.return unless strategy_instance.void?
+ strategy_instance.functions.each do |func|
+ @buffer << strategy_instance.send(func)
+ end
end
end
View
27 lib/mri/instrumentation/strategy/calls.rb
@@ -0,0 +1,27 @@
+module Mri
+ module Instrumentation
+ module Strategy
+ class Calls < Base
+
+ def setup
+ super %[ printf("Tracing... Hit Ctrl-C to end.\\n");\n ]
+ end
+
+ def function
+ super %[ #{assign_arguments}
+ @calls[#{arguments_list( arguments_size )}] = count(); ]
+ end
+
+ def functions
+ [:function]
+ end
+
+ def report
+ super %[ printf(" #{header_format}\\n", #{report_header}, "CALLS");
+ printa(" #{report_format}\\n", @calls); ]
+ end
+
+ end
+ end
+ end
+end
View
8 lib/mri/instrumentation/strategy/calltime.rb
@@ -3,11 +3,11 @@ module Instrumentation
module Strategy
class Calltime < Base
- def setup( contents = '' )
+ def setup
super %[ printf("Tracing... Hit Ctrl-C to end.\\n");\n ]
end
- def entry( contents = '' )
+ def entry
super %[ self->depth++;
self->exclude[self->depth] = 0;
#{assign_arguments}
@@ -20,7 +20,7 @@ def predicate
"/self->#{name}[self->depth]/"
end
- def return( contents = '' )
+ def return
super %[ this->elapsed_incl = timestamp - self->#{name}[self->depth];
this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];
self->#{name}[self->depth] = 0;
@@ -33,7 +33,7 @@ def return( contents = '' )
self->exclude[self->depth] += this->elapsed_incl; ]
end
- def report( contents = '' )
+ def report
super %[ printf("\\nCount,\\n");
printf(" #{header_format}\\n", #{report_header}, "COUNT");
printa(" #{report_format}\\n", @num);
View
4 test/instrumentation/probe_test.rb
@@ -35,6 +35,10 @@ def setup
assert_equal 'pid$target::ruby_xrealloc:return', @probe.function_return
end
+ test "should be able to yield a function name" do
+ assert_equal 'pid$target*:::ruby_xrealloc', @probe.function
+ end
+
test "should be able to yield an arguments list" do
assert_equal 'this->type, this->arg0, this->arg1', @probe.arguments_list
assert_equal "this->type, this->arg0, this->arg1, \"\", \"\"", @probe.arguments_list( 5 )
View
4 test/instrumentation/strategy/base_test.rb
@@ -11,6 +11,10 @@ def setup
assert_equal 'pid$target::ruby_xrealloc:return', @strategy.function_return
end
+ test "should be able to yield function definitions to build" do
+ assert_equal [:entry, :return], @strategy.functions
+ end
+
test "should be able to yield a header" do
assert_match /pragma/, @strategy.header
end
View
28 test/instrumentation/strategy/calls_test.rb
@@ -0,0 +1,28 @@
+require File.join( File.dirname( __FILE__ ), '..', '..', 'helper' )
+
+class CallsStrategyTest < Test::Unit::TestCase
+
+ def setup
+ @probe = Mri::Instrumentation::Test.probe
+ @probes = Mri::Instrumentation.probes( Mri::Instrumentation::Test::PROBES )
+ @probe_collection = Mri::Instrumentation::ProbeCollection.new( @probes )
+ @strategy = Mri::Instrumentation::Strategy::Calls.new( @probe, @probe_collection )
+ end
+
+ test "should be able to yield a header" do
+ assert_equal " #!/usr/sbin/dtrace -Zs \n #pragma D option quiet\n\n #pragma D option dynvarsize=64m\n\n \n ", @strategy.header
+ end
+
+ test "should be able to yield a setup function" do
+ assert_equal " dtrace:::BEGIN\n { \n printf(\"Tracing... Hit Ctrl-C to end.\\n\");\n \n }\n ", @strategy.setup
+ end
+
+ test "should be able to yield a function definition" do
+ assert_equal " pid$target*:::ruby_xrealloc\n {\n this->type = probefunc;\nthis->arg0 = arg0;\nthis->arg1 = stringof( arg1 );\n @calls[this->type, this->arg0, this->arg1] = count(); \n }\n ", @strategy.function
+ end
+
+ test "should be able to yield a report" do
+ assert_equal " dtrace:::END\n {\n printf(\" %-24s %-24s %20s\\n\", \"Probe\", \"arg0\", \"CALLS\");\n \t printa(\" %-24s %-24s %@20d\\n\", @calls); \n }\n ", @strategy.report
+ end
+
+end
View
7 test/instrumentation/strategy/calltime_test.rb
@@ -10,27 +10,22 @@ def setup
end
test "should be able to yield a header" do
- assert_match /pragma/, @strategy.header
assert_equal " #!/usr/sbin/dtrace -Zs \n #pragma D option quiet\n\n #pragma D option dynvarsize=64m\n\n \n ", @strategy.header
end
test "should be able to yield a setup function" do
- assert_match /BEGIN/, @strategy.setup
assert_equal " dtrace:::BEGIN\n { \n printf(\"Tracing... Hit Ctrl-C to end.\\n\");\n \n }\n ", @strategy.setup
end
test "should be able to yield a function entry definition" do
- assert_match /ruby_xrealloc:entry/, @strategy.entry
assert_equal " pid$target::ruby_xrealloc:entry\n {\n self->depth++;\n \t self->exclude[self->depth] = 0;\n \t this->type = probefunc;\nthis->arg0 = arg0;\nthis->arg1 = stringof( arg1 );\n \t @num[this->type, this->arg0, this->arg1] = count();\n \t self->ruby_xrealloc[self->depth] = timestamp; \n }\n ", @strategy.entry
end
- test "should be able to yield a function return definition" do
- assert_match /ruby_xrealloc:return/, @strategy.return
+ test "should be able to yield a function return definition" do
assert_equal " pid$target::ruby_xrealloc:return\n /self->ruby_xrealloc[self->depth]/\n {\n \t this->elapsed_incl = timestamp - self->ruby_xrealloc[self->depth];\n this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];\n \t self->ruby_xrealloc[self->depth] = 0;\n \t self->exclude[self->depth] = 0;\n \t this->type = probefunc;\nthis->arg0 = arg0;\nthis->arg1 = stringof( arg1 );\n \t @types_incl[this->type, this->arg0, this->arg1] = sum(this->elapsed_incl);\n \t @types_excl[this->type, this->arg0, this->arg1] = sum(this->elapsed_excl);\n\n \t self->depth--;\n \t self->exclude[self->depth] += this->elapsed_incl; \n }\n ", @strategy.return
end
test "should be able to yield a reporting function" do
- assert_match /END/, @strategy.report
assert_equal " dtrace:::END\n {\n printf(\"\\nCount,\\n\");\n printf(\" %-24s %-24s %20s\\n\", \"Probe\", \"arg0\", \"COUNT\");\n \t printa(\" %-24s %-24s %@20d\\n\", @num);\n normalize(@types_excl, 1000);\n \t printf(\"\\nExclusive function elapsed times (us),\\n\");\n \t printf(\" %-24s %-24s %20s\\n\", \"Probe\", \"arg0\", \"TOTAL\");\n \t printa(\" %-24s %-24s %@20d\\n\", @types_excl);\n\n \t normalize(@types_incl, 1000);\n \t printf(\"\\nInclusive function elapsed times (us),\\n\");\n \t printf(\" %-24s %-24s %20s\\n\", \"Probe\", \"arg0\", \"TOTAL\");\n \t printa(\" %-24s %-24s %@20d\\n\", @types_incl); \n }\n ", @strategy.report
end

0 comments on commit e7bea4f

Please sign in to comment.
Something went wrong with that request. Please try again.