How to find this stack trace? - android

My program keeps crashing, but the logcat does not show any exceptions. I just get the following message, plus a lot of stats about CPU usage. Clearly I'm using too much of the CPU, but I don't know what part of my program is doing this. Where is the following file? I can't find it.
12-30 23:13:06.639: INFO/dalvikvm(7688): Wrote stack trace to
'/data/anr/traces.txt'

adb shell
-->
cat /data/anr/traces.txt
EDIT:
You need to have root access to modify the files in /data/ you should be able to access the file with an app like https://market.android.com/details?id=com.estrongs.android.pop
Once you have that app, open it --> Menu --> Settings --> Home Directory (Change from /sdcard/ to /) --> Exit the app --> Open it again
Then you should be able to browse to /data/anr/*
EDIT2 (Additional info, based on comments) for use with a published app after hands on testing:
Most developers rely on the developer console error reporting to see the stacktrace and error logs when a user submits an error report.
Others impliment their own or use a library like ACRA
Be warned some users do not install an app simply because it uses the permission to read sensitive log data.

For comfortable viewing without cutted head of file use following one-line command:
adb shell "cat /data/anr/traces.txt" | less

The ANR stands for "Android Not Responding" and it doesn't mean you're using too much of the CPU, it means that the UI main looper hadn't been called for a given amount of time. The UI looper takes care of user input, so from the point of view of your user, the app was unresponsive to input. Usually this is caused by doing long-running or blocking operations on the main UI thread. For example, downloading a file on the main thread could cause an ANR. Usually it's pretty easy to pick out the code that causes an ANR just from that information.

If you are on Windows with Android Studio, you can do the following:
In Andriod Studio:
View > Tool Windows > Device File Explorer
This should open a new window with all files on the device (where your stack trace is located), then you can navigate to '/data/anr/traces.txt', just double click on the file will open it up for you.

Related

how to hide files in android (new proposed method)

is it possible to hide files in android by transfering/moving them to a location or sector (like in root folders or something) of which other apps don't have access to (via adb or termux or something)?.
I have mentioned adb and termux because i've seen performing actions like uninstalling system apps from device. and if possible, i don't want to root my device.
One humble request: i don't know the ABC's of app building/compiling, maximum i can do is execute commands in adb/termux. so if you paste any code, please also mention what to do with it.
i have tried:
putting dot at starting of the name of the files is too older method and everyone knows about it. encryption and decryption is too much time consuming process. And i don't have that much important data, i just want to hide it from direct access so that most of the people can't find it by normal methods.
Thank you very much

What is contained in Androids Bugreport?

I have been searching all around the Internet to find out what is contained in the android bugreport.
I am referring to the one you can generate by executing
adb bugreport
I am curious if the created .zip would contain Device crashes, Fatal exceptions and similar.
Where would they be found if yes?
Is there any documentation on what is and where archived?
Yes. Android Bugreport contains debug information like contents of the logcat buffers (main, radio, system, events, crash), dump of all the packages installed, ANR stack traces, network, data usage, battery usage, wakelocks etc. After extracting the zip file, you will see a text file with "bugreport" or "dumpstate" prefix which contains the logs from logcat buffers. The most recent exceptions and crashes can be found in that file.
For example search for string "beginning of crash" to find the crashes. "beginning of main" in the file is the start of logcat main buffer logs.
See Android documentation for more details https://source.android.com/setup/contribute/read-bug-reports

Using systrace in application code android

The documentation in android says
you can use the methods of the Trace class to add instrumentation to
your application code and see the results in a Systrace report.
I have added the below methods to my code
Trace.beginSection("test-trace");
// block of code
Trace.endSection();
Now where can I check the results of this section. I start the systrace tool from the android device monitor and recorded it for 30 secs(performed the button click that executes the above the block). It generates the trace.html file but how do i get the above section information from this html file
It is there, I myself searched for it about one hour :D
If you have only one thread, it's shown in UI thread row, otherwise it's shown in your-defined thread row.
If you can not find it, use the search toolbox, in top right corner of page, type 'test-trace' there and it will show you the start time of that in detail
:)
this screenshot may help you
The systrace output only includes the tags that are listed on the command line. For app-specific tracing, that means adding a --app=package-name argument. This is necessary because systrace logs the entire system, and you wouldn't want it to automatically pick up the traces for every app and component.
You can find an example here. For a program with package name com.faddensoft.multicoretest, you would use a command line like:
python systrace.py --app=com.faddensoft.multicoretest gfx view sched dalvik
With that, your tracing should appear in the row of the thread that's issuing the trace calls. (Open the HTML file in a web browser; might need to use Chrome.)
Probably you recorded too long, make sure to increase buffer size with -b command, or simply follow this example:
python systrace.py -app=package_name sched freq idle am wm gfx view dalvik input binder_driver -t 30 -o test.html -b 30384

Read Android Framebuffer in Java or Native Code

first off: I know that this worky only on rooted devices and i know that it is not recommended - but I still want and need to do it.
I am writing an app which performs OCR on an other app, parses its on-screen output and gives the user feedback on the apps progress (therefor using getRootView is out of the question).
This can not be done in an other way, I need to have screenshots of the app at least 3 to 4 times per second.
Other ways that I tried:
/system/bin/screencap - too slow, takes >2 sec per shot on a Galaxy S5.
using obscure C Code to access the internal API of the SurfaceComposer (bloated, did not compile)
What I want: Have a way to read bytes from the framebuffer without having to write it to a file each time.
Currently I have the problem that my app does not have the right permissions. I added the READ_FRAME_BUFFER permission, but I still get a ERRNO 13 (Permission denied) when reading /dev/graphics/fb0, as the app itself is not started with root permissions.
I know I can start a shell or something similar with su, but that is not convenient - I would prefer a way to start a Service or my native Code with the right permissions.
I read about System Services but could not find any "easy" introductions. My experience in C/C++/Java is more than enough, but the Android API's jungle is newfound land to me.
The information from TI-Wiki - Writing System Services seems to implie that a rebuild of the Android System is necessary to integrate a System Service. That would be out of the question. Is that correct?
In an ideal world I would have:
Bitmap Service.getCurrentFrame() {
read one frame from /dev/graphics/fb0
create Java Bitmap
return Bitmap
}
This could be either native or Java code.
But how to gain the privileges?
Any ideas?
Additionally, I read that using the framebuffer is not recommended since it is about to be removed in future releases (sorry, lost source link).
What other fast ways are there to get the current screen content?
Use DDMS lib /dev/graphics/fb0 to get bitmap. No special permission needed.

using startMethodTracing and stopMethodTracing with ddms

I'd like to measure performance in a specific function (and everything it calls). To do so, it seems I should use Debug.startMethodTracing() and Debug.stopMethodTracing(), then somehow start DDMS tracing.
However, when I open a DDMS view in Eclipse and click the Start Method Profiling button, it starts immediately - not when startMethodTracing() executes. The result is a huge trace file with mostly irrelevant stuff in it. Too hard to narrow in (I tried a few times).
Apparently TraceView is deprecated. Should I hack a way to use that anyway? Is it any better? What is the correct approach to do what I need?
Thanks.
If you use Debug.startMethodTracing() and Debug.stopMethodTracing() a .trace file will be created on the device. The exact location of it is printed out in the logcat.
Look for entries that start with "TRACE STARTED" and "TRACE STOPPED". You then can use adb pull to get the .trace file from your device and open it in the tool of your choice for analysis (e.g. Eclipse or some third party product)
There is no need to manually use DDMS in Eclipse if you're using the above calls. The .trace file itself can simply be opened in Eclipse by using File -> Open

Categories

Resources