I've used many apps that show the speed in MHz on my phone, but where are they getting the information from? I am trying to get the minimum and maximum frequencies of my processor, but am stuck. I've tried reading from:
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
but, the only folders under cpufreq are "power", "subsystem", "uevent", and "topology".
/sys/devices/system/cpu/cpufreq/
Also has no files.
/proc/cpuinfo
Has a lot of information, but it only shows BogoMIPS instead of both.
Is there elsewhere should be looking or is there some special equation that I need to use in order to calculate it from the data that I do have?
For me,this code works:
String cpuMaxFreq = "";
RandomAccessFile reader = new RandomAccessFile("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
cpuMaxFreq = reader.readLine();
reader.close();
Related
I've seen numerous questions/answers showing how to get temperature information from an Android device - using this approach:
int zoneNumber = 0; // Usually 0 or 1
String temperatureFileLocation = "sys/devices/virtual/thermal/thermal_zone" + zoneNumber + "/temp";
File temperatureFile = new File(temperatureFileLocation);
scanner = new Scanner(temperatureFile);
double temperatureC = scanner.nextFloat(); // Degrees C
...
scanner.close(); // finally
I wasn't really sure what each zone is for (i.e., in which part of the device the sensor is located) but I just discovered that there is also a file that describes the type of each zone - for example:
String zoneTypeFileLocation = "sys/devices/virtual/thermal/thermal_zone" + zoneNumber + "/type"; // NB - that's "/type" not "/temp" !
Now, when using Scanner to read in what type each zone is, I get values back such as this:
mtktswmt
mtktscpu
mtktspmic
mtktspa
mtktsabb
mtktsbattery
tsen_max
sec-fuelguage
Can anyone explain what locations/components all these zone names are actually referring to?
(Ideally, I would like to obtain the temperature of the device's NFC hardware.)
I guess that's the Hardware thermal sensors of the mobile. They usually give the temperature of the given zones when the mobile is working or even when you perform some benchmarks results.
like
mtktswmt is Wifi Chip temperature zone.
mtktscpu is cpu temperature zone.
mtktspmic is Multi IO and Regulator Chip temperature zone.
mtktspa is Thermal sensor MD1
mtktsabb is processor temperature zone.
mtktsbattery is the battery temperature zone.
tsen_max is the maximum temperature sensor capacity(I dont know for sure).
sec-fuelguage is the fuel gauge chip.
the mtkt prefix is just the name of the maker. In this case it is Mediatek
That's pretty hardcore hardware stuff. These are actually used by the makers of the android mobile phone(I guess). Even the above mentioned data is searched from google android open source project where the values were found in kernal drivers. Hence it's pretty hardcore hardware to play with it.
For using the Hardware Properties that actually gives you your desired results try HardwarePropertiesManager.
I hope it Helps.
I am trying to obtain a bitmap of the number of cores which are online in an android device. I am trying to create a command line tool in C++ that does some additional functionality based on how many cores are on and in particular which cores are available.
I have tried to use the following to try and get the number of cores on in C++:
cpus = sysconf( _SC_NPROCESSORS_ONLN );
This gives me the number of cores in the system but not which cores are presently ON.
Does anyone know a potential way to do this?
There's no clear cut answer to this problem.
You can use nproc to see how many cores you have available, but this won't tell you how many cores you have online.
You can use top to view the utilization of each core. You can then parse the information from top to infer which cores are presently on.
I was able to get the core online status using this:
int numCPU = 1;
char *status = (char*)calloc(32,sizeof(char));
char *directory = (char*)calloc(1024,sizeof(char));
sprintf(directory, "/sys/devices/system/cpu/cpu%d/online", numCPU);
FILE *online = fopen(directory, "r");
if(online)
{
size = fread(status, sizeof(char), 32, online);
}
printf("Core %d status=%d", numCPU, status);
I write a little android app, sends Http request, receives response from server, and count how many bytes transmitted and received.
and the code is simply as follow
long receivedBytes = TrafficStats.getUidRxBytes(uid)-lastNumer
i find that the receivedBytes is always larger the size http Header+http Body, for example
the actual http frame's size i caught( use wireshark) in server is 1645 bytes(header+body), but the android API returns receivedBytes is 1912, so as the transmission.
the TrafficStats getUidRxBytes itself is inaccurate(may be this problem is specific to my platform samsung i9300 with cynogenmod 10.3)
finally, i find the correct way to count the data usage i find other way to count the data usage which seems more accurate than TrafficStats API.(many thanks to here)
private long[] getStat() {
String line, line2;
long[] stats = new long[2];
try {
File fileSnd = new File("/proc/uid_stat/"+uid+"/tcp_snd");
File fileRcv = new File ("/proc/uid_stat/"+uid+"/tcp_rcv");
BufferedReader br1 = new BufferedReader(new FileReader(fileSnd));
BufferedReader br2 = new BufferedReader(new FileReader(fileRcv));
while ((line = br1.readLine()) != null&& (line2 = br2.readLine()) != null) {
stats[0] = Long.parseLong(line);
stats[1] = Long.parseLong(line2);
}
br1.close();
br2.close();
} catch (Exception e) {
e.printStackTrace();
}
return stats;
}
I see that you've already found a solution, but I'll add my thoughts on your question as it might be useful to other people (ended up here myself after googling how to use the TrafficStats API).
The API documentation states:
Statistics are measured at the network layer, so they include both TCP and UDP usage.
The documentation could indeed be more thorough, but I'm inclined to say that one can assume that the returned byte count also includes the bytes making up the transport layer header and the network layer header.
HTTP is an application layer protocol. When you're calculating your expected bytes to be the HTTP header bytes plus the HTTP body bytes, you're only dealing with application layer bytes, hence not accounting for transport and network layer header bytes. I assume TCP is used for the download. This adds a header ranging from 20 to 60 bytes. Moreover, let's assume you're using IPv4 for the download. This also adds a header ranging from 20 to 60 bytes.
Obviously this won't account for the entire 1912 - 1645 = 267 bytes, but it might give you/other people some leads.
A bit off-topic, but still related. It's not quite clear if the TrafficStats API actually count header bytes or not. According to this answer, the API does not count header bytes. However, given the API documentation listed above, the linked answer may be stipulating something that is not true (at least not for API level 21). Moreover, this question also hints at TrafficStats actually counting network and transport layer header bytes (check comments).
TrafficStats actually counts network and transport layer header bytes. See kernel source and TrafficStatsTest.
From my understanding, you should combine getUidRxBytes with getUidRxPackets.
You should have something like : getUidRxBytes = getUidRxPackets * (tcp/ip header size)
I've been working on a cryptographic (POT) protocol in Java for my master's thesis.
It uses cryptographic Pairings and therefore makes use of an external java library called jPBC (http://gas.dia.unisa.it/projects/jpbc/).
As I want one side of the protocol to run on a mobile device, I 've made a simple GUI in Android ADT with a single button that starts the protocol. However, the protocol runs about 200 times slower on my phone (Samsung S2 plus, ARM Cortex A9 32 bit processor) than on my laptop (Intel Core i7, but only using half a core). As the difference in processors might explain a factor 10 but certainly not a factor 100/200 I figured the difference in performance would be due to the inefficiency of the jPBC library on Android.
The jPBC library makes extensive use of BigInteger for all of its calculations so I decided to investigate if BigInteger could be extra inefficient on android (it's not super efficient on normal computers either). I executed a loop of 1200 bit BigInteger calculations on the phone and the laptop. I've come up with some results that I cannot explain:
10^6 Additions and subtractions take 205ms on laptop, 48 025ms on phone (x 200).
10^5 Multiplications and divisions take 814 ms on laptop and 13 705ms on phone (x 17).
10^3 Modular Exponentiations (modPow) take 5079ms on laptop and 22 153ms on phone (x 4.5)
As there is much to be said about these results, I'll just stick to this simple question:
Can anyone either reproduce these results and confirm that BigInteger addition is immensively slow on Android, or tell me what I've done wrong?
The code:
Java method:
public static long bigIntCalculations(){
System.out.println("starting bigIntCalculations");
Random random = new Random();
BigInteger start = new BigInteger(1200, random);
BigInteger temp = new BigInteger(start.toString());
long nOfIterations = 1000000L;
long time1 = System.nanoTime()/1000000;
for (long i = 0; i < nOfIterations; i++) {
start = start.add(temp);
start = start.subtract(temp);
}
long result = (System.nanoTime()/1000000)-time1;
System.out.println(result);
return result;
}
In Android:
/** Called when the user clicks the button1*/
public void runProtocol(View view) {
long duration = Test.bigIntCalculations();
String result ="Calculations take: " + duration + " ms";
Intent intent = new Intent(this, DisplayMessageActivity.class);
intent.putExtra(CALC_RESULT, result);
startActivity(intent);
}
Many thanks!
Only x4.5 for 1200-bit modular exponentiation is a terrific result, considering the underpowered hardware. It's also a testament to how bad the JDK's BigInteger implementation is.
The Android standard library uses OpenSSL BigNum for some under-the-hood operations. Without peeking, I would guess modular exponentiation and modular inverse are handled in native code, while simpler arithmetic is handled in Java code.
For tight loops of addition and multiplication you would be generating lots of garbage, and GC performance disparity between platforms could also be having a large impact -- my guess is that some warmup + a much smaller benchmark will show closer results.
My performance pain point is modular exponentiation, so I'm pretty happy with Android performance. If that were not the case, I'd be looking at porting libraries such as gmp4j or gmp-java (two libraries by that name) to Android. Two of these provide a BigInteger-compatible API. Another offers a more direct mapping to GMPLib, which can be ideal in terms of memory management (GMP numbers are mutable).
Is possible to compare a voice with already recorded voice in the phone.Based on the comparison we can rate like Good, Very Good , Excellent etc. Most closed sound get high rating.
Anybody know is it possible in Android?
Help is highly appreciable.
For a general audio processing library I can recommend marsyas. Unfortunately the official home page is currently down.
Marsyas even provides a sample android application. After getting a proper signal analysis framework, you need to analyse your signal. For example, the AimC implementation for marsyas can be used to compare voice.
I recommend installing marsyas on your computer and fiddle with the python example scripts.
For your voice analysis, you could use a network like this:
vqNetwork = ["Series/vqlizer", [
"AimPZFC/aimpzfc",
"AimHCL/aimhcl",
"AimLocalMax/aimlocalmax",
"AimSAI/aimsai",
"AimBoxes/aimBoxes",
"AimVQ/vq",
"Gain/g",
]
This network takes your audio data and transforms it as it would be processed by a human ear. After that it uses vector quantization to reduce the many possible vectors to very specific codebooks with 200 entries. You can then translate the output of the network to readable characters (utf8 for example), which you then can compare using something like string edit distances (e.g. Levenshtein distance).
Another possibility is to use MFCC (Mel Frequency Cepstral Coefficients) for speech recognition which marsyas supports as well and use something, for example Dynamic Time Warping, to compare the outputs. This document describes the process pretty well.
Using 'Musicg' library you can compare two voice (.wav format) files.
use Wave object to load the wave file to instantiate in pgm.
here using FingerPrintSimilarity
function you pass pre recorded wav files to get the output.
But you should know that "musicg" library deals only with .wav format files, so if you have a an .mp3 file for example you need to convert it to a wave file first.
android gradle dependency:
implementation group: 'com.github.fracpete', name: 'musicg', version: '1.4.2.2'
for more:
https://github.com/loisaidasam/musicg
sample code:
private void compareTempFile(String str) {
Wave w1 = new Wave(Environment.getExternalStorageDirectory().getAbsolutePath()+"/sample1.wav");
Wave w2 = new Wave(Environment.getExternalStorageDirectory().getAbsolutePath()+"/sample2.wav");
println("Wave 1 = "+w1.getWaveHeader());
println("Wave 2 = "+w2.getWaveHeader());
FingerprintSimilarity fpsc1 = w2.getFingerprintSimilarity(w1);
float scorec = fpsc1.getScore();
float simc= fpsc1.getSimilarity();
tvSim.setText(" Similarity = "+simc+"\nScore = "+scorec);
println("Score = "+scorec);
println("Similarity = "+simc);
}