I ran the Monkey tool (the tool to perform stress testing on Android application) and I got some script file that have this form:
type= raw events
count= -1
speed= 1.0
start data >>
LaunchActivity(com.amaze.filemanager,com.amaze.filemanager.activities.MainActivity)
DispatchPointer(6934862,6934862,0,517.0,124.0,0.0,0.0,0,1.0,1.0,0,0)
DispatchPointer(6934862,6934867,1,520.041,127.07279,0.0,0.0,0,1.0,1.0,0,0)
GUIGen(3)
DispatchTrackball(-1,6945789,2,1.0,-3.0,0.0,0.0,0,1.0,1.0,0,0)
...
I would like to re-execute such sequence of events again, using the produced script.
How can I do that?
You will need adb for the same. First you will create the file on your local
monkey.script
type= raw events
count= -1
speed= 1.0
start data >>
LaunchActivity(com.amaze.filemanager,com.amaze.filemanager.activities.MainActivity)
DispatchPointer(6934862,6934862,0,517.0,124.0,0.0,0.0,0,1.0,1.0,0,0)
DispatchPointer(6934862,6934867,1,520.041,127.07279,0.0,0.0,0,1.0,1.0,0,0)
GUIGen(3)
DispatchTrackball(-1,6945789,2,1.0,-3.0,0.0,0.0,0,1.0,1.0,0,0)
Then you will copy it to your phone
adb push ./monkey.script /sdcard/Download
And then you can run the script from adb
$ adb shell monkey -f /sdcard/Download/monkey.script 1
Events injected: 4
## Network stats: elapsed time=10ms (0ms mobile, 0ms wifi, 10ms not connected)
Related
I am working on one project requires obtaining the complete app package name inside kernel mode. I realized the package name is also the process name inside kernel. However, the task_struct->comm (process name) can only give me 15 characters long.
Also, fs/proc/base.c proc_get_cmdline() can return the full process name but it is private function. I try to export proc_get_cmdline() to public and invoke from my loadable kernel module, but it always crash when I invoke the public proc_get_cmdline().
Is there any way I can get the complete package name inside kernel? Like read from proc/pid/cmdline, read from mm_struct, etc. Appreciate any code example.
You are not supposed to call proc_pid_cmdline().
It is a non-public function in fs/proc/base.c:
static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task)
However, what it does is simple:
get_cmdline(task, m->buf, PAGE_SIZE);
That is not likely to return the full path though and it will not be possible to determine the full path in every case. The arg[0] value may be overwritten, the file could be deleted or moved, etc. A process may exec() in a way which obscures the original command line, and all kinds of other maladies.
A scan of my opensuse 12.3 system /proc/*/cmdline turns up all kinds of less-than-useful results:
/proc/1/cmdline
/sbin/init showopts
/proc/10/cmdline
/proc/11/cmdline
/proc/1163/cmdline
/sbin/dhclient6 -6 -cf /var/lib/dhcp6/dhclient6.eth0.conf -lf /var/lib/dhcp6/dhclient6.eth0.lease -pf /var/run/dhclient6.eth0.pid -q eth0
/proc/12/cmdline
/proc/13/cmdline
/proc/14/cmdline
/proc/15/cmdline
/proc/16/cmdline
/proc/17/cmdline
/proc/1710/cmdline
/sbin/dhcpcd --netconfig -L -E -HHH -c /etc/sysconfig/network/scripts/dhcpcd-hook -t 0 -h del1-dhp-32429 eth0
/proc/172/cmdline
/proc/185/cmdline
/proc/186/cmdline
/proc/187/cmdline
/proc/19/cmdline
/proc/2/cmdline
/proc/20/cmdline
/proc/21/cmdline
/proc/22/cmdline
/proc/23/cmdline
/proc/25/cmdline
/proc/254/cmdline
/proc/255/cmdline
/proc/26/cmdline
/proc/2671/cmdline
/usr/lib/upower/upowerd
/proc/2674/cmdline
/usr/lib/polkit-1/polkitd --no-debug
/proc/27/cmdline
/proc/2727/cmdline
/usr/lib/udisks2/udisksd --no-debug
/proc/28/cmdline
/proc/285/cmdline
/usr/lib/systemd/systemd-journald
/proc/286/cmdline
/proc/288/cmdline
/proc/29/cmdline
/proc/2913/cmdline
/usr/sbin/cron -n
/proc/2924/cmdline
/usr/sbin/sshd -D
/proc/3/cmdline
/proc/3023/cmdline
/usr/lib/postfix/master
/proc/3090/cmdline
pickup -l -t fifo -u
/proc/3091/cmdline
qmgr -l -t fifo -u
/proc/31/cmdline
/proc/311/cmdline
/usr/lib/systemd/systemd-udevd
/proc/3132/cmdline
/usr/lib/vmware/bin/vmware-vmblock-fuse -o subtype=vmware-vmblock,default_permissions,allow_other /var/run/vmblock-fuse
/proc/3168/cmdline
/usr/sbin/vmware-authdlauncher
/proc/32/cmdline
Works for me in openSUSE 12.3:
for I in /proc/*/cmdline; do echo $I; cat $I | tr '\000' ' '; echo; done
I am seeking a way to measure launch times of general apps in Android, and happen to know that
adb logcat -b events | grep am_activity_launch_time
might be one answer.
But I failed to find out what duration the command above shows (i.e., from what event to what event). Any help?
You can use this command
cmd0=add logcat -c
to clear the logs and then execute the below command
cmd1 = "grep am_activity_launch_time Example.txt | grep com.example.example| cut -d ',' -f4-4 > Example.csv"
The values are then saved in a csv file.
Then you can the python commands
os.system(cmd0);
os.system(cmd2);
Then use matplotlib to plot the graph from the generated csv files.
axes=plt.gca()
axes.set_xlim([1,20])
axes.set_ylim([0,4000])
plt.title("Performance Analysis ")
plt.ylabel('Time in milliseconds')
plt.xlabel('Number of itirations (DEVICE:Samsung Galaxy Note 4)')
data1=np.genfromtxt("Example.csv)"
plt.plot(data1,label="Example",linewidth=2.0,color='m')
plt.legend(bbox_to_anchor=(1,1),loc=1,borderaxespad=0.)
plt.show()
Once this is done execute this file in the python cmd.
adb logcat -b all | egrep -n --color 'Displayed *'
12461:11-26 22:43:05.316 1110 1167 I ActivityTaskManager: Displayed mobi.goldendict.android.free/mobi.goldendict.android.GoldenDict: +1s494ms
You could measure app launches time in android by this.
I have 2 errors in logcat.
Function: selinux_android_load_priority [0], There is no sepolicy file
04-11 10:58:13.837: E/SELinux(10101): Function: selinux_android_load_priority , loading version is VE=SEPF_SGH-I337M_4.3_0022
It's not fatal, my app seems to be fine.
Any idea what is the cause, and how do I fix it? Just can have Error Logs in my app!
I don't know how to get rid of those messages. But they do prevent the Android NDK ndk-gdb script from working. I found this question while searching for a way to get the debugger working after getting this error:
ERROR: Could not setup network redirection to gdbserver?
Maybe using --port=<port> to use a different TCP port might help?
This seems to be an issue with some phones - possibly Samsung phones, or at least the one that I am working with is a Samsung Galaxy Note 2. Certain commands (such as run-as) come with these selinux warning messages in stderr output.
The ndk-gdb script parses output from shell commands run on a device to determine facts like the path of the data directory for the package that it is debugging. The selinux messages interfere with that collection. To fix that problem, edit $NDK_HOME/ndk-gdb and make this change:
diff --git a/ndk-gdb b/ndk-gdb
index 537808e..c8561e5 100755
--- a/ndk-gdb
+++ b/ndk-gdb
## -620,7 +620,7 ## else
fi
# Find the <dataDir> of the package on the device
-adb_var_shell2 DATA_DIR run-as $PACKAGE_NAME /system/bin/sh -c pwd
+adb_var_shell DATA_DIR "run-as $PACKAGE_NAME /system/bin/sh -c pwd 2>/dev/null"
if [ $? != 0 -o -z "$DATA_DIR" ] ; then
echo "ERROR: Could not extract package's data directory. Are you sure that"
echo " your installed application is debuggable?"
I'm using a quad-core smartphone.
I want to know how to force three cores or two cores offline. Thus I can measure the performance of different active core counts at different frequency level running a specified benchmark.
I can manage the core frequency through "userspace governor". However, I can't shut down cores. When I run benchmarks, the idle cores will wake up.
I've connect to the phone using "adb shell". I can get the root access either.
Could anyone help to solve this problem? Thanks in advance.
run following commands to turn off cpu1, cpu2, cpu3.
adb root
adb shell stop mpdecision
adb shell
echo "0" > /sys/devices/system/cpu/cpu1/online
echo "0" > /sys/devices/system/cpu/cpu2/online
echo "0" > /sys/devices/system/cpu/cpu3/online
I had to disable hotplug first for the Galaxy-S7 device to prevent CPUs to return to online state:
echo 0 > /sys/devices/system/cpu/cpuhotplug/enabled
On my device each write access to this file cause CPU state reset. So, check existing value first to not run into troubles:
if [[ 0 != $(cat /sys/devices/system/cpu/cpuhotplug/enabled) ]]; then
echo 0 > /sys/devices/system/cpu/cpuhotplug/enabled
fi
You can force "online" status by changing permissions for the corresponding file:
# Without stopping this service, the following approach will fail
# You can run it after. This will increase battery life. So, I suggest to run it.
stop mpdecision
# Make the file writable
chmod 664 /sys/devices/system/cpu/cpu0/online
# Make the core always offline
echo 0 > /sys/devices/system/cpu/cpu0/online
# Make the file read-only.
# Now "online" status will not be changed by external apps
chmod 444 /sys/devices/system/cpu/cpu0/online
# Run the service again
start mpdecision
You have to run all that stuff for every cpu core.
I'd suggest to create a bash script, like that:
...
set_core_offline () {
local core=$1
chmod 664 /sys/devices/system/cpu/cpu$core/online
echo 0 > /sys/devices/system/cpu/cpu$core/online
chmod 444 /sys/devices/system/cpu/cpu$core/online
}
# Works for 4-core CPUs
set_cores_offline () {
set_core_offline 0
set_core_offline 1
set_core_offline 2
set_core_offline 3
}
...
And, of course, this solution is not perfect. Look again, at the code snippet:
echo 0 > /sys/devices/system/cpu/cpu0/online
chmod 444 /sys/devices/system/cpu/cpu0/online
These are two separate commands. After execution of the first one, an external app might change "online" status to "1" again. After that the second command will fix this status as unchangeable. So, the clearest solution would be to wrap these 2 commands into a loop and check the status until we'd get desired results.
I am logging the data coming from top and putting it into a circular set of files. I am not executing top for one set of data and then rerunning for the next set, but instead using a read time out to specify when to go from one log file to the next. This is primarily done this way to remove the startup CPU load cost every time top is executed. The shell script file's name is toplog.sh and looks similar to this:
#!/data/data/com.spartacusrex.spartacuside/files/system/bin/bash
date
echo " Logging started."
fileCmp()
{
test `ls -lc "$1" | sed -n 's/\([^ ]* *\)\{4\}\([0-9]*\).*$/\2/;p'` $2 $3
}
oldest()
{
ls -rc $1 2> /dev/null |head -1
}
file=`oldest /mnt/sdcard/toplog.\*.gz`
echo " Oldest file is $file"
if [ -z "$file" ]; then
x=0
else
file=${file%%.gz}
file=${file##*.}
x=$file
fi
echo " x=$x"
top -d 20 -b | \
while true; do
file=/mnt/sdcard/toplog.$x.gz
while read -t 5 line; do
echo "$line"
done | gzip -c > $file
if fileCmp "$file" -le 300; then
date
echo " Failure to write to file '$file'."
exit
fi
x=$((($x+1)%10))
sleep 14
done
I execute this using nohup so that when the shell dies, this process still runs, like so:
$ nohup ./toplog.sh
But there's a problem. top terminates when I exit the shell session that executed that command, and I'm not exactly sure why. Any ideas?
To clarify, I'm logging on a Android phone. The tools are limited in functionality (i.e. lack some of these switches) and is why I am using top as it contains the output I want.
Version of busybox I'm using is:
BusyBox 1.19.2 (2011-12-12 12:59:36 GMT)
Installed when I installed Terminal IDE.
BTW, this phone is not rooted. I'm trying to track down a failure when my phone responds as if the CPU has spiked and won't go down.
Edit:
Well, I found a workaround. But the reason is a bit hazy. I think it has to do with process management and smells of a bug in the busybox ver that I'm using that was missed during regression testing.
The workaround is to wrap top with a useless loop structure like this: while true; do top; done. Through testing, top never gets killed and never gets respawned, but by wrapping it up, it isn't killed.
Any insights on this?
going to sound stupid, but change your startup command from
nohup ./toplog.sh
to
nohup ./toplog.sh &
the & makes it run as a background process further removing it from the terminal stack.
Running the bash internal command "disown" on your script's process before logging off may prevent it from being signaled.