How to resolve the usage of the Gfx dev memory - android

I am using adb shell dumpsys meminfo to get informations about the current memory usage of my app.
The Gfx dev memory increases frequently and seems to cause memory leaks.
Is there an adb command or and Android Studio function to get more informations about the Gfx dev memory and where it is used/referenced?
Pss Private Private Swapped Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 17380 17324 0 0 36864 19380 17483
Dalvik Heap 30366 29796 0 0 50519 48334 2185
Dalvik Other 672 672 0 0
Stack 220 220 0 0
Gfx dev 4704 4704 0 0
Other dev 5 0 4 0
.so mmap 2109 356 872 0
.jar mmap 1 0 0 0
.apk mmap 707 0 420 0
.ttf mmap 35 0 4 0
.dex mmap 7442 0 7400 0
.oat mmap 2712 0 948 0
.art mmap 1458 948 72 0
Other mmap 42 4 0 0
EGL mtrack 13888 13888 0 0
GL mtrack 8924 8924 0 0
Unknown 172 172 0 0
TOTAL 90837 77008 9720 0 87383 67714 19668
Additional Info:
Gfx dev is not available for Kitkat devices and below.

You can use below command to get more info on Gfx;
adb shell dumpsys gfxinfo

Related

pidstat command in android?

Is there any substitute for pidstat command between the supported commands in busybox? I need to run pidstat on my Android device. I have busybox but pidstat is not supported.
Busybox has no such command. It does however provide the top command which can be used in a similar fashion.
top
top [-b] [-nCOUNT] [-dSECONDS] [-m]
Provide a view of process activity in real time. Read the status of all processes from /proc each SECONDS and display a screenful of them.
Where:
$ top -bn10 -p1
-b - shows top in batch mode
n10 - shows 10 iterations and then stops
-p1 - shows PID 1
Example
$ top -bn10 -p1
top - 23:19:27 up 5:30, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1015500 total, 414600 free, 88176 used, 512724 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 737992 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 125776 4240 2616 S 0.0 0.4 0:04.59 systemd
You can then use grep to filter this output like so:
$ top -bn10 -p1 | grep -A1 "PID"
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 125776 4240 2616 S 0.0 0.4 0:04.61 systemd
--
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 125776 4240 2616 S 0.0 0.4 0:04.61 systemd
--
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 125776 4240 2616 S 0.0 0.4 0:04.61 systemd
--
You can of course manipulate top so that it shows a similar set of columns to what pidstat shows.

Jack server failed to (re)start

