Long time ago I had written a C++ library to parse ARFF files for one of my Machine-Learning projects. Today, I'm making the code open-source! Here's the link to the code hosted on github: https://github.com/teju85/ARFF. This also comes with doxygen documentation for the API exposed by this library and also has unit-tests (written using google-test) for CYA.
Monday, September 5, 2011
Sunday, August 28, 2011
Iterator for templated STL containers in C++
I realized this today! The following code almost always will give compilation error.
std::vector::const_iterator itr;
And the compilation error (with g++ version 3.4.6) will be as vague as:
error: expected `;' before "itr"
The solution is to just do the following:
typename std::vector::const_iterator itr;
Sunday, July 31, 2011
Getting (approx?) memory usage information on linux
Here's the code for doing so: (Tested on Ubuntu 10.10)
Hope this helps!
#include <unistd.h>
#include <stdio.h>
int processMemUsage() {
int vm = 0;
FILE* fp = fopen("/proc/self/stat", "r");
if(fp == NULL) {
return vm;
}
int dummy;
char cmd[128], state[8];
fscanf(fp, "%d%s%s%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",
&dummy, cmd, state, &dummy, &dummy, &dummy, &dummy,
&dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
&dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
&dummy, &dummy, &dummy);
unsigned long vmSize;
fscanf(fp, "%lu", &vmSize);
fclose(fp);
vm = (int) (vmSize >> 10);
return vm;
}
Hope this helps!
Thursday, July 28, 2011
How to request 'super user' permission from your app?
NOTE: This blog assumes that you have installed Superuser application installed on your device! Also, I'm not responsible for any bricked devices!
Process p;
try {
p = Runtime.getRuntime().exec("su");
}
catch(IOException e) {
e.printStackTrace();
}
This will pop up a window from 'Superuser' application which will ask user to whether allow your app to be given 'su' permissions or not. Users can either 'Allow' or 'Deny' and also set 'Remember this option' on this window.
Hope this helps!
Hope this helps!
AdbCommandRejectedException!
Sometimes, adb goes crazy on my Win7. If I open 'ddms' (to view logcat messages), I wont see any messages at all! If I look into the 'Command Window', I see the above exception being raised in it. Apparently, the work-around this is to do the following:
- Un-plug the USB cable.
- Kill the adb-server (adb kill-server)
- Start the adb-server (adb start-server)
- Plug in the USB
Hope this helps!
Sunday, July 24, 2011
Camera shutter sound on CM7!
Due to legal issues in some countries (see this issue) cyanogenmod doesn't support any settings for enabling/disabling camera shutter sound (It is enabled by default!). However, there's a system property which one can set in order to turn off the shutter sound. But, unfortuantely for this you need to install android SDK on your system and plug USB cable to your phone and connect it to your PC. (Also, do not forget to 'enable USB debugging'!!).
adb shell setprop persist.camera.shutter.disable 1
NOTE:
I'm not responsible for any damages/law-suites caused (whatsoever), by disabling the shutter sound of your phone's camera!
Tuesday, July 19, 2011
Measuring read/write BW of sdcard(s) on your android phones
I needed a quantitative way to measure the performance of the sd-card on my LG Optimus 2X. Hence I wrote the tool 'sd-speed'. Currently, this tool is supported only on linux and windows platforms. The project is hosted on github at the following location: 'git@github.com:teju85/sd-speed.git'. I have released it with the WTFPL (do What The Fuck you want to Public License).
Here are the results of running my program on my 'external sd-card', 'internal sd-card' and on 'phone memory' respectively: (Phone: LG O2X, CM7)
External sd-card
$ ./sdCardSpeedTest.sh /mnt/sdcard
NOTE: Test might take about 5-10 min depending on your sd-card speed!
Please be patient during this time...
Evaluating write-BW...
100000000 bytes transferred in 26.371 secs (3792044 bytes/sec)
100000000 bytes transferred in 19.656 secs (5087505 bytes/sec)
100000000 bytes transferred in 20.697 secs (4831618 bytes/sec)
100000000 bytes transferred in 20.086 secs (4978592 bytes/sec)
100000000 bytes transferred in 53.975 secs (1852709 bytes/sec)
100000000 bytes transferred in 28.934 secs (3456141 bytes/sec)
Write BandWidth: 3.81448 MBps
Evaluating read-BW...
100000000 bytes transferred in 18.844 secs (5306728 bytes/sec)
100000000 bytes transferred in 17.818 secs (5612302 bytes/sec)
100000000 bytes transferred in 17.331 secs (5770007 bytes/sec)
100000000 bytes transferred in 17.301 secs (5780012 bytes/sec)
100000000 bytes transferred in 17.306 secs (5778342 bytes/sec)
100000000 bytes transferred in 17.310 secs (5777007 bytes/sec)
Read BandWidth: 5.40803 MBps
Cleaning up all the temporary files...
Internal sd-card
$ ./sdCardSpeedTest.sh /mnt/emmc
NOTE: Test might take about 5-10 min depending on your sd-card speed!
Please be patient during this time...
Evaluating write-BW...
100000000 bytes transferred in 9.372 secs (10670081 bytes/sec)
100000000 bytes transferred in 6.579 secs (15199878 bytes/sec)
100000000 bytes transferred in 6.252 secs (15994881 bytes/sec)
100000000 bytes transferred in 6.321 secs (15820281 bytes/sec)
100000000 bytes transferred in 6.532 secs (15309246 bytes/sec)
100000000 bytes transferred in 6.516 secs (15346838 bytes/sec)
Write BandWidth: 14.0415 MBps
Evaluating read-BW...
100000000 bytes transferred in 5.168 secs (19349845 bytes/sec)
100000000 bytes transferred in 5.038 secs (19849146 bytes/sec)
100000000 bytes transferred in 4.661 secs (21454623 bytes/sec)
100000000 bytes transferred in 4.671 secs (21408691 bytes/sec)
100000000 bytes transferred in 4.694 secs (21303792 bytes/sec)
100000000 bytes transferred in 4.693 secs (21308331 bytes/sec)
Read BandWidth: 19.8165 MBps
Cleaning up all the temporary files...
Phone memory
$ ./sdCardSpeedTest.sh /data/local
NOTE: Test might take about 5-10 min depending on your sd-card speed!
Please be patient during this time...
Evaluating write-BW...
100000000 bytes transferred in 6.876 secs (14543339 bytes/sec)
100000000 bytes transferred in 8.566 secs (11674060 bytes/sec)
100000000 bytes transferred in 8.565 secs (11675423 bytes/sec)
100000000 bytes transferred in 6.783 secs (14742739 bytes/sec)
100000000 bytes transferred in 7.617 secs (13128528 bytes/sec)
100000000 bytes transferred in 8.168 secs (12242899 bytes/sec)
Write BandWidth: 12.3989 MBps
Evaluating read-BW...
100000000 bytes transferred in 5.537 secs (18060321 bytes/sec)
100000000 bytes transferred in 5.641 secs (17727353 bytes/sec)
100000000 bytes transferred in 5.274 secs (18960940 bytes/sec)
100000000 bytes transferred in 5.275 secs (18957345 bytes/sec)
100000000 bytes transferred in 5.268 secs (18982536 bytes/sec)
100000000 bytes transferred in 5.273 secs (18964536 bytes/sec)
Read BandWidth: 17.7468 MBps
Cleaning up all the temporary files...
I have compiled these results in a tabular format for quick comparison.
| Location | Write BW (MBps) | Read BW (MBps) |
|---|---|---|
| External sd-card | 3.81 | 5.41 |
| Internal sd-card | 14.04 | 19.82 |
| Phone Memory | 12.40 | 17.75 |
Subscribe to:
Comments (Atom)