How can I discover CPU usage of my application in Android (programmatically)? - android

Is there any way to find out CPU usage of my Android application programmatically? I'm aware of this question already, but it is about Corona SDK.
Note that I want to do this on non-root devices.
Any help would be appreciated.

I am not sure about programmatically, but you can use Android profiler to achieve the same.
Run your application, either in a physical device or emulator (doesn't matter here)
When the application is running, you will see a Profile tab in the toolbar
If you don't see a Profile tab, you can access the same using Run > Profile 'app'
Edit
Check this answer
Edit 2
You can use firebase performance monitoring for runtime data collection about performance. Follow this link

I just found a way to calculate the CPU usage of a process by PID. According to the doc, the /proc/[pid]/stat file contains status information about the process. So we can parse this file to get the following members:
utime %lu
stime %lu
Check this page to get more information about the /proc/[pid]/stat file and the way to parse it.
Also here is a relevant question about utime and stime.

Related

Get the layout of other running apps in Android?

Is there a way I can get the hierchary view/layout of other running android apps? If that's not possible, could I possibly unpack the app's .apk file and get the information there? For example, there's a setting in developer options that allows you to get the bounds of every elememt on the screen like so
EDIT
I have come to realize that this is not allowed and goes completely against the Android SDK. I apologize for this error and will look more closely in the future.
I have found out that Google blocks any of this because it would require me to inject my own code into other apps, which is not allowed due to malicious behavior in past apps.

How can my Android app get method tracing of another process/app on a phone that has enabled developer options?

I would like to write an Android app (not a PC program) that has a subset features of Android Device Monitor (ADM), ie. select a process and trace its method calls, with detailed information (all the information that ADM can get, like stack trace and time), while the phone is not connected to any computer nor does it have any network access.
I've searched into android.os.Debug.startMethodTracing*, but it seems can only trace current process and the result can only be written into a file (I need the info in memory).
Digging its implementation, I found dalvik.system.VMDebug.startMethodTracing*, but it seems cannot be used by apps and I didn't find a way to specify pids, neither. Looks like it's calling JNI functions, but I didn't find the implementation.
Maybe I can get the information by lower level way by using Linux perf events (perf_event_open(2)). But before doing that, I would like to know if such kind of feature possible to implement purely in Java (maybe by talking to some "system manager" process or "debugging server" process, or by calling some CLI tools then get its stdout)?
These capabilities can only be accessed by the shell user (the user that adb runs as), or the root user of course. By design, a normal android application cannot access these features, because this would completely break the application sandbox that is the basis of the application security model in Android.

Tcpreplay in Android?

I am performing some experiments where I want to replay a previously captured packet trace from Android. So far I have written my own application to replay the trace and get then answer back from the server. Timing accuracy is not a big problem as long as is within reasonable bounds (e.g., some milliseconds).
However, I would prefer to use a tested tool like tcpreplay. Is there any project that have ported tcpreplay to Android? Given that libpcap is available, there should be something available, but I could not find anything.
Thanks for your help
I'm the author of tcpreplay, and I can't say I'm aware of an Android port. Never owned an Android device so can't say one is coming anytime soon.
I've got it running on my tab, you need to install GNUroot and Debian no root, they are both from the same developer... After get it, open GNUroot, check emulate new root, create rootfs and run the rootfs, after this "apt-get install tcpreplay". If you want to capture use TpacketCapture in the play store, you can also get Tpacketcapture Pro to use the capture in only one app.
If you are planning to hack games don't publish it, cause this vulnerability can be easily patched...
any question email me.

Need to get specific SW information from Android phone in app

I am working on an app that will access different items in the phone status screen for work. I need to be able to get specific software information from the phone to populate in the app. For example: in the droid x, the system version shows as 4.5.605.MB810.Verizon.en.us . This is the software info I need to auto populate. I have tried all of the Build options from the android developer site and I have even tried the SYSTEM_VERSION string from telephony, but they all provide information other than what I need. Can anyone tell me how to reference this software information please?
Check out android.os.Build. Here are the details:
http://developer.android.com/reference/android/os/Build.html
And for OS version specifics, use the nested class Build.VERSION detailed here:
http://developer.android.com/reference/android/os/Build.VERSION.html
Check the Settings app code for where it gets its information.

Retrieving configuration of my android device programmatically

Can anyone explain me that how can i get the configuration of Android device programatically in my app.
Also how can I get the other device related information like Battery usage,CPU load,RAM usage,Memory details etc programatically.
Thanks in advance.
This will get you started for the battery:
Android Battery in SDK
And this will get you a bunch of system properties (look at the getProperty method):
http://developer.android.com/reference/java/lang/System.html
Also these threads on memory management will provide a place to start:
Get Memory Usage in Android
How to get current memory usage in android?
You can use package Manager, using package manager you can get it

Categories

Resources