Skip to content

Instantly share code, notes, and snippets.

@headius
Last active December 15, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/5207050 to your computer and use it in GitHub Desktop.
Save headius/5207050 to your computer and use it in GitHub Desktop.
oprofile source output from JRuby on JVM

Some stuff I did to get oprofile working with JRuby:

  1. Build my own oprofile according to instructions here: http://fiji.sc/Profiling_Java_Code#OProfile
  2. Enable profiling, naturally
  3. Run JRuby as jruby -J-agentpath:path/to/libjvmti_oprofile.so ...
  4. Run commands as seen in this blog post to create annotated output, etc: https://github.com/ryoqun/rubinius/blob/4e560bf8bdc56769317aa0cc438bf5094c736d52/web/_posts/2013-03-20-profiling-jitted-ruby-code-with-oprofile.markdown

Everything worked pretty much as I expected. You might want to pass -X+C to JRuby to make sure things compile to bytecode right away (so JVM can JIT them sooner).

# This is a sample of oprofile's source output, which shows how many
# samples occurred at each line. oprofile is a native profiler, but
# there's a JVM plugin. Because JRuby eventually JITs Ruby code to
# JVM bytecode, and JVM eventually JITs that to native code, Ruby
# code can show up in oprofile results.
# The first number is sample count, and the second is percent of all
# samples at that line. This method is from the red/black benchmark.
93 0.0070 : while x != root && x.parent.color == Node::RED
: if x.parent == x.parent.parent.left
367 0.0274 : y = x.parent.parent.right
59 0.0044 : if !y.nil? && y.color == Node::RED
74 0.0055 : x.parent.color = Node::BLACK
24 0.0018 : y.color = Node::BLACK
7 5.2e-04 : x.parent.parent.color = Node::RED
25 0.0019 : x = x.parent.parent
: else
12 9.0e-04 : if x == x.parent.right
24 0.0018 : x = x.parent
5 3.7e-04 : left_rotate(x)
: end
1 7.5e-05 : x.parent.color = Node::BLACK
18 0.0013 : x.parent.parent.color = Node::RED
22 0.0016 : right_rotate(x.parent.parent)
: end
: else
13 9.7e-04 : y = x.parent.parent.left
166 0.0124 : if !y.nil? && y.color == Node::RED
287 0.0214 : x.parent.color = Node::BLACK
91 0.0068 : y.color = Node::BLACK
62 0.0046 : x.parent.parent.color = Node::RED
124 0.0093 : x = x.parent.parent
: else
29 0.0022 : if x == x.parent.left
115 0.0086 : x = x.parent
: right_rotate(x)
: end
5 3.7e-04 : x.parent.color = Node::BLACK
99 0.0074 : x.parent.parent.color = Node::RED
121 0.0090 : left_rotate(x.parent.parent)
: end
: end
: end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment