First of all, I'm using two ways of measuring activity launch time.
The first one is using the following command adb logcat -b events -d | grep am_activity_launch_time where the second from the last is represents the launch time.
11-02 17:14:39.710 608 626 I am_activity_launch_time [0,146177546,com.example.audiorecorder/.MainActivity,322,322]
Anyway, if use in code Log.i(appName, start) right in the beginning of onCreate and in the end of onResume() the elapsed time is around 50ms (which seems pretty impossible), comparing to 322ms from the logcat.
Any ideas of this discrepancy being so big?
I need to achieve a right measurement value using Log.i() in order to calculate the overhead of the same application (activity) using a binder service that I developed.
Thanks!
Related
I am currently compiling and executing some C++ code on a rooted Android device. I use adb (adb shell). To compile my code, I don't use the NDK, but I cross-compile with CMake
I'm using the function sleep(seconds) of unistd.h.
I've experienced some curious behaviors with that function on Android: Basically, I have a for loop in which I std::cout something and then call sleep(x).
If I call sleep(1), the behavior is the one expected: The program waits 1 second, and then executes the next instructions.
If I call sleep(2), the behavior isn't the one expected. The program gets stuck on that instruction for ever.... until I hit a key on my PC keyboard (not the device's one), and then it gets stuck on the next sleep(2)... until I hit a key, etc...
This behavior happens only when the device screen is off. As soon as I click on the power button to turn the screen on, the program resumes and has the expected behavior.
N.B: The behavior is the same with usleep(useconds)
I have tried to see where the limit is between 1 and 2 seconds:
1.5s, 1.25s, 1.125s -> always stay blocked | 1.0625s -> ~50% chance of staying blocked.
Obviously, there is something that prevents a thread to wake up if it sleeps more than 1 seconds (at least 2).
So my question would be, does anyone have any idea of why this is happening, and has a detailed explanation of the process ?
Thank you !
Android puts applications in the background when they aren't doing any user interaction - unix sleep and java timers etc. won't wake them up. You have to use an android alarm or runnable postDelayed handler.
I'm trying to get CPU usage in some point of running app. I need something like i used for time measurement.
Before I called the function (witch I want to measure) I used System.currentTimeMillis() to get the start time and the difference with the same value after function ended.
Running time of this function could be from 1 to 1000ms.
Mine solutions:
I can use adb top command triggered every millisecond (but i don't think it is working properly) adb shell top -m 15 -d 0.001 > C:\something\something\results.txt
Or, I was thinking about to call this command from running app in another thread (if the function will end so the thread would). If you think this could be the right way, may I still send results of command to some file in phone?Or should I use adb shell top -m 15 -d 0.001 -n 1 and call it in while cycle until thread will end?
If by function you mean literally java function then why dont you measure CPU time of its execution (difference of end and start measurements)? You can use System.currentTimeMillis() but this will measure also time of other threads that got CPU quantum. So I believe you are after Debug.threadCpuTimeNanos() which will measure only time CPU was executing your function code, you can investigate how it works by looking into sources:
http://androidxref.com/5.1.0_r1/xref/art/runtime/utils.cc#177
I'm not sure if this is what you're looking for, I've been looking into Android debugging recently, but I haven't tried this myself.
Here's the link: Traceview War Story, from the Android Developer's blog.
It describes using the Traceview tool to analyze functions and how much time the system is devoting to each process within that function.
Is there a way to automatically test android apps performance, like the time, needed by an app to load itself and become ready for user's interaction in android?
The one useful thing to do app performance automation is dumpsys that is described in this talk: https://www.youtube.com/watch?v=Qfo5fdoXrTU
Also there is a nice log output for the app start time, this is a quote from the docs:
From Android 4.4 (API level 19), logcat includes an output line
containing a value called Displayed. This value represents the amount
of time elapsed between launching the process and finishing drawing
the corresponding activity on the screen. The elapsed time encompasses
the following sequence of events:
Launch the process. Initialize the objects. Create and initialize the
activity. Inflate the layout. Draw your application for the first
time. The reported log line looks similar to the following example:
ActivityManager: Displayed com.android.myexample/.StartupTiming:
+3s534ms
Demo script (the one that is generated by new app generator) takes about 6 seconds to start on my SGS2. Is this a jRuby tax or is it me failing to install it properly (I am assuming rake install is the way)?
If it is just the way it is, then I am wondering whether an app that plays spinner 6 seconds longer than its rivals is of any value to anyone (genuine question - not trolling).
The startup time is how it is now, so you are not doing anything wrong. The main part of the startup time is JRuby initialisation. Work is going on to speed this up, but you should not expect a major change in the near future.
There are several workarounds for the startup time.
You can add a pretty splash instead of the boring progress spinner. You do that by adding a splash.xml in res/layout/ . A nice splash will make startup seem shorter.
You can initialize the JRuby runtime before users start the app. One way is to start a service at boot by adding a broadcast receiver that listens for the BOOT_COMPLETED event. The service can be empty, but by starting the service, the JRuby runtime is initialized, and any activities started later will start within milliseconds. You can find an example of this here:
https://github.com/ruboto/ruboto/wiki/Tutorial%3A-Detect-and-display-the-connected-WIFI-network
You can let the initial activity of your app be Java based, and start the JRuby initialisation in the background. In that case JRuby will be initialised when the user selects the next activity.
What the actual impact of longer startup time is, I cannot say. Faster is better, but I use several Java based apps that take 10 seconds or more to start up, and for me it is not a show stopper. It depends heavily on the type of app.
I am doing some ui automation, and I am able to store screen touches using getevent, but when I try to send this using sendevent, it takes a really long time, making it hard to actually replay the inputs.
I have already trying loading the script onto the device and running the script locally on the device (a script with a bunch of sendevent commands). But this only imporved this slightly. Is there some other way to inject these commands in a quicker way?
The handler for touch is implemented differently across devices. You should cat /proc/bus/input/devices to see where the touch handler is implemented.
You can also do adb shell getevent, interact with the device and see the output for the interface name.
The reason why your replay takes a long time is because the sendevent binary opens the interface file, writes data to it and closes it for every call to sendevent. So in theory, if you have a bunch of sendevent commands, the binary is opening the interface file, writing data and closing it for every command.
The way I've solved this issue is by re-writing the sendevent.c file under /system/core/toolbox to open the file only once during replay, writing all the data and closing it at the end of the replay. It works perfectly for me!
OK.
Instead of using the getevent/sendevent you can try direct reading from the event interface
inside adb shell try:
dd if=/dev/input/event6 of=record1 # to record
dd if=./record1 of=/dev/input/event6 #to play
However, this may run too fast...