title: Measure execution time of Java with JVMTI
body: <p>For the profiler which I implement using <a href="http://download.oracle.com/javase/1.5.0/docs/guide/jvmti/jvmti.html" rel="nofollow">JVMTI</a> I would like to start measuring the execution time of all Java methods. The JVMTI offers the events:</p>
  
  <ul>
  <li><code>MethodEntry</code></li>
  <li><code>MethodExit</code></li>
  </ul>
  
  <p>So this would be quite easy to implement, however I came across this <a href="http://download.oracle.com/javase/1.5.0/docs/guide/jvmti/jvmti.html#MethodExit" rel="nofollow">note</a> in the API:</p>
  
  <blockquote>
    <p>Enabling method entry or exit events will significantly degrade performance on many platforms and is thus not advised for performance critical usage (such as profiling). Bytecode instrumentation should be used in these cases.</p>
  </blockquote>
  
  <p>But my profiling agent works headless, which means the collected data is serialized and sent via socket to a server application displaying the results. How should I realize this using byte code instrumentation. I am kind of confused how to go on from here. Could someone explain to me, if I have to switch the strategy or how can I approach this problem?</p>