My app changes the properties of some really simple views (rotation, translation) per frame. I used systrace, as advised by Android performance articles, to check if I was dropping frames.
Something really unexpected came up. When the device was standing still (even if I touched the screen) the CPU usage was higher, alerts on systrace came up and the red portion of GPU rendering profiler was longer. When I rotated or shook the device really fast, everything was OK.
Below are the links of the results. Shake
is when I rotated the devices really fast, no_shake
is when it was left sitting on my desk.
I made a really simple test app that uses a single translation animation: source code.
Looking at the shake systrace, where frame-rate is smooth, why do HW_VSYNC_0 and HW_VSYNC_ON_0 lines have no data? How can I read the CPU frequency (I did enable the option when capturing the trace).
Regarding the problem, my theory was that the device could be lowering the CPU frequency. How can I read this in systrace? I used a 3rd party app to test this hypothesis and it is true as shown below. So, what can I do to avoid this problem?
Why is the device doing this? At first I thought that the device uses the accelerometer data to understand if it is not being used and then it reduced the CPU frequency. But, in order to increase the CPU frequency I have to shake the device really hard. Holding it like a normal person would does not increase the CPU frequency.
I know that's a lot of questions, but having read all the related articles about the Android graphics pipeline, I am out of ideas.
The problem occurred on a Sony Xperia Z3 running Android 5.1 The problem was not reproducable on a Nexus 5 running Android 6.
Update
It seems that the performance issue is caused by CPU/GPU throttling. The same device, Xperia Z3, when running Android 4.4, even though it reduces the clock speed, it performs better according to Systrace. Also, it does not increase speed when shaking.
Regarding the shaking gesture required to increase the CPU speed, I noticed that when I try to rotate the device from portrait to landscape or vice versa, then the CPU clock increase in triggered (even if the app doesn't change orientation). So, I think that the reason this gesture is monitored is to speed up a possible orientation change.