I am trying a build of Android N, but I am constantly getting this error :
15:37:13 FAILED: /bin/bash -c "(prebuilts/sdk/tools/jack-admin install-server prebuilts/sdk/tools/jack-launcher.jar prebuilts/sdk/tools/jack-server-4.8.ALPHA.jar 2>&1 || (exit 0) ) && (JACK_SERVER_VM_ARGUMENTS=\"-Dfile.encoding=UTF-8 -XX:+TieredCompilation\" prebuilts/sdk/tools/jack-admin start-server 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update server prebuilts/sdk/tools/jack-server-4.8.ALPHA.jar 4.8.ALPHA 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-2.28.RELEASE.jar 2.28.RELEASE || exit 47; prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-3.36.CANDIDATE.jar 3.36.CANDIDATE || exit 47; prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-4.7.BETA.jar 4.7.BETA || exit 47 )"
15:37:13 Jack server already installed in "/srv/jenkins/.jack-server"
15:37:13 Launching Jack server java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=/tmp -Dfile.encoding=UTF-8 -XX:+TieredCompilation -cp /srv/jenkins/.jack-server/launcher.jar com.android.jack.launcher.ServerLauncher
15:37:13 Jack server failed to (re)start, try 'jack-diagnose' or see Jack server log
15:37:13 No Jack server running. Try 'jack-admin start-server'
15:37:13 No Jack server running. Try 'jack-admin start-server'
I put some logs in the jack-admin code and I am getting the following error, when I do ./jack-admin start-server.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to 127.0.0.1 port 8077: No route to host
isServerRunning : Curl code : 7
Launching Jack server java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=/tmp -Dfile.encoding=UTF-8 -XX:+TieredCompilation -cp /srv/jenkins/.jack-server/launcher.jar com.android.jack.launcher.ServerLauncher
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to 127.0.0.1 port 8077: No route to host
waitServerStarted : curl code : 7
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to 127.0.0.1 port 8077: No route to host
waitServerStarted : curl code : 7
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to 127.0.0.1 port 8077: No route to host
Can someone please help?
EDIT
Jack server logs are clean, there are no exceptions or errors.
The default ports 8076 and 8077 get blocked as seen in netstat -nlp, which indicates the server is indeed started.
tcp6 0 0 127.0.0.1:8076 :::* LISTEN 19180/java
tcp6 0 0 127.0.0.1:8077 :::* LISTEN 19180/java
The machine I am building the code upon, is behind a proxy.
When I was getting Curl error 7 it was accompanied by an SSL error when running jack-diagnose. The following solution worked for me:
Edit java.security file under /etc/java-8-openjdk/security/
Remove TLSv1, TLSv1.1 from jdk.tls.disabledAlgorithms
Restart the jack server:
cd <your-aosp-home-dir>/prebuilts/sdk/tools/
./jack-admin kill-server
./jack-admin start-server
Try changing service and admin ports both in .jack-settings and .jack-server/config.properties and make sure they match.
Jack server may not be able to use the default ports, especially if you are on a server machine where there are more than one user trying to use Jack.

Memory Leak LibGDX ANdroid

I am making a live wallpaper app with libgdx in which I change the assets depending on the time. For. e.g from 6am to 6pm I have the "morning graphics" after that I have "evening graphics" from 6pm to 6am.
The way I have structured the Assets is as follows
I have 12 static arrays of type AtlasRegion 1 static Texture Region variable and 1 static texture variable.
I have two static functions loadMorning() and loadEvening() for loading the assets.
In the funcions I load as follows
For all arrays if they are not null do array.clear()
then load the regions. Dispose the TextureRegion variable and set texture variable to null before resetting their values.
The thing that is happening is that after every change of assets the memory seems to increasing
As a user's perepective I am using this app to see the memory
https://play.google.com/store/apps/details?id=mem.usage&hl=en
When I start my app for the first time .. it is showing as 68MB in the app ,
Day1 Morning Stats
Day 1
ID Heap Size Allocated Free %Used #Objects
1 10.812 MB 3.186 MB 7.626 MB 29.47% 45,405
Pss Private Private Swapped Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 0 0 0 0 16620 4285 38
Dalvik Heap 8692 8604 0 0 11072 3293 7779
Dalvik Other 1374 1216 0 0
Stack 96 96 0 0
Other dev 33016 4908 4 0
.so mmap 1266 692 136 0
.apk mmap 160 0 116 0
.dex mmap 287 20 8 0
Other mmap 5 4 0 0
Unknown 1431 1412 0 0
TOTAL 46327 16952 264 0 27692 7578 7817
Objects
Views: 1 ViewRootImpl: 0
AppContexts: 3 Activities: 0
Assets: 2 AssetManagers: 2
Local Binders: 11 Proxy Binders: 19
Death Recipients: 0
OpenSSL Sockets: 0
SQL
MEMORY_USED: 0
PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
Day 1 Evening Stats
adb log after evening assets are loaded
D/dalvikvm(2451): GC_FOR_ALLOC freed 1619K, 71% free 3281K/11072K, paused 14ms, total 15ms
D/dalvikvm(2451): GC_FOR_ALLOC freed 1517K, 71% free 3281K/11072K, paused 11ms, total 11ms
I/dalvikvm-heap(2451): Grow heap (frag case) to 6.548MB for 1331595-byte allocation
D/dalvikvm(2451): GC_CONCURRENT freed 1862K, 67% free 4127K/12376K, paused 2ms+2ms, total 13ms
D/dalvikvm(2451): GC_EXPLICIT freed 2384K, 74% free 3268K/12376K, paused 2ms+3ms, total 27ms
ID Heap Size Allocated Free %Used #Objects
1 10.816 MB 3.191 MB 7.625 MB 29.50% 45,525
This adb log right after change
Pss Private Private Swapped Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 0 0 0 0 16728 4346 29
Dalvik Heap 1654 1576 0 0 11076 3348 7728
Dalvik Other 1435 1296 0 0
Stack 100 100 0 0
Other dev 63332 32644 4 0
.so mmap 1110 692 116 0
.apk mmap 7 0 4 0
.dex mmap 586 20 368 0
Other mmap 5 4 0 0
Unknown 1504 1488 0 0
TOTAL 69733 37820 492 0 27804 7694 7757
Objects
Views: 1 ViewRootImpl: 0
AppContexts: 3 Activities: 0
Assets: 2 AssetManagers: 2
Local Binders: 10 Proxy Binders: 17
Death Recipients: 0
OpenSSL Sockets: 0
SQL
MEMORY_USED: 0
PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
The memory showing in the app is now 117MB
This keeps increasing , next morning the size shown in app is about 150 MB.
I need some pointers where to look to understand this better.
One remedy against resource leaks in the code that you cannot control is restarting the application. You either kill the process or do System.exit().
But before doing that, you have to schedule a restart.
Please note that although different android releases should all have been compatible, they are not compatible in application restart behavior. At least, v2.x and v4.0 did differ (in v2.x System.exit() caused application restart with the topmost activity closed), not sure about the latest releases.

