Permalink
Browse files

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

Conflicts:
	test/printers_test.rb
  • Loading branch information...
2 parents 822879b + 6bed197 commit dc2d7ecb28c5aa83a86c75904cb335021ab9052e @goncalossilva goncalossilva committed Oct 30, 2011
Showing with 402 additions and 256 deletions.
  1. +8 −0 CHANGES
  2. +7 −1 README.rdoc
  3. +47 −54 Rakefile
  4. +24 −4 bin/ruby-prof
  5. +3 −0 ext/ruby_prof/extconf.rb
  6. +0 −23 ext/ruby_prof/mingw/Rakefile
  7. +0 −38 ext/ruby_prof/mingw/build.rake
  8. +18 −10 ext/ruby_prof/ruby_prof.c
  9. +3 −0 ext/ruby_prof/vc/ruby_prof.def
  10. +7 −6 ext/ruby_prof/vc/ruby_prof.vcxproj
  11. +3 −3 ext/ruby_prof/version.h
  12. +11 −9 lib/ruby-prof.rb
  13. +10 −0 lib/ruby-prof/abstract_printer.rb
  14. +2 −0 lib/ruby-prof/aggregate_call_info.rb
  15. +2 −0 lib/ruby-prof/call_info.rb
  16. +3 −5 lib/ruby-prof/call_stack_printer.rb
  17. +1 −0 lib/ruby-prof/call_tree_printer.rb
  18. +4 −4 lib/ruby-prof/dot_printer.rb
  19. +6 −6 lib/ruby-prof/flat_printer.rb
  20. +2 −5 lib/ruby-prof/flat_printer_with_line_numbers.rb
  21. +4 −2 lib/ruby-prof/graph_html_printer.rb
  22. +2 −1 lib/ruby-prof/graph_printer.rb
  23. +2 −0 lib/ruby-prof/method_info.rb
  24. +2 −0 lib/ruby-prof/multi_printer.rb
  25. +1 −0 lib/ruby-prof/rack.rb
  26. +2 −0 lib/ruby-prof/result.rb
  27. +2 −0 lib/ruby-prof/symbol_to_proc.rb
  28. +1 −0 lib/ruby-prof/task.rb
  29. +2 −0 lib/ruby-prof/test.rb
  30. +2 −0 lib/unprof.rb
  31. +2 −2 test/aggregate_test.rb
  32. +2 −2 test/basic_test.rb
  33. +2 −2 test/duplicate_names_test.rb
  34. +2 −2 test/enumerable_test.rb
  35. +3 −2 test/exceptions_test.rb
  36. +2 −2 test/exclude_threads_test.rb
  37. +2 −2 test/exec_test.rb
  38. +8 −7 test/line_number_test.rb
  39. +17 −6 test/measurement_test.rb
  40. +2 −2 test/method_elimination_test.rb
  41. +3 −2 test/module_test.rb
  42. +2 −2 test/multi_printer_test.rb
  43. +3 −1 test/no_method_class_test.rb
  44. +3 −3 test/prime_test.rb
  45. +109 −6 test/printers_test.rb
  46. +3 −2 test/recursive_test.rb
  47. +2 −2 test/singleton_test.rb
  48. +3 −3 test/stack_printer_test.rb
  49. +2 −2 test/stack_test.rb
  50. +2 −2 test/start_stop_test.rb
  51. +14 −0 test/test_helper.rb
  52. +27 −26 test/test_suite.rb
  53. +4 −3 test/thread_test.rb
  54. +2 −2 test/unique_call_path_test.rb
