Permalink
Browse files

Merge branch 'master' of git://github.com/rdp/ruby-prof

Conflicts:
	CHANGES
	ext/ruby_prof/measure_process_time.h
	lib/ruby-prof.rb
	ruby-prof.gemspec
  • Loading branch information...
goncalossilva committed May 10, 2011
2 parents ea8c77d + 83cc0b6 commit ae2c5ef90981d9f37cd90c9ea1df7655fc3f8be1
View
28 CHANGES
@@ -1,5 +1,28 @@
-<<<<<<< HEAD
-=======
+0.10.5
+=======================
+1.8.6 compat for -v command (bug fix)
+
+0.10.4
+=======================
+Faster load time for ruby-prof itself.
+
+0.10.3
+=======================
+Can cleanly load before rubygems now.
+
+0.10.2
+=======================
+Fix for 1.9.2, os x for latest commits (thanks skaes!)
+
+0.10.1
+=======================
+Fix bug in linux wall time, also load with only relative paths so that you can use it to benchmark rubygems startup overhead,
+itself.
+
+0.10.0
+=======================
+Some rdoc changes, for linux wall time attempt to use higher granularity (thanks to all the contributors for this round!)
+
0.9.2
=======================
Make graphviz work on 1.8.6
@@ -9,7 +32,6 @@ roll back some 1.9.2 optimizations until I can figure out what caused them.
=======================
Add a graphviz output
->>>>>>> 31a7a37051007c8019fe1882d73e16275c2766b8
0.9.0
=======================
* measurements for recursive methods are now correct
View
@@ -12,7 +12,6 @@ ruby-prof is a fast code profiler for Ruby. Its features include:
- Call tree profiles - outputs results in the calltree format suitable for the KCacheGrind profiling tool.
* Threads - supports profiling multiple threads simultaneously
-
== Requirements
ruby-prof requires Ruby 1.8.4 or higher.
@@ -21,7 +20,7 @@ If you are running Linux or Unix you'll need a C compiler so the extension
can be compiled when it is installed.
If you are running Windows, then you may need to install the
-Windows specific RubyGem which includes an already built extension (see below).
+Windows specific RubyGem which includes an already built extension (see Install section).
== Install
@@ -30,11 +29,11 @@ The easiest way to install ruby-prof is by using Ruby Gems. To install:
gem install ruby-prof
If you on windows mswin [not mingw] (check via ruby -v) and
-don't have an MSVC compiler, please install v0.7.3 which
+don't have an MSVC compiler, please install v0.8.1 which
has a prebuilt binary
-C:> gem install ruby-prof -v0.7.3
+C:> gem install ruby-prof -v0.8.1
-If you're on mingw, please install the devkit first, then install the latest version (gem install ruby-prof).
+If you're on mingw, please install the devkit first, then install the latest gem version (via gem install ruby-prof).
== Usage
@@ -79,7 +78,7 @@ to profile:
# Print a graph profile to text
printer = RubyProf::GraphPrinter.new(result)
- printer.print(STDOUT, 0)
+ printer.print(STDOUT, {})
Starting with the 0.6.1 release, ruby-prof also supports pausing and resuming
profiling runs.
@@ -110,18 +109,14 @@ has not yet started. In addition, resume can also take a block:
With this usage, resume will automatically call pause at the
end of the block.
-
=== require unprof
The third way of using ruby-prof is by requiring unprof.rb:
require 'unprof'
-This will start profiling immediately and will output the results
-using a flat profile report.
-
-This method is provided for backwards compatibility. Using the
-ruby-prof command provides more flexibility.
+This will start profiling immediately at that point and will output the results
+using a flat profile report when the process ends.
== Method Elimination
@@ -145,6 +140,22 @@ the name of a file containing a list of regular expressions (line separated text
After eliminating methods the resulting profile will appear exactly as if those methods
had been inlined at their call sites.
+== Benchmarking full load time including rubygems startup cost ==
+
+If you want to get a more accurate measurement of what takes all of a gem's bin/xxx
+command to load, you may want to also measure rubygems' startup penalty.
+You can do this by calling into bin/ruby-prof directly, ex:
+
+$ gem which ruby-prof
+ g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/lib/ruby-prof.rb
+
+now run it thus (substitute lib/ruby-prof.rb with bin/ruby-prof):
+
+$ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof g:\192\bin\some_installed_gem_command
+
+or
+
+$ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof ./some_file_that_does_a_require_rubygems_at_the_beginning.rb
== Profiling Tests
@@ -230,6 +241,7 @@ ruby-prof can generate a number of different reports:
* HTML Graph Reports
* Call graphs
* Call stack reports
+* More!
Flat profiles show the overall time spent in each method. They
are a good of quickly identifying which methods take the most time.
@@ -276,6 +288,7 @@ Reports are created by printers. Supported printers include:
* RubyProf::CallTreePrinter - Creates a call tree report compatible with KCachegrind.
* RubyProf::CallStackPrinter - Creates a HTML visualization of the Ruby stack
* RubyProf::MultiPrinter - Uses the other printers to create several reports in one profiling run
+* More!
To use a printer:
@@ -427,7 +440,8 @@ profiled. Most programs will run approximately twice as slow
while highly recursive programs (like the fibonacci series test)
will run three times slower.
-Because of some threading difficulties in 1.9, it currently runs a bit slower there.
+Because of some threading difficulties in 1.9, it currently runs a
+bit slower there, as well.
http://www.ruby-forum.com/topic/201329
== License
@@ -437,3 +451,5 @@ See LICENSE for license information.
== Development
Code is located at http://github.com/rdp/ruby-prof
+
+Google group/mailing list: http://groups.google.com/group/ruby-prof
View
@@ -4,71 +4,17 @@ require 'rake/rdoctask'
require 'rake/testtask'
require 'date'
-# ------- Version ----
-# Read version from header file
-version_header = File.read('ext/ruby_prof/version.h')
-match = version_header.match(/RUBY_PROF_VERSION\s*["](\d.+)["]/)
-raise(RuntimeError, "Could not determine RUBY_PROF_VERSION") if not match
-RUBY_PROF_VERSION = match[1]
+# to release a version of ruby-prof, do a git tag, then rake cleanr default and publish that
+# git tag 0.10.1
+# git push origin 0.10.1
+# rake cleanr default
+# gem push pkg/ruby-prof-0.10.1.gem
+default_spec = eval File.read(File.expand_path('../ruby-prof.gemspec', __FILE__))
-# ------- Default Package ----------
-FILES = FileList[
- 'Rakefile',
- 'README.rdoc',
- 'LICENSE',
- 'CHANGES',
- 'bin/*',
- 'doc/**/*',
- 'examples/*',
- 'ext/ruby_prof/*.c',
- 'ext/ruby_prof/*.h',
- 'ext/ruby_prof/mingw/Rakefile',
- 'ext/ruby_prof/mingw/build.rake',
- 'ext/vc/*.sln',
- 'ext/vc/*.vcproj',
- 'lib/**/*',
- 'rails/**/*',
- 'test/*'
-]
-
-# Default GEM Specification
-default_spec = Gem::Specification.new do |spec|
- spec.name = "ruby-prof"
-
- spec.homepage = "http://rubyforge.org/projects/ruby-prof/"
- spec.summary = "Fast Ruby profiler"
- spec.description = <<-EOF
-ruby-prof is a fast code profiler for Ruby. It is a C extension and
-therefore is many times faster than the standard Ruby profiler. It
-supports both flat and graph profiles. For each method, graph profiles
-show how long the method ran, which methods called it and which
-methods it called. RubyProf generate both text and html and can output
-it to standard out or to a file.
-EOF
-
- spec.version = RUBY_PROF_VERSION
-
- spec.author = "Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes"
- spec.email = "shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de"
- spec.platform = Gem::Platform::RUBY
- spec.require_path = "lib"
- spec.bindir = "bin"
- spec.executables = ["ruby-prof"]
- spec.extensions = ["ext/ruby_prof/extconf.rb"]
- spec.files = FILES.to_a
- spec.test_files = Dir["test/test_*.rb"]
- spec.required_ruby_version = '>= 1.8.4'
- spec.date = DateTime.now
- spec.rubyforge_project = 'ruby-prof'
- spec.add_development_dependency 'os'
- spec.add_development_dependency 'rake-compiler'
-
-end
-
-
-desc 'build native .gem files -- use like "native_gems clobber cross native gem"--for non native gem creation use "native_gems clobber" then "clean gem"'
+desc 'deprecated--build native .gem files -- use like "native_gems clobber cross native gem"--for non native gem creation use "native_gems clobber" then "clean gem"'
task :native_gems do
+ # we don't do cross compiler anymore, now that mingw has devkit
ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
require 'rake/extensiontask'
Rake::ExtensionTask.new('ruby_prof', default_spec) do |ext|
@@ -125,16 +71,15 @@ task :build do
system(Gem.ruby + " extconf.rb")
system("make clean")
end
- system("make")
+ raise 'make failed' unless system("make")
FileUtils.cp 'ruby_prof.so', '../../lib' if File.exist? 'lib/ruby_prof.so'
FileUtils.cp 'ruby_prof.bundle', '../../lib' if File.exist? 'lib/ruby_prof.bundle'
end
end
desc 'clean stuff'
task :cleanr do
- FileUtils.rm 'lib/ruby_prof.so' if File.exist? 'lib/ruby_prof.so'
- FileUtils.rm 'lib/ruby_prof.bundle' if File.exist? 'lib/ruby_prof.bundle'
+ Dir['**/*.{so,bundle}'].each{|f| File.delete f}
Dir.chdir('ext/ruby_prof') do
if File.exist? 'Makefile'
system("make clean")
View
@@ -8,46 +8,14 @@
#
# ruby_prof [options] <script.rb> [--] [script-options]"
#
-# Options:
-# -p, --printer=printer Select a printer:
-# flat - Prints a flat profile as text (default).
-# flat_with_line_numbers - Above, with line numbers
-# graph - Prints a graph profile as text.
-# graph_html - Prints a graph profile as html.
-# call_tree - format for KCacheGrind
-# call_stack - prints a HTML visualization of the call tree
-# dot - Prints a graph profile as a dot file
-# -f, --file=path Output results to a file instead of standard out.
-# -m, --min_percent=min_percent The minimum percent a method must take before ',
-# being included in output reports. Should be an
-# integer between 1 and 100. 0 means all methods are printed.
-# --mode=measure_mode Select a measurement mode:
-# process - Use process time (default).
-# wall - Use wall time.
-# cpu - Use the CPU clock counter
-# (only supported on Pentium and PowerPCs).
-# allocations - Tracks object allocations
-# (requires a patched Ruby interpreter).
-# memory - Tracks total memory size
-# (requires a patched Ruby interpreter).
-# gc_runs - Tracks number of garbage collection runs
-# (requires a patched Ruby interpreter).
-# gc_time - Tracks time spent doing garbage collection
-# (requires a patched Ruby interpreter).
-# --replace-progname Replace $0 when loading the .rb files.
-# --specialized-instruction Turn on specialized instruction.
-# -h, --help Show help message
-# --version Show version
-# -v Show version, set $VERBOSE to true, run file
-# -d Set $DEBUG to true
-#
+# Various options:
+# run "$ ruby-prof --help" to see them
#
# See also: {flat profiles}[link:files/examples/flat_txt.html], {graph profiles}[link:files/examples/graph_txt.html], {html graph profiles}[link:files/examples/graph_html.html]
-#
require 'ostruct'
require 'optparse'
-require 'ruby-prof'
+require File.dirname(__FILE__) + "/../lib/ruby-prof"
options = OpenStruct.new
options.measure_mode = RubyProf::PROCESS_TIME
@@ -59,7 +27,7 @@ options.specialized_instruction = false
opts = OptionParser.new do |opts|
opts.banner = "ruby_prof #{RubyProf::VERSION}\n" +
- "Usage: ruby_prof [options] <script.rb> [--] [script-options]"
+ "Usage: ruby-prof [options] <script.rb> [--] [profiled-script-command-line-options]"
opts.separator ""
opts.separator "Options:"
@@ -157,15 +125,34 @@ opts = OptionParser.new do |opts|
exit
end
- opts.on("-v","Show version, set $VERBOSE to true, profile script") do
- puts "ruby_prof " + RubyProf::VERSION
- puts "ruby " + RUBY_DESCRIPTION
- $VERBOSE= true
+ opts.on("-v","Show version, set $VERBOSE to true, profile script if option given") do
+ puts "ruby version: " + [RUBY_PATCHLEVEL, RUBY_PLATFORM, RUBY_VERSION].join(' ')
+ $VERBOSE = true
end
opts.on("-d", "Set $DEBUG to true") do
$DEBUG = true
end
+
+ opts.on('-R lib', '--require-noprof lib', 'require a specific library (not profiled)') do |lib|
+ options.pre_libs ||= []
+ options.pre_libs << lib
+ end
+
+ opts.on('-E code', '--eval-noprof code', 'execute the ruby statements (not profiled)') do |code|
+ options.pre_exec ||= []
+ options.pre_exec << code
+ end
+
+ opts.on('-r lib', '--require lib', 'require a specific library') do |lib|
+ options.libs ||= []
+ options.libs << lib
+ end
+
+ opts.on('-e code', '--eval', 'execute the ruby statements') do |code|
+ options.exec ||= []
+ options.exec << code
+ end
end
begin
@@ -179,7 +166,7 @@ rescue OptionParser::InvalidOption, OptionParser::InvalidArgument,
end
# Make sure the user specified at least one file
-if ARGV.length < 1
+if ARGV.length < 1 and not options.exec
puts opts
puts ""
puts "Must specify a script to run"
@@ -229,8 +216,28 @@ if options.replace_prog_name
$0 = File.expand_path(script)
end
+if options.pre_libs
+ options.pre_libs.each { |l| require l }
+end
+
+if options.pre_exec
+ options.pre_exec.each { |c| eval c }
+end
+
+# do not pollute profiling report with OpenStruct#libs
+ol = options.libs
+oe = options.exec
+
# Start profiling
RubyProf.start
+if ol
+ ol.each { |l| require l }
+end
+
+if oe
+ oe.each { |c| eval c }
+end
+
# Load the script
-load script
+load script if script
Oops, something went wrong.

0 comments on commit ae2c5ef

Please sign in to comment.