Is there an instruction-oriented profiling tool for Android? - java

I need to profile several functions in my java code for Android.
I do know about traceview. And I actually found which functions to investigate using this tool. But it gives no information that can help in investigations inside specific functions.
So, is there any way I can get per-instruction profiling information for Java code on Android?

I would suggest you can try 'hprof' within your Java code to dump the profiled data to a file and you can analyse that file for more details.
API to use:
dumpHprofData(String fileName)
If you are interested in more granular level profiling then you can try 'readprofile' which works at Kernel level. You would need 'busybox' to use it though. However, I guess you need to map the instructions with your Java statements.

Related

JNI library profiling

in my project I wrote a java-agent library, which i want to profile. This question was already asked in 2013 here. So, I tried following the suggestion, using sprof, which failed due to this problem. I have also tried oprofile, however I am still not able to identify the bottlenecks of my application from its output.
So, my question is, what are the other suitable profilers for java native libraries? Does anyone have expirience in this kind of task?
You may find useful VTune Amplifier which is a profiler supportingĀ Java code analysis. You will be able to see the hotspots in your Java code and the performance metrics distributed through your java source file. What's really valuable is that VTune Amplifier shows the accurate stacks for pure Java code and Java/C++ mixed mode code. Please ask if you have questions.
First of all you should choose "Hotspots and stacks" while you're configuring analysis. See screenshot below. When collection is done that you should switch to the "Top-down Tree" tab in VTune UI. More info about the "Top-down Tree" tab is here.
Try to use "Hotspots, call count and stacks" to get call counts.

Retrieving CPU information in java

I need to write a small client application which gives CPU information such as CPU_TYPE, Processor_Speed, Serial number, UUID, operating system, physical memory and etc...
Does any one knows very straight approach for getting these information.
Thanks in advance
Viswanathan G
For CPU try org.hyperic.sigar.cmd.CpuInfo.
For OS try System.getProperties().
On Windows you could use WMI to get the necessary information by simply executing a (or several) simple scripts.
On linux you can do something similar by parsing information out of proc/cpuinfo and other stuff (not an expert there).
minimal example for win
I'm not aware of any framework that is crossplatform for this kind of information - mostly because there's just no way to get this information without delving deep into the platforms insides. Depending on how much data you need you may get by by parsing the data from some trivial scripts or you could use frameworks for all platforms you need.
I'm pretty certain there's no way to do this in pure Java. You'll need to use JNI or some other native-code interface to get information from the underlying OS. Unfortunately, this will also make your Java program not portable to other operating systems.
I'd just call some native command for that. On Linux it is cat /proc/cpuinfo.
Java is not good tool for this purpose but still can easily collect information from such native tools/calls.

Save and load a (Java) program's state

Suppose you're short on time and you're looking for a program with certain features, and you find one, except it lacks one feature - it cannot save and load its state. Is it possible to achieve this on OS level, or with another program, that can take the whole thing, write it to a file, and then at a later time, load it back into memory? How?
Specifically for me, this is about a Java program, but any more information on this topic is welcome.
One (heavy and easy) solution could be to use VirtualPC and install the program on a virtual OS.
Check these library's:-
Brakes
ACTC(Asynchronous Transfer of Control Threading) [Article]
Apache JavaFlow
You want to do something like the Hibernate function of Windows right?
This will be extremely difficult to implement in Java as you will also have to write the state of the JavaVM. If you had open files when you closed the program end so on.
I think the best you can do is writing the objects you need to recover to disk using Java serialization.
Have a look at the CRIU project at https://criu.org/Main_Page
It offers exactly this possibility within linux systems. Docker integrates it and offers a docker checkpoint command, which if you run your program in a container, will allow you to do this on any OS.

How can i monitor system statistics in kubuntu using Java?

i am doing a project related to configuration and memory analyzer for kubuntu.
i want to display the system statistics information like CPU usage, RAM usage and proceses etc. graphically using an odometer.
i wanted to know if there is any great open source library for graphical component like odometers and other graphing utilities.
also another problem is that i have to get information of cpu from somewhere and parse it and feed it into the odometer for display.
one method may be that i use command line utilities and parse the results and feed to the graphical component.
another option is that there is a library called libstatgrab which is written in complete C and i need to use JNI.
i dont like both these approaches because i am a little short on time and need a library that can do these things for me. there is a binding library present for Python to libstatgrab but not to java.
and if any one has any other approach, please write up.
For collecting the statistics, I would read directly from /proc or /sys, since they're just text files which are readily parseable (slightly moreso than exec()ing a command line tool and reading its output). Look at /proc/meminfo, /proc/loadavg, /proc/stat and others.
You can look at the C source of the procps package to see how these files are worked with by running
apt-get source procps
In there, you can look at how top.c reads the /proc/stat file.
As for charting, the "bog standard" plotting library is JFreeChart.
there is a binding library present for
Python to libstatgrab but not to java
Use jython?

How can I retrieve a hard disk's unique ID using Java+JNI on Linux, Windows and Mac

How can I retrieve a hard disk's unique ID using Java+JNI on Linux, Windows and Mac?
To sum it up: you can't do this with just Java
I do not think there is a simple, uniform way to do that.
You can however create seperate logic for all cases; on linux you could check /proc (using the java.io package). There are probably similar ways on OS X and Windows, or, if not, you could execute a shell script or batch file on these systems and parse the output.
Or you could use JNI, though that would mean building your module for all environments.
You could use Java+JNA (https://github.com/twall/jna/), but then you'd have to figure out how to gather that information by using native libraries on each of the platforms you'd like to support.
The benefit is that you wouldn't have to compile any C/C++ code for each of the platforms. If you decide to go with that option someone else might be able to tell you how to figure out the harddisk IDs on the different platforms using C/C++ code/libraries.
AFAIK, on Linux you need to read something from /proc or /sys, on Windows I would look through MSDN and see what you could find that is usable in Visual Studio (C++) and for Mac someone else would have to fill in. Solaris/BSD should probably be supported too if you do it right. In fact, for most of the POSIX-compatible OSes out there I think you should be able to do it somewhat uniformly.
As already in indicated, you can't within the boundaries of the question. However, you might be able to do it with a combination of java and native code specific for each platform via the JNI layer.
I may be wrong, imho, this canNot be done without using JNI.
Build your app in two parts
Native component that will use either a script/application to query the hardware, and output to a file
Your java app to read from the file and do whatever

Categories

Resources