Using dd to change a hex value in Android script

What I am doing is trying to build a script that can be flashed in a custom android recovery like TWRP or ClockWorkMod.
The beginning: So using this command at a ADB shell prompt will modify the partition in which the locked or unlocked flag lives for the bootloader on many HTC devices-
echo -ne '\x00\x00\x00\x00' | dd of=/dev/block/mmcblk0p3 bs=1 seek=33796
I am trying to be able to do the same thing from recovery (Aroma script, but shouldn't matter)
The issue is that while CWM recovery can use these 2 simple lines to complete it:
echo -ne "\000\000\000\000" > /tmp/data_new
dd if=/tmp/data_new of=/dev/block/mmcblk0p3 bs=1 seek=33796 conv=notrunc
TWRP environment cannot. The issue seems to be with the quotes and/or the backslashes in the echo.
To get around this I have tried to package a file called data_new with the output of the echo (which is just 4 nul bytes) and then use the DD command, but it doesn't read the data_new correctly because I get 0+0 records in and 0+0 records out. I have also tried writing a shell script to execute the commands, but same issue in TWRP.
To add a layer of complexity the commands in the aroma script are quoted like this:
run_program("/sbin/busybox", "dd", "if=/tmp/data_new", "of=/dev/block/mmcblk0p3" etc
I have tried many combinations of single and double quotes and leading backticks but still fails.
Bottom line - Is there a different way of expressing 4 zeroed out hex values?
The reverse is not a problem because it's echo to Lock is this: (no backticks and quotes on HTCU don't come into play, since echo output is the same with or without)
echo -ne "HTCU" | dd of=/dev/block/mmcblk0p3 bs=1 seek=33796
The issue is in getting a DD command to change the HTCU values to 4 zeroes without using backticks in the echo.
Can anyone help?
PS - I think that this could be done by pulling the partition with DD to /tmp and then find the HTCU string (48 54 43 55) and replace with 00 00 00 00, but the partition is large with only a small amount of data actually in it so the process would take a while and the script would be more complicated than I think I could write, as yes I am a noob to coding.
Thanks
EDIT: I tried using /dev/null as that seems like a good idea and a way to avoid echo altogether. However that fails as well. Same result as using a preloaded 4 nul byte file. I know it is not the recovery as the /dev/null method produced the same failure in a ADB shell.
0+0 records in
0+0 records out
0 bytes copied
Here is the full string of code:
run_program("/sbin/busybox", "dd", "if=/dev/null", "of=/dev/block/mmcblk0p3", "bs=1", "count=4", "seek=33796", "conv=notrunc")
After dd, what might be the best alternate way to do a quick hex edit?
This is my requirement:
writting into parttion mmcblk0p3 at offset 0x8404. HTCU for unlocked, HTCL for relocked or 0x00000000 for locked
Thanks again
Could you not read directly from /dev/null reading 4 bytes; I believe the syntax is:
dd if=/dev/null of=/dev/block/mmcblk0p3 bs=1 count=4 seek=33796 conv=notrunc
Please double check the above code, I've not used dd in a while.
Update
After playing around with dd I managed to get it to write 4 null bytes to a position I specified within a file:
Firstly create the example file:
$ dd if=/dev/urandom of=randomfile bs=64 count=1
1+0 records in
1+0 records out
64 bytes (64 B) copied, 4.5401e-05 s, 1.4 MB/s
$ od -b randomfile
0000000 105 342 131 116 213 371 352 344 217 236 320 106 010 154 074 375
0000020 360 215 014 203 030 357 144 053 302 265 012 310 217 362 236 303
0000040 156 033 266 035 303 061 262 055 253 102 222 037 372 105 230 321
0000060 117 277 322 277 166 174 316 176 010 202 302 151 120 045 120 334
0000100
Then zeroing 4 bytes, skipping the first two bytes:
$ dd if=/dev/zero of=randomfile seek=2 bs=1 count=4 conv=notrunc
4+0 records in
4+0 records out
4 bytes (4 B) copied, 4.4779e-05 s, 89.3 kB/s
$ od -b randomfile
0000000 105 342 000 000 000 000 352 344 217 236 320 106 010 154 074 375
0000020 360 215 014 203 030 357 144 053 302 265 012 310 217 362 236 303
0000040 156 033 266 035 303 061 262 055 253 102 222 037 372 105 230 321
0000060 117 277 322 277 166 174 316 176 010 202 302 151 120 045 120 334
0000100
This should extend to your larger file.
dd if=/dev/null of=/dev/block/mmcblk2p3 bs=1 count=4 seek=33796 conv=notrunc
This above Ans worked for me... Thanks for the Ans.
dd if=/dev/null of=/dev/block/mmcblk2p3 bs=1 count=4 seek=33796
without conv=notrunc argument it used to give
dd: ftruncate: Invalid argument error.

Finding usage of resources (CPU and memory) by threads of a process in Android

I have a multi-threaded application(C++,C and pthread library) and I will like to know how much resources(CPU and memory) each thread uses. Is there a way to find out these details on Android?
I have tried
$ adb shell ps -p -t
But, this gives information in the below format,
USER PID PPID VSIZE RSS PRIO NICE RTPRI SCHED WCHAN PC NAME
root 1 0 476 312 20 0 0 0 c037c0e0 000087bc S /init
root 2 0 0 0 20 0 0 0 c031f114 00000000 S kthreadd
root 3 2 0 0 20 0 0 0 c030e5d0 00000000 S ksoftirqd/0
root 4 2 0 0 -100 0 99 1 c033fc50 00000000 S watchdog/0
root 5 2 0 0 20 0 0 0 c031b4b4 00000000 S events/0
root 6 2 0 0 20 0 0 0 c031b4b4 00000000 S khelper
Any way to know which threads are running along with their parent's id will be really helpful.
using
$ adb logcat -v threadtime
prints info about the running process (PID) and the thread (TID).
But, its not enough for my purpose. I want to know how much resources is a particular thread consuming. Any pointers.
ps command in android seems to be very limited compared to linux.
You could try:
ps -t -c APP_NAME
This will show you threads(-t) and the CPU assigned to the thread (-c)
Example:
ps -t -c -p com.whatsapp
-p is thread priority(linux nice value)

Categories

Resources