— Exposing Dalvik's sampling profiler to general public.
// Profile only this thread, store result into "/sdcard".
SamplingProfilerReceiver.setStorageDirectory("/sdcard");
SamplingProfilerReceiver.start(Thread.currentThread());
...
SamplingProfilerReceiver.stop("MyProcess");
public final class TestActivity extends Activity {
private final SamplingProfilerReceiver mReceiver = new SamplingProfilerReceiver();
...
@Override
public void onDestroy() {
...
mReceiver.unregister(this);
super.onDestroy();
}
@Override
public void onCreate(final Bundle bundle) {
super.onCreate(bundle);
mReceiver.register(this);
...
}
}
To control it:
# start
adb shell am broadcast -a hihex.samplingprofiler -e action start -e interval 30 -e depth 16
# stop
adb shell am broadcast -a hihex.samplingprofiler -e action stop -e format ascii
# suspend
adb shell am broadcast -a hihex.samplingprofiler -e action suspend
GPLv3.