Android -- How can we determine the Battery Usage statistics per application? - java

I am having trouble finding a class or API in Android documentation that would help me get battery usage statistics per application.
I have read PowerManager and BatteryManager classes but they are of no use.
However, I can find applications like PowerTutor that do provide battery usage statistics per application, so I think it's technically possible.
Can any one point me in right direction?

I'd be surprised if such an API exists. Rather, I expect that PowerTutor is using some sampling heuristics to estimate how much of the current battery usage to blame on each application.

Related

How to find battery leak in my application?

I've written an application, it's a big one and it has lots of features.
But I have a problem with it: in the phone battery usage it takes about 35 percent of battery and it's a huge problem even when I don't use it very much.
I've no services in my application and I really don't know where the problem is.
Is there any way that I can find out what is using my battery?
I am using PowerTutor for this purpose when i am testing my application performance and battery usage. Even i am using this application also https://developer.qualcomm.com/software/trepn-power-profiler. Please try this let me know if it helps you.

Is there any Android API to get CPU and battery status?

I'm working in my thesis, and I need to explore the google Android API to find a way to get every possible information about the CPU and Battery (like CPU temperature, % of usage, battery level, energy consumption, ...).
The idea is measuring, in 2 or more different execution times, the energy consumed by an Android APP, and get details on what was used by the APP to spend that energy.
Does anyone know any API from Android to measure this kind of things?
For getting battery level, you can register an Intent for ACTION_BATTERY_CHANGED. For more information refer to the Android Battery API. If you just want to get the battery temperature, you can get it using the API itself. I think Android does not have an API for CPU temperature.
However, you can read the temperature from /sys/class/thermal/thermal_zone0/temp
This is the way to get temperature on linux based systems and since Android is Unix based, I think you should be able to do it. I haven't tried it myself though
Take a look at Monitoring the Battery Level and Charging State guide. Concerning CPU, you should be able to collect some data from Systrace.

How to measure the energy consumed by my Android app in a certain moment

I have been trying to figure this out since couple months ago because I'm working on my thesis, but unfortunately I have not been able to make it. What I'm doing is a performance analysis regarding energy consumed by an application running an algorithm locally on the phone and the same app but running the algorithm on the cloud and getting the response back to the phone. What I want to do is to try to find an accurate way to obtain the energy consumed by this algorithm since it's executed until it gets the solution (locally and remotely).
Is there any way that I can use in java to do it by using the Android API? I would like to write my own code to get the measures. Please anything you guys think it is helpful PLEASE, let me know... I appreciate your time and patience,
Alberto.
I am not sure if there is such an API available. Here is a link with similar discussion. If you want because energy/battery consumption depends on may other factors including the efficiency of the compiler.

Java SNMP API Choice

I know this question has been asked many times over, but I am currently using snmp4j library and I am finding it very slow. It takes about six seconds for six queries even on my local system, and also I cannot get direct values such as particular disk usage, I have to manipulate several values since the MIB-II mib that I use doesn't have that many features built in. Is there any API that's fast and also permits direct retrieval of metrics such as disk usage, CPU usage, memory free, memory usage etc.,
There are many APIs available on the net but I don't have time to try out all, I would like answers from someone who have actually worked hands on with such APIs.
You should analyze the performance down to a much lower level and then tell if it performs slow. Of course, you should clarify which part of snmp4j you are using (the manager or the agent).
Your requirements on what kind of data to be returned from SNMP queries are not suitable for a general SNMP libraries/agents such as snmp4j. To be general, they are designed according to IETF RFCs, where no OS specific API was documented.
If you do search for an OS specific agent, or you want this agent to have as many features as possible implemented, you may go to commercial ones. In that case, their presale guys can take your phone calls or mails and give you the answers you want.
The performance problems you encounter are not related to SNMP4J. I would suspect some programming issues with your test case. SNMP4J perfectly is able to "directly" (using GET PDU) fetch metric values for any standard or custom MIB.
I am not aware of any "more advanced" API. SNMP4J fully implements all SNMP standards. So what are you missing?

How to get CPU utilization using Javascript or Java

How can I get the CPU utilization of client's machine.
I have created a Java web application and where I need to get the CPU utilization of client's machine.
Can it be done using either Javascript or Java?
Whatever you use, Java or Javascript, you can't get CPU utilization of the client's machine. That will be a huge security risk. The only way to do it will be to install a plug-in. This wouldn't help too much however, as reading the CPU utilization is platform specific.
#Daniel provides a link to a method that (on a good day) would give an approximate measure of CPU usage.
#kgiannakakis says that this would be a serious security risk.
But I wonder. How could an attacker exploit CPU usage levels to compromise the user machine's security, or steal sensitive information about the user? Off the top of my head, I cannot think of anything realistic.
The only possible risk I can think of would be if the attacker had already installed/launched some spy software somewhere else on the user's machine. The ability to measure CPU usage could be used to implement a "covert channel" to get information from the spy s/w to the outside world. But this is only of theoretical interest (unless you are trying to implement A1 / A2 level security).
It may look like a security risk, but there is a technique to get an estimate of the CPU usage with JavaScript inside the browser. You may want to check this article:
Ajaxian - JPU: JavaScript CPU Monitor (Demo here)
As kgiannakakis noted in a comment below, this calculation is based on the delay of setInterval() calls.
I remember seeing a similar implementation on Mindmeister.com (showing the CPU usage while editing a mind map.)
There is simple example of a CPU usage monitor demonstrates how to use XML DOM capabilities of client JavaScript in a BSP application to dynamically request data from server and adjust corresponding elements of the screen without reloading the whole page.
This article might be helpful.
jni concept for cpu utilization
http://www.javaworld.com/javaworld/javaqa/2002-11/01-qa-1108-cpu.html?page=1
try this link
If its java look at OperatingSystemMXBean using the please be aware this is Java 1.6 only.
OperatingSystemMXBean operatingSystemInfo =
(com.sun.management.OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
I am not sure how well this works in an applet.
I once looked into creating a Web Start application that could be launched by a user to "scan" their system hardware. Luckily, the targeted systems were Windows boxes, so I used the Jacob package (Google or search this site for info) to do a WMI query for things like serial numbers, etc.
I created a proof of concept Swing client app, but never got around to the Web Start portion.

Categories

Resources