Search code examples
androidsystrace

Can you use the Android Trace class from multiple threads?


Are you able to use the Android Trace class (http://developer.android.com/reference/android/os/Trace.html) from multiple threads and have it log time doing operations on each of those threads appropriately?

In particular, I have 2 threads that are each doing things and I'd like to visualize what each thread is doing at a given point in time using systrace. The docs for Trace only say that you should call #endSection from the same thread that called #beginSection, but it doesn't say whether multiple threads can be making their own calls to beginSection and endSection at the same time. Does anyone know if this is safe?


Solution

  • It's safe. It writes a marker to the systrace device, which is shared across multiple processes and threads.