title: android traceview asynchronous events
body: <p>I'd like to use traceview to measure performance for several asynchronous events.  The asynchronous events are passed to me in a callback that looks similar to the below code.</p>
  
  <pre><code>interface EventCallback {
  
      void onStartEvent(String name);
  
      void onStopEvent(String name);
  }
  </code></pre>
  
  <p>where every asynchronous event will start with a "onStartEvent" call and end with an "onStopEvent" call.</p>
  
  <p>I'd like to create trace files for every event.  From my reading here (<a href="http://developer.android.com/tools/debugging/debugging-tracing.html#creatingtracefiles" rel="nofollow">http://developer.android.com/tools/debugging/debugging-tracing.html#creatingtracefiles</a>), it's not possible to trace asynchronous events since the ordering of the calls must be "structured" in a "stack" like ordering.  So, the call to "Debug.stopMethodTracing()" always applies to the most recent call to "Debug.startMethodTracing("calc");"</p>
  
  <p>So, if I receive callbacks in the following order.</p>
  
  <p>onStartEvent(A)</p>
  
  <p>onStartEvent(B)</p>
  
  <p>onStopEvent(A)</p>
  
  <p>onStopEvent(B)</p>
  
  <p>which will get interpreted to</p>
  
  <p>Debug.startMethodTracing("A");</p>
  
  <p>Debug.startMethodTracing("B");</p>
  
  <p>Debug.stopMethodTracing(); // will apply to "B" instead of "A"</p>
  
  <p>Debug.stopMethodTracing(); // will apply to "A" instead of "B"</p>
  
  <p>Using traceview, is there anyway to do what I want?  i.e. trace "non-structured" asynchronous events?</p>