View
@@ -1,3 +1,11 @@
+0.10.7
+======================
+Fix a bug with REE's GC stats. Issue #53 [thanks graaff]
+
+0.10.6
+======================
+Slightly more normalized url for linux/windows links to files.
+
0.10.5
=======================
1.8.6 compat for -v command (bug fix)
View
@@ -10,6 +10,7 @@ ruby-prof is a fast code profiler for Ruby. Its features include:
- Flat Profiles - similar to the reports generated by the standard Ruby profiler
- Graph profiles - similar to GProf, these show how long a method runs, which methods call it and which methods it calls.
- Call tree profiles - outputs results in the calltree format suitable for the KCacheGrind profiling tool.
+ - Many more -- see reports section of this README.
* Threads - supports profiling multiple threads simultaneously
== Requirements
@@ -248,6 +249,8 @@ are a good of quickly identifying which methods take the most time.
An example of a flat profile and an explanation can be found in
{examples/flat.txt}[http://github.com/rdp/ruby-prof/tree/master/examples/flat.txt].
+There are several varieties of these -- run $ ruby-prof --help
+
Graph profiles also show the overall time spent in each method. In
addition, they also show which methods call the current method and which
methods its calls. Thus they are good for understanding how methods
@@ -271,10 +274,13 @@ Call stack reports produce a HTML visualization of the time spent in
each execution path of the profiled code. An example can be found at
{examples/stack.html}[http://github.com/rdp/ruby-prof/tree/master/examples/call_stack.html].
+Another good example: [http://twitpic.com/28z94a]
+
Finally, there's a so called MultiPrinter which can generate several
reports in one profiling run. See
{examples/multi.stack.html}[http://github.com/rdp/ruby-prof/tree/master/examples/multi.stack.html].
+There is also a graphviz .dot visualiser.
== Printers
@@ -452,4 +458,4 @@ See LICENSE for license information.
Code is located at http://github.com/rdp/ruby-prof
-Google group/mailing list: http://groups.google.com/group/ruby-prof
+Google group/mailing list: http://groups.google.com/group/ruby-optimization
View
101 Rakefile
@@ -1,38 +1,61 @@
-require 'rubygems'
-require 'rake/gempackagetask'
-require 'rake/rdoctask'
-require 'rake/testtask'
-require 'date'
+# encoding: utf-8
-# 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
+require "rubygems/package_task"
+require "rake/extensiontask"
+require "rake/testtask"
+require "rdoc/task"
+require "date"
-default_spec = eval File.read(File.expand_path('../ruby-prof.gemspec', __FILE__))
+# To release a version of ruby-prof:
+# * Update version.h
+# * Update CHANGES
+# * Update rdocs
+# * git commit to commit files
+# * rake clobber to remove extra files
+# * rake compile to build windows gems
+# * rake package to create the gems
+# * Tag the release in git (tag 0.10.1)
+# * Push to ruybgems.org (gem push pkg/<gem files>)
-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|
- ext.cross_compile = true
- ext.cross_platform = ['x86-mswin32-60', 'x86-mingw32-60']
- end
+GEM_NAME = 'ruby-prof'
+SO_NAME = 'ruby_prof'
+
+default_spec = Gem::Specification.load("#{GEM_NAME}.gemspec")
+
+Rake::ExtensionTask.new do |ext|
+ ext.gem_spec = default_spec
+ ext.name = SO_NAME
+ ext.ext_dir = "ext/#{SO_NAME}"
+ ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d$/, '')}"
+ ext.cross_compile = true
+ ext.cross_platform = ['x86-mswin32-60', 'x86-mingw32-60']
end
# Rake task to build the default package
-Rake::GemPackageTask.new(default_spec) do |pkg|
+Gem::PackageTask.new(default_spec) do |pkg|
pkg.need_tar = true
- #pkg.need_zip = true
end
+# Setup Windows Gem
+if RUBY_PLATFORM.match(/win32|mingw32/)
+ # Windows specification
+ win_spec = default_spec.clone
+ win_spec.platform = Gem::Platform::CURRENT
+ win_spec.files += Dir.glob('lib/**/*.so')
+ win_spec.instance_variable_set(:@cache_file, nil) # Hack to work arond gem issue
+
+ # Unset extensions
+ win_spec.extensions = nil
+
+ # Rake task to build the windows package
+ Gem::PackageTask.new(win_spec) do |pkg|
+ pkg.need_tar = false
+ end
+end
# --------- RDoc Documentation ------
desc "Generate rdoc documentation"
-Rake::RDocTask.new("rdoc") do |rdoc|
+RDoc::Task.new("rdoc") do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = "ruby-prof"
# Show source inline with line numbers
@@ -60,34 +83,4 @@ Rake::TestTask.new do |t|
t.test_files = Dir['test/test_suite.rb']
t.verbose = true
t.warning = true
-end
-
-require 'fileutils'
-
-desc 'Build ruby_prof.so'
-task :build do
- Dir.chdir('ext/ruby_prof') do
- unless File.exist? 'Makefile'
- system(Gem.ruby + " extconf.rb")
- system("make clean")
- end
- 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
- Dir['**/*.{so,bundle}'].each{|f| File.delete f}
- Dir.chdir('ext/ruby_prof') do
- if File.exist? 'Makefile'
- system("make clean")
- FileUtils.rm 'Makefile'
- end
- Dir.glob('*~') do |file|
- FileUtils.rm file
- end
- end
- system("rm -rf pkg")
-end
+end
View
@@ -11,7 +11,7 @@
# 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]
+# See also the readme "reports" section for the various outputs
require 'ostruct'
require 'optparse'
@@ -104,7 +104,26 @@ opts = OptionParser.new do |opts|
options.measure_mode = RubyProf::GC_TIME
end
end
-
+
+ opts.on('-s sort_mode', '--sort=sort_mode', [:total, :self, :wait, :child],
+ 'Select how ruby-prof results should be sorted:',
+ ' total - Total time',
+ ' self - Self time',
+ ' wait - Wait time',
+ ' child - Child time') do |sort_mode|
+
+ options.sort_method = case sort_mode
+ when :total
+ :total_time
+ when :self
+ :self_time
+ when :wait
+ :wait_time
+ when :child
+ :children_time
+ end
+ end
+
opts.on("--replace-progname", "Replace $0 when loading the .rb files.") do
options.replace_prog_name = true
end
@@ -184,18 +203,19 @@ at_exit {
# Create a printer
printer = options.printer.new(result)
+ printer_options = {:min_percent => options.min_percent, :sort_method => options.sort_method}
# Get output
if options.file
# write it relative to the dir they *started* in, as it's a bit surprising to write it in the dir they end up in.
Dir.chdir(options.old_wd) do
File.open(options.file, 'w') do |file|
- printer.print(file, {:min_percent => options.min_percent})
+ printer.print(file, printer_options)
end
end
else
# Print out results
- printer.print(STDOUT, {:min_percent => options.min_percent})
+ printer.print(STDOUT, printer_options)
end
}
View
@@ -18,6 +18,9 @@
have_func("rb_gc_collections")
have_func("rb_gc_time")
+# 1.9.3 superclass
+have_func("rb_class_superclass")
+
# Lloyd Hilaiel's heap info patch
have_func("rb_heap_total_mem")
have_func("rb_gc_heap_info")
@@ -1,23 +0,0 @@
-# We can't use Ruby's standard build procedures
-# on Windows because the Ruby executable is
-# built with VC++ while here we want to build
-# with MingW. So just roll our own...
-
-require 'fileutils'
-require 'rbconfig'
-
-EXTENSION_NAME = "ruby_prof.#{Config::CONFIG["DLEXT"]}"
-
-# This is called when the Windows GEM is installed!
-task :install do
- # Gems will pass these two environment variables:
- # RUBYARCHDIR=#{dest_path}
- # RUBYLIBDIR=#{dest_path}
-
- dest_path = ENV['RUBYLIBDIR']
-
- # Copy the extension
- cp(EXTENSION_NAME, dest_path)
-end
-
-task :default => :install
@@ -1,38 +0,0 @@
-# We can't use Ruby's standard build procedures
-# on Windows because the Ruby executable is
-# built with VC++ while here we want to build
-# with MingW. So just roll our own...
-
-require 'rake/clean'
-require 'rbconfig'
-
-RUBY_INCLUDE_DIR = Config::CONFIG["archdir"]
-RUBY_BIN_DIR = Config::CONFIG["bindir"]
-RUBY_LIB_DIR = Config::CONFIG["libdir"]
-RUBY_SHARED_LIB = Config::CONFIG["LIBRUBY"]
-RUBY_SHARED_DLL = RUBY_SHARED_LIB.gsub(/lib$/, 'dll')
-
-EXTENSION_NAME = "ruby_prof.#{Config::CONFIG["DLEXT"]}"
-
-CLEAN.include('*.o')
-CLOBBER.include(EXTENSION_NAME)
-
-task :default => "ruby_prof"
-
-SRC = FileList['../*.c']
-OBJ = SRC.collect do |file_name|
- File.basename(file_name).ext('o')
-end
-
-SRC.each do |srcfile|
- objfile = File.basename(srcfile).ext('o')
- file objfile => srcfile do
- command = "gcc -c -fPIC -O2 -Wall -o #{objfile} -I/usr/local/include #{srcfile} -I#{RUBY_INCLUDE_DIR}"
- sh "sh -c '#{command}'"
- end
-end
-
-file "ruby_prof" => OBJ do
- command = "gcc -shared -o #{EXTENSION_NAME} -L/usr/local/lib #{OBJ} #{RUBY_BIN_DIR}/#{RUBY_SHARED_DLL}"
- sh "sh -c '#{command}'"
-end
View
@@ -83,10 +83,15 @@ figure_singleton_name(VALUE klass)
/* Make sure to get the super class so that we don't
mistakenly grab a T_ICLASS which would lead to
unknown method errors. */
-#ifdef RCLASS_SUPER
- VALUE super = rb_class_real(RCLASS_SUPER(klass));
+#ifdef HAVE_RB_CLASS_SUPERCLASS
+ // 1.9.3
+ VALUE super = rb_class_superclass(klass);
#else
+# ifdef RCLASS_SUPER
+ VALUE super = rb_class_real(RCLASS_SUPER(klass));
+# else
VALUE super = rb_class_real(RCLASS(klass)->super);
+# endif
#endif
result = rb_str_new2("<Object::");
rb_str_append(result, rb_inspect(super));
@@ -1078,10 +1083,8 @@ pop_frames(st_data_t key, st_data_t value, st_data_t now_arg)
}
static void
-prof_pop_threads()
+prof_pop_threads(prof_measure_t now)
{
- /* Get current measurement */
- prof_measure_t now = get_measurement();
st_foreach(threads_tbl, pop_frames, (st_data_t) &now);
}
@@ -1541,6 +1544,7 @@ prof_running(VALUE self)
static VALUE
prof_start(VALUE self)
{
+ char* trace_file_name;
if (threads_tbl != NULL)
{
rb_raise(rb_eRuntimeError, "RubyProf.start was already called");
@@ -1551,7 +1555,7 @@ prof_start(VALUE self)
threads_tbl = threads_table_create();
/* open trace file if environment wants it */
- char* trace_file_name = getenv("RUBY_PROF_TRACE");
+ trace_file_name = getenv("RUBY_PROF_TRACE");
if (trace_file_name != NULL) {
if (0==strcmp(trace_file_name, "stdout")) {
trace_file = stdout;
@@ -1613,23 +1617,27 @@ prof_resume(VALUE self)
static VALUE
prof_stop(VALUE self)
{
+ VALUE result = Qnil;
+
+ /* get 'now' before prof emove hook because it calls GC.disable_stats
+ which makes the call within prof_pop_threads of now return 0, which is wrong
+ */
+ prof_measure_t now = get_measurement();
if (threads_tbl == NULL)
{
rb_raise(rb_eRuntimeError, "RubyProf.start was not yet called");
}
- VALUE result = Qnil;
-
/* close trace file if open */
if (trace_file != NULL) {
if (trace_file!=stderr && trace_file!=stdout)
fclose(trace_file);
trace_file = NULL;
}
-
+
prof_remove_hook();
- prof_pop_threads();
+ prof_pop_threads(now);
/* Create the result */
result = prof_result_new();
@@ -0,0 +1,3 @@
+LIBRARY ruby_prof
+EXPORTS
+ Init_ruby_prof
Oops, something went wrong.

0 comments on commit dc2d7ec

Please sign in to comment.