jruby-profiler-callgrind-printer 1.0.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b24992a0511c20384c29de64017e79ac16d11a53
4
+ data.tar.gz: e784d2ee82590cfd94125f1dd6b88e91302664ed
5
+ SHA512:
6
+ metadata.gz: bcc66ce47fb9fe38d1a98775a2727d4f4f0322cc88035c9f422027f973305761b56e969dd70678580ea6e33ebef17bc2b16c7d714e911ff33ba88242ae850f1e
7
+ data.tar.gz: fc26fdbed30f3f9360449a2ecd16f0f8ba51ca6614b674a993edf1e1da7631170e836d7a73e9438296eaf8d60466be9768dc685e31612f2e366469ec5a66eedb
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "bundler"
5
+ gem "jeweler"
6
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Michael Ryan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # JRuby::Profiler::CallgrindPrinter
2
+
3
+ ## Summary
4
+
5
+ This gem provides the similar functionality to that of [ruby-prof](https://github.com/ruby-prof/ruby-prof)'s [RubyProf::CallTreePrinter](https://github.com/ruby-prof/ruby-prof/blob/master/lib/ruby-prof/printers/call_tree_printer.rb), but for the JRuby's Profiler. Specifically, JRuby::Profiler::CallgrindPrinter will produce 'callgrind' formatted output for analysis in any tool that understands Valgrind's 'callgrind' file format, such as KCacheGrind and QCacheGrind.
6
+
7
+ CallgrindPrinter has been written in pure-ruby, as opposed to Java, simply to see if it was possible (and it was).
8
+
9
+ ## Usage
10
+
11
+
12
+ For a runnable example, see examples/example1.rb.
13
+
14
+ Generally, you would do something like the following:
15
+ ```
16
+ require 'jruby/profiler'
17
+ require 'jruby/profiler/callgrind_printer'
18
+
19
+ result = JRuby::Profiler.profile do
20
+ # Do some expensive stuff.
21
+ end
22
+
23
+ printer = JRuby::Profiler::CallgrindPrinter.new(result)
24
+ File.open("callgrind.out", "w") do |fio|
25
+ printer.printHeader(fio)
26
+ printer.printProfile(fio)
27
+ printer.printFooter(fio)
28
+ end
29
+ ```
30
+
31
+ and then run the above with 'jruby --profile.api your_code.rb'. You can then open up 'callgrind.out' with Kcachegrind or Qcachegrind.
32
+
33
+ ## Important!
34
+ The jruby profiler is disabled by default. You *must* run jruby with the '--profile.api' switch in order for any data to be gathered. Something along the lines of 'jruby --profile.api some_script.rb'
35
+
36
+ If you don't enable the profiler, everything will run fine, but it will seem as though no data is being gathered, and somewhat empty outputs will be produced.
37
+
38
+
39
+ * [Callgrind Format Specification](http://valgrind.org/docs/manual/cl-format.html)
40
+
41
+
42
+
43
+
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "jruby-profiler-callgrind-printer"
16
+ gem.homepage = "http://github.com/justfalter/jruby-profiler-callgrind-printer"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Provides callgrind output for the JRuby profiler}
19
+ gem.description = %Q{Provides callgrind output for the JRuby profiler}
20
+ gem.email = "falter@gmail.com"
21
+ gem.authors = ["Mike Ryan"]
22
+ gem.platform = "java"
23
+ gem.files = Dir.glob("lib/**/*.rb") +
24
+ Dir.glob("examples/{*.rb,*.callgrind.out}") +
25
+ %w(LICENSE.txt Gemfile README.md Rakefile VERSION)
26
+
27
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
28
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
29
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
30
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
31
+ end
32
+ Jeweler::RubygemsDotOrgTasks.new
33
+
34
+ #require 'rspec/core'
35
+ #require 'rspec/core/rake_task'
36
+ #RSpec::Core::RakeTask.new(:spec) do |spec|
37
+ # spec.pattern = FileList['spec/**/*_spec.rb']
38
+ #end
39
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,42 @@
1
+ events: process_time
2
+
3
+ fl=(jruby_runtime)
4
+ fn=Fixnum#<=>
5
+ 0 8766488
6
+
7
+ fl=example1.rb
8
+ fn=Object#fibonacci
9
+ 8 256712
10
+ cfl=example1.rb
11
+ cfn=Object#fibonacci
12
+ calls=57270 8
13
+ 8 0
14
+ cfl=(jruby_runtime)
15
+ cfn=Range#include?
16
+ calls=57291 0
17
+ 0 51924983
18
+
19
+ fl=(jruby_runtime)
20
+ fn=Range#include?
21
+ 0 43158495
22
+ cfl=(jruby_runtime)
23
+ cfn=Fixnum#<=>
24
+ calls=114582 0
25
+ 0 8766488
26
+
27
+ fl=(jruby_runtime)
28
+ fn=Integer#upto
29
+ 0 248929
30
+ cfl=example1.rb
31
+ cfn=Object#fibonacci
32
+ calls=21 8
33
+ 8 114585076
34
+
35
+ fl=(jruby_runtime)
36
+ fn=(top)
37
+ 0 0
38
+ cfl=(jruby_runtime)
39
+ cfn=Integer#upto
40
+ calls=1 0
41
+ 0 114834005
42
+
@@ -0,0 +1,25 @@
1
+ # To run:
2
+ # jruby --profile.api example1.rb
3
+ #
4
+ # This will produce 'example1.callgrind.out', which may be opened within Kcachegrind
5
+
6
+ require 'jruby/profiler'
7
+ require 'jruby/profiler/callgrind_printer'
8
+
9
+ def fibonacci( n )
10
+ return n if ( 0..1 ).include? n
11
+ ( fibonacci( n - 1 ) + fibonacci( n - 2 ) )
12
+ end
13
+
14
+ result = JRuby::Profiler.profile do
15
+ 0.upto(20) do |i|
16
+ fibonacci(i)
17
+ end
18
+ end
19
+
20
+ printer = JRuby::Profiler::CallgrindPrinter.new(result)
21
+ File.open("example1.callgrind.out", "w") do |fio|
22
+ printer.printHeader(fio)
23
+ printer.printProfile(fio)
24
+ printer.printFooter(fio)
25
+ end
@@ -0,0 +1,68 @@
1
+ module JRuby
2
+ module Profiler
3
+ class CallgrindPrinter < org.jruby.runtime.profile.ProfilePrinter
4
+ # @param [IO] out
5
+ def printHeader(out)
6
+ out.puts("events: process_time")
7
+ out.puts()
8
+ end
9
+
10
+ # @param [IO] out
11
+ def printFooter(out)
12
+ end
13
+
14
+ # @param [IO] out Where we want to write our output
15
+ # @param [Boolean] is_first (false) Does nothing, at the moment
16
+ def printProfile(out, is_first=false)
17
+ ti = getTopInvocation()
18
+ methods = self.class.methodData(ti);
19
+
20
+ methods.entrySet.each do |entry|
21
+ serial = entry.key
22
+ method_data = entry.value
23
+ file, line, method_name = get_info(serial)
24
+ out.puts("fl=#{file}")
25
+ out.puts("fn=#{method_name}")
26
+ out.puts("#{line} #{method_data.selfTime}")
27
+
28
+ method_data.children.to_a().each do |child_id|
29
+ next if self.isThisProfilerInvocation(child_id)
30
+ f, l, n = get_info(child_id)
31
+ invs = method_data.rootInvocationsOfChild(child_id)
32
+ num_calls = method_data.invocationsOfChild(child_id).totalCalls
33
+ out.puts("cfl=#{f}")
34
+ out.puts("cfn=#{n}")
35
+ out.puts("calls=#{num_calls} #{l}")
36
+ out.puts("#{l} #{invs.totalTime()}")
37
+ end
38
+
39
+ out.puts()
40
+ end
41
+ end
42
+
43
+ # @param [Integer]
44
+ # @return filename, line number, method_name
45
+ def get_info(serial)
46
+ name = self.methodName(serial)
47
+ file = '(jruby_runtime)'
48
+ line = 0
49
+
50
+ if pm = self.getProfileData().getProfiledMethods().get(serial)
51
+ if m = pm.getMethod
52
+ if m.respond_to?(:getFile)
53
+ file = m.getFile
54
+ end
55
+
56
+ if m.respond_to?(:getLine)
57
+ line = m.getLine
58
+ end
59
+ end
60
+ end
61
+
62
+ return [file, line, name]
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jruby-profiler-callgrind-printer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: java
6
+ authors:
7
+ - Mike Ryan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: jeweler
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ description: Provides callgrind output for the JRuby profiler
42
+ email: falter@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files:
46
+ - LICENSE.txt
47
+ - README.md
48
+ files:
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - VERSION
54
+ - examples/example1.callgrind.out
55
+ - examples/example1.rb
56
+ - lib/jruby/profiler/callgrind_printer.rb
57
+ homepage: http://github.com/justfalter/jruby-profiler-callgrind-printer
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.1.9
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Provides callgrind output for the JRuby profiler
81
+ test_files: []