Is the memory returned by adb shell dumsys meminfo in kB or KB?
where:
kB = 1000 bytes
KB = 1024 bytes
It's KB (1024 bytes), or kibibytes (KiB), contrary to the kB notation in their printfs which is supposed to mean 1000 bytes as you noted.
Here's how I know. On my Linux box, if I do free -b,
total used free shared buffers cached
Mem: 67459153920 60865880064 6593273856 307834880 1373028352 40107618304
So look at the total value of 67459153920. That's in bytes (-b). Now if I look at meminfo,
MemTotal: 65878080 kB
and 67459153920 / 1024 = 65878080, so that value is in KB or aka KiB (1024 bytes).
https://en.wikipedia.org/wiki/Kilobyte
Note that I tested this on my Linux desktop because Android Linux doesn't happen to include the free command, but dumpsys meminfo is just reporting the results of cat /proc/meminfo which is implemented at the Linux kernel level of Android fs/proc/meminfo.c.
Related
installing (run.bat) MobSF I have this error during installation on a Win10. I have c++ insalled. Do you have any idea why this breaks?
run.bat of MobSF
Thanks.
I have tried running "clean.bat", installing C++ and insstalling SDK
Microsoft Windows [Versión 10.0.19044.2604]
(c) Microsoft Corporation. Todos los derechos reservados.
C:\Users\DAS>cd C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF
C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF>./setup.bat
"." no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF>setup.bat
[INSTALL] Checking for Python version 3.8+
[INSTALL] Found Python 3.10.4
[INSTALL] Found pip
Requirement already satisfied: pip in c:\users\das\appdata\local\programs\python\python310\lib\site-packages (23.0.1)
[INSTALL] Found OpenSSL executable
[INSTALL] Found Visual Studio Build Tools
[INSTALL] Creating venv
Requirement already satisfied: pip in c:\users\das\desktop\k\pentesting android\mobile-security-framework-mobsf\venv\lib\site-packages (22.0.4)
Collecting pip
Using cached pip-23.0.1-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 22.0.4
Uninstalling pip-22.0.4:
Successfully uninstalled pip-22.0.4
Successfully installed pip-23.0.1
[INSTALL] Installing Requirements
Collecting wheel
Downloading wheel-0.38.4-py3-none-any.whl (36 kB)
Installing collected packages: wheel
Successfully installed wheel-0.38.4
Ignoring gunicorn: markers 'platform_system != "Windows"' don't match your environment
Collecting Django>=3.1.5
Downloading Django-4.1.7-py3-none-any.whl (8.1 MB)
---------------------------------------- 8.1/8.1 MB 12.0 MB/s eta 0:00:00
Collecting lxml>=4.6.2
Downloading lxml-4.9.2-cp310-cp310-win_amd64.whl (3.8 MB)
---------------------------------------- 3.8/3.8 MB 12.7 MB/s eta 0:00:00
Collecting rsa>=4.7
Downloading rsa-4.9-py3-none-any.whl (34 kB)
Collecting biplist>=1.0.3
Downloading biplist-1.0.3.tar.gz (21 kB)
Preparing metadata (setup.py) ... done
Collecting requests>=2.25.1
Downloading requests-2.28.2-py3-none-any.whl (62 kB)
---------------------------------------- 62.8/62.8 kB ? eta 0:00:00
Collecting bs4>=0.0.1
Downloading bs4-0.0.1.tar.gz (1.1 kB)
Preparing metadata (setup.py) ... done
Collecting colorlog>=4.7.2
Downloading colorlog-6.7.0-py2.py3-none-any.whl (11 kB)
Collecting macholib>=1.14
Downloading macholib-1.16.2-py2.py3-none-any.whl (38 kB)
Collecting whitenoise>=5.2.0
Downloading whitenoise-6.3.0-py3-none-any.whl (19 kB)
Collecting waitress>=1.4.4
Downloading waitress-2.1.2-py3-none-any.whl (57 kB)
---------------------------------------- 57.7/57.7 kB ? eta 0:00:00
Collecting psutil>=5.8.0
Downloading psutil-5.9.4-cp36-abi3-win_amd64.whl (252 kB)
---------------------------------------- 252.5/252.5 kB 15.1 MB/s eta 0:00:00
Collecting shelljob>=0.6.2
Downloading shelljob-0.6.3-py3-none-any.whl (9.9 kB)
Collecting asn1crypto>=1.4.0
Downloading asn1crypto-1.5.1-py2.py3-none-any.whl (105 kB)
---------------------------------------- 105.0/105.0 kB ? eta 0:00:00
Collecting oscrypto>=1.2.1
Downloading oscrypto-1.3.0-py2.py3-none-any.whl (194 kB)
---------------------------------------- 194.6/194.6 kB 11.5 MB/s eta 0:00:00
Collecting distro>=1.5.0
Downloading distro-1.8.0-py3-none-any.whl (20 kB)
Collecting IP2Location==8.9.0
Downloading IP2Location-8.9.0-py3-none-any.whl (16 kB)
Collecting lief>=0.12.1
Downloading lief-0.12.3-cp310-cp310-win_amd64.whl (4.9 MB)
---------------------------------------- 4.9/4.9 MB 12.9 MB/s eta 0:00:00
Collecting http-tools>=2.1.0
Downloading http-tools-2.1.1.tar.gz (550 kB)
---------------------------------------- 550.3/550.3 kB 17.4 MB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Collecting libsast>=1.5.1
Downloading libsast-1.5.2.tar.gz (36 kB)
Preparing metadata (setup.py) ... done
Collecting pdfkit>=0.6.1
Downloading pdfkit-1.0.0-py3-none-any.whl (12 kB)
Collecting google-play-scraper>=0.1.2
Downloading google_play_scraper-1.2.3-py3-none-any.whl (28 kB)
Collecting androguard==3.4.0a1
Downloading androguard-3.4.0a1-py3-none-any.whl (918 kB)
---------------------------------------- 918.1/918.1 kB 14.6 MB/s eta 0:00:00
Collecting apkid==2.1.4
Downloading apkid-2.1.4-py2.py3-none-any.whl (116 kB)
---------------------------------------- 116.6/116.6 kB ? eta 0:00:00
Collecting quark-engine==22.10.1
Downloading quark_engine-22.10.1-py3-none-any.whl (97 kB)
---------------------------------------- 97.6/97.6 kB ? eta 0:00:00
Collecting frida==15.2.2
Downloading frida-15.2.2.tar.gz (11 kB)
Preparing metadata (setup.py) ... done
Collecting tldextract==3.4.0
Downloading tldextract-3.4.0-py3-none-any.whl (93 kB)
---------------------------------------- 93.9/93.9 kB 5.2 MB/s eta 0:00:00
Collecting openstep-parser==1.5.4
Downloading openstep_parser-1.5.4-py3-none-any.whl (4.5 kB)
Collecting svgutils==0.3.4
Downloading svgutils-0.3.4-py3-none-any.whl (10 kB)
Collecting ruamel.yaml==0.16.13
Downloading ruamel.yaml-0.16.13-py2.py3-none-any.whl (111 kB)
---------------------------------------- 111.9/111.9 kB ? eta 0:00:00
Collecting click==8.0.1
Downloading click-8.0.1-py3-none-any.whl (97 kB)
---------------------------------------- 97.4/97.4 kB ? eta 0:00:00
Collecting decorator==4.4.2
Downloading decorator-4.4.2-py2.py3-none-any.whl (9.2 kB)
Collecting asgiref<4,>=3.5.2
Downloading asgiref-3.6.0-py3-none-any.whl (23 kB)
Collecting tzdata; sys_platform == "win32"
Downloading tzdata-2022.7-py2.py3-none-any.whl (340 kB)
---------------------------------------- 340.1/340.1 kB 10.6 MB/s eta 0:00:00
Collecting sqlparse>=0.2.2
Downloading sqlparse-0.4.3-py3-none-any.whl (42 kB)
---------------------------------------- 42.8/42.8 kB ? eta 0:00:00
Collecting pyasn1>=0.1.3
Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
---------------------------------------- 77.1/77.1 kB ? eta 0:00:00
Collecting urllib3<1.27,>=1.21.1
Downloading urllib3-1.26.14-py2.py3-none-any.whl (140 kB)
---------------------------------------- 140.6/140.6 kB ? eta 0:00:00
Collecting charset-normalizer<4,>=2
Downloading charset_normalizer-3.0.1-cp310-cp310-win_amd64.whl (96 kB)
---------------------------------------- 96.5/96.5 kB 5.7 MB/s eta 0:00:00
Collecting certifi>=2017.4.17
Downloading certifi-2022.12.7-py3-none-any.whl (155 kB)
---------------------------------------- 155.3/155.3 kB 9.7 MB/s eta 0:00:00
Collecting idna<4,>=2.5
Downloading idna-3.4-py3-none-any.whl (61 kB)
---------------------------------------- 61.5/61.5 kB ? eta 0:00:00
Collecting beautifulsoup4
Downloading beautifulsoup4-4.11.2-py3-none-any.whl (129 kB)
---------------------------------------- 129.4/129.4 kB ? eta 0:00:00
Collecting colorama; sys_platform == "win32"
Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting altgraph>=0.17
Downloading altgraph-0.17.3-py2.py3-none-any.whl (21 kB)
Collecting mitmproxy==6.0.2
Downloading mitmproxy-6.0.2-py3-none-any.whl (1.1 MB)
---------------------------------------- 1.1/1.1 MB 14.3 MB/s eta 0:00:00
Collecting markupsafe==2.0.1
Downloading MarkupSafe-2.0.1-cp310-cp310-win_amd64.whl (15 kB)
Collecting pyyaml>=6.0
Downloading PyYAML-6.0-cp310-cp310-win_amd64.whl (151 kB)
---------------------------------------- 151.7/151.7 kB 8.8 MB/s eta 0:00:00
Collecting networkx>=2.2
Downloading networkx-3.0-py3-none-any.whl (2.0 MB)
---------------------------------------- 2.0/2.0 MB 13.0 MB/s eta 0:00:00
Collecting matplotlib>=3.0.2
Downloading matplotlib-3.7.0-cp310-cp310-win_amd64.whl (7.6 MB)
---------------------------------------- 7.6/7.6 MB 12.5 MB/s eta 0:00:00
Collecting pygments>=2.3.1
Downloading Pygments-2.14.0-py3-none-any.whl (1.1 MB)
---------------------------------------- 1.1/1.1 MB 11.8 MB/s eta 0:00:00
Collecting pydot>=1.4.1
Downloading pydot-1.4.2-py2.py3-none-any.whl (21 kB)
Collecting ipython>=5.0.0
Downloading ipython-8.10.0-py3-none-any.whl (784 kB)
---------------------------------------- 784.3/784.3 kB 12.5 MB/s eta 0:00:00
Collecting yara-python-dex>=1.0.1
Downloading yara_python_dex-1.0.4-cp310-cp310-win_amd64.whl (130 kB)
---------------------------------------- 130.2/130.2 kB ? eta 0:00:00
Collecting kaleido
Downloading kaleido-0.2.1-py2.py3-none-win_amd64.whl (65.9 MB)
---------------------------------------- 65.9/65.9 MB 12.6 MB/s eta 0:00:00
Collecting prettytable>=1.0.0
Downloading prettytable-3.6.0-py3-none-any.whl (27 kB)
Collecting tqdm
Downloading tqdm-4.64.1-py2.py3-none-any.whl (78 kB)
---------------------------------------- 78.5/78.5 kB ? eta 0:00:00
Collecting plotly
Downloading plotly-5.13.0-py2.py3-none-any.whl (15.2 MB)
---------------------------------------- 15.2/15.2 MB 12.8 MB/s eta 0:00:00
Collecting prompt-toolkit==3.0.19
Downloading prompt_toolkit-3.0.19-py3-none-any.whl (368 kB)
---------------------------------------- 368.4/368.4 kB 23.9 MB/s eta 0:00:00
Collecting pandas
Downloading pandas-1.5.3-cp310-cp310-win_amd64.whl (10.4 MB)
---------------------------------------- 10.4/10.4 MB 12.6 MB/s eta 0:00:00
Collecting rzpipe
Downloading rzpipe-0.4.0-py3-none-any.whl (11 kB)
Collecting graphviz
Downloading graphviz-0.20.1-py3-none-any.whl (47 kB)
---------------------------------------- 47.0/47.0 kB ? eta 0:00:00
Requirement already satisfied: setuptools in c:\users\das\desktop\k\pentesting android\mobile-security-framework-mobsf\venv\lib\site-packages (from frida==15.2.2->-r requirements.txt (line 26)) (58.1.0)
Collecting requests-file>=1.4
Downloading requests_file-1.5.1-py2.py3-none-any.whl (3.7 kB)
Collecting filelock>=3.0.8
Downloading filelock-3.9.0-py3-none-any.whl (9.7 kB)
Collecting soupsieve>1.2
Downloading soupsieve-2.4-py3-none-any.whl (37 kB)
Collecting tornado<7,>=4.3
Downloading tornado-6.2-cp37-abi3-win_amd64.whl (425 kB)
---------------------------------------- 425.3/425.3 kB 13.4 MB/s eta 0:00:00
Collecting pyparsing<2.5,>=2.4.2
Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
---------------------------------------- 67.8/67.8 kB ? eta 0:00:00
Collecting passlib<1.8,>=1.6.5
Downloading passlib-1.7.4-py2.py3-none-any.whl (525 kB)
---------------------------------------- 525.6/525.6 kB 16.6 MB/s eta 0:00:00
Collecting pydivert<2.2,>=2.0.3; sys_platform == "win32"
Downloading pydivert-2.1.0-py2.py3-none-any.whl (104 kB)
---------------------------------------- 104.7/104.7 kB ? eta 0:00:00
Collecting protobuf<3.15,>=3.14
Downloading protobuf-3.14.0-py2.py3-none-any.whl (173 kB)
---------------------------------------- 173.5/173.5 kB 10.2 MB/s eta 0:00:00
Collecting sortedcontainers<2.4,>=2.3
Downloading sortedcontainers-2.3.0-py2.py3-none-any.whl (29 kB)
Collecting zstandard<0.15,>=0.11
Downloading zstandard-0.14.1.tar.gz (676 kB)
---------------------------------------- 676.8/676.8 kB 14.2 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [25 lines of output]
Traceback (most recent call last):
File "C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\venv\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
main()
File "C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\venv\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\venv\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in _get_build_requires
self.run_setup()
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\build_meta.py", line 484, in run_setup
super(_BuildMetaLegacyBackend,
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup
exec(code, locals())
File "<string>", line 63, in <module>
File "C:\Users\DAS\AppData\Local\Temp\pip-install-suw_x1ii\zstandard\setup_zstd.py", line 164, in get_c_extension
compiler.initialize()
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 253, in initialize
vc_env = _get_vc_env(plat_spec)
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\msvc.py", line 210, in msvc14_get_vc_env
return _msvc14_get_vc_env(plat_spec)
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\msvc.py", line 164, in _msvc14_get_vc_env
raise distutils.errors.DistutilsPlatformError(
distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [25 lines of output]
Traceback (most recent call last):
File "C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\venv\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
main()
File "C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\venv\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\venv\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in _get_build_requires
self.run_setup()
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\build_meta.py", line 484, in run_setup
super(_BuildMetaLegacyBackend,
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup
exec(code, locals())
File "<string>", line 63, in <module>
File "C:\Users\DAS\AppData\Local\Temp\pip-install-suw_x1ii\zstandard\setup_zstd.py", line 164, in get_c_extension
compiler.initialize()
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 253, in initialize
vc_env = _get_vc_env(plat_spec)
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\msvc.py", line 210, in msvc14_get_vc_env
return _msvc14_get_vc_env(plat_spec)
File "C:\Users\DAS\AppData\Local\Temp\pip-build-env-dh4tf_vd\overlay\Lib\site-packages\setuptools\msvc.py", line 164, in _msvc14_get_vc_env
raise distutils.errors.DistutilsPlatformError(
distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
[INSTALL] Clean Up
=======================MobSF Clean Script for Windows=======================
Running this script will delete the Scan database, all files uploaded and generated.
C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\scripts
Deleting all uploads
Deleting all downloads
Deleting Static Analyzer migrations
Deleting Dynamic Analyzer migrations
Deleting MobSF migrations
Deleting temp and log files
Deleting Scan database
Deleting Secret file
Deleting Previous setup files
Deleting MobSF data directory: "C:\Users\DAS\.MobSF"
Done
[INSTALL] Migrating Database
Traceback (most recent call last):
File "C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\manage.py", line 12, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
Traceback (most recent call last):
File "C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\manage.py", line 12, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
Traceback (most recent call last):
File "C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF\manage.py", line 12, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
Download and Install wkhtmltopdf for PDF Report Generation - https://wkhtmltopdf.org/downloads.html
[INSTALL] Installation Complete
[ERROR] Installation Failed!
Please ensure that all the requirements mentioned in documentation are installed before you run setup script.
Scroll up to see any installation errors.
The 'decorator==4.4.2' distribution was not found and is required by the application
C:\Users\DAS\Desktop\K\Pentesting Android\Mobile-Security-Framework-MobSF>
..........................................................................................................................................................................................................................................................................................................................................................................................................................
If you run adb shell dumpsys <package_name>, the output contains a section like this:
App Summary
Pss(KB)
------
Java Heap: 65636
Native Heap: 22216
Code: 1444
Stack: 1444
Graphics: 79332
Private Other: 6140
System: 19569
TOTAL: 195781 TOTAL SWAP PSS: 85
What does the Graphics metric correspond to?
please refer to How do I discover memory usage of my application in Android?
the Debug.MemoryInfo class has full documentation for related fields above~
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.
When I use TOP command, I could get the following info:
shell#android:/ $ top -n 1
User 31%, System 10%, IOW 0%, IRQ 0%
User 346 + Nice 10 + Sys 120 + Idle 637 + IOW 6 + IRQ 0 + SIRQ 2 = 1121
PID PR CPU% S #THR VSS RSS PCY UID Name
481 1 26% S 89 762832K 81688K fg system system_server
1699 0 5% S 27 676472K 39092K fg u0_a72 wm.cs.systemmonitor
11243 0 3% S 28 673140K 29796K bg u0_a111 com.weather.Weather
13327 2 1% S 23 680472K 35844K bg u0_a83 com.rhmsoft.fm
659 0 1% S 17 663044K 33136K bg u0_a13 android.process.media
20260 1 0% R 1 1208K 508K shell top
We can see the CPU% is round to integer, is there any way I could get a process's CPU% with higher precision?
-- Clarifications on the bounty -- Alex
The question refers to Android system, and preferably to a non-rooted device. While Android provides advanced profiling techniques for Java applications, tools for native code (C++) are limited. top command on Android allows to show the statistics for all threads running in the system, both Java threads and C++ threads. I am looking for an answer that will help with the following quest:
My app uses 2% CPU when it is inactive in background, while it should be below 0.1%. If I run top -t, I get 0% for all 15 threads that belong to my process (some threads are Java threads, e.g. the Main, UI thread; others are pthreads that never attach to JVM). How can I guess which thread eats the battery?
I would be glad to get even more details about this unexpected activity, and Android provides great helpers like TraceView for Java threads. Any insight regarding tools for native code will be highly appreciated.
You didn't mention it in your post, but in the comment you said that you really need CPU utilization per thread, not per process.
If you can't find a tool that's accurate enough, you can look directly in /proc/[pid]/task/[ThreadName] as described in the man page for /proc. This gives total CPU time consumed in "clock ticks" since execution began. Getting better resolution than this is probably difficult or impossible.
Edit
From the OP's comment, a command that lists the relevant information is:
adb shell cat /proc/${pid}/task/*/stat | awk -F\ '{print $1, $14}'
This just cats the correct /proc files to the debugging host, which runs a tiny awk program to print the columns for pid and user time. You could also easily use cut -d " " -f1,14 or something similar in perl to get the columns if awk isn't available.
Try this:
ps -eo pcpu,pid,user,args | sort -r -k1 | less
%CPU PID USER COMMAND
9.0 2721 user bash
1.4 956 root ...
0.5 2212 user ...
EDIT:
You can use adb shell and busybox (http://www.busybox.net/downloads/BusyBox.html)
adb shell busybox top
c:\ adb push busybox /system/bin
c:\ adb shell
# busybox top
CPU: 2.3% usr 3.1% sys 3.9% nic 90.5% idle 0.0% io 0.0% irq 0.0% sirq
Load average: 1.06 1.66 10.63 1/589 8048
←[7m PID PPID USER STAT VSZ %MEM CPU %CPU COMMAND←[0m
31619 2180 10112 S 217m 67.0 0 3.8 com.mgeek.android.DolphinBrowser.B
2232 2180 1000 S 551m169.6 0 2.6 system_server
8038 8037 0 R 2068 0.6 0 0.8 busybox top
2178 1 0 S 11092 3.3 0 0.6 /system/bin/drexe
6812 2180 10104 S 199m 61.2 0 0.5 android.tether
2291 2180 1001 S 324m 99.8 0 0.3 com.android.phone
2308 2180 10006 S 325m100.0 0 0.1 com.sec.android.app.dialertab
2177 1 1001 S 9624 2.8 0 0.1 /system/bin/rild
5 2 0 SW< 0 0.0 0 0.1 [events/0]
30087 2180 10022 S 358m110.4 0 0.0 com.samsung.vvm
2304 2180 10006 S 311m 96.0 0 0.0 com.sec.android.app.twlauncher
16110 2180 10006 S 296m 91.3 0 0.0 android.process.acore
2445 2180 10006 S 272m 83.8 0 0.0 com.sec.android.provider.logsprovi
8064 2180 10002 S 238m 73.4 0 0.0 com.google.process.gapps
31537 2180 10037 S 227m 69.9 0 0.0 com.google.android.gm
2288 2180 10048 S 221m 68.1 0 0.0 com.swype.android.inputmethod
2285 2180 10013 S 215m 66.3 0 0.0 com.tat.livewallpaper.aurora
30664 2180 10011 S 213m 65.8 0 0.0 com.android.email
31191 2180 10099 S 209m 64.4 0 0.0 com.sirma.mobile.bible.android
2377 2180 10087 S 207m 63.9 0 0.0 android.tts
(Taken from here)
Got this information from another thread:
3) Getting CPU info
~$ adb shell dumpsys cpuinfo
Output:
Load: 0.08 / 0.4 / 0.64
CPU usage from 42816ms to 34683ms ago:
system_server: 1% = 1% user + 0% kernel / faults: 16 minor
kdebuglog.sh: 0% = 0% user + 0% kernel / faults: 160 minor
tiwlan_wq: 0% = 0% user + 0% kernel
usb_mass_storag: 0% = 0% user + 0% kernel
pvr_workqueue: 0% = 0% user + 0% kernel
+sleep: 0% = 0% user + 0% kernel
+sleep: 0% = 0% user + 0% kernel
TOTAL: 6% = 1% user + 3% kernel + 0% irq
EDIT:
You can also try this command: echo $(adb shell ps | grep com.android.phone | awk '{ system("adb shell cat /proc/" $2 "/stat");}' | awk '{print $14+$15;}')
Also:
using top : This will show you the cpu stats
top -b -n 1 |grep ^Cpu
using ps: This will show you the % cpu usage for each process.
ps -eo pcpu,pid,user,args | sort -r -k1 | less
EDIT2:
In realtion to your comments and the bounty description (How can I guess which thread eats the battery?) I found an interesting page:
http://ziyang.eecs.umich.edu/projects/powertutor/
As stated there:
You can use PowerTutor to monitor the power consumption of any
application.
Try this for an instance and see if it meets your requirements.
FINAL EDIT:
Check out the Systrace documentation on the developer.android.com site:
http://developer.android.com/tools/debugging/systrace.html
http://developer.android.com/tools/help/systrace.html
I'm sorry if you already tried that, but that's one concrete method to measure the performance.
Use DDMS and method profiling to get a TraceView.
Basically:
Launch your app in debug mode
In DDMS, in the Devices tab, click "Start method profiling"
Do stuff on your device to recreate the conditions you want to monitor
Click "Stop method profiling"
You'll get a fairly detailed graph with each thread's execution that you can drill down into
More details here:
http://developer.android.com/tools/debugging/debugging-tracing.html
Disclaimer: I've only done this with a simple test app so I don't know how much mileage you'll get out of it. It does seem to give a bit more precision than what has been described so far, and does not require root.
I have an android application which enables some features only when the device has 512MB of RAM or more. This application reads the memtotal from /proc/meminfo (from Native C++ code) to determine the RAM size of the device.
I'm trying to install this application in an emulator running Android 4.1. I've set the RAM size of this emulator to 1024 and still the memtotal just shows 516312 KB. I have tried to increase the RAM size to 1536 (1.5GB) and still memtotal value remains the same in the meminfo file. I understand some memory is reserved for Kernel and some predefined bits. But missing a whole GB of memory left me clueless. Below is my meminfo file.
MemTotal: 516312 kB
MemFree: 282584 kB
Buffers: 1056 kB
Cached: 105976 kB
SwapCached: 0 kB
Active: 141696 kB
Inactive: 75880 kB
Active(anon): 122328 kB
Inactive(anon): 0 kB
Active(file): 19368 kB
Inactive(file): 75880 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 110560 kB
Mapped: 57468 kB
Slab: 5080 kB
SReclaimable: 1568 kB
SUnreclaim: 3512 kB
PageTables: 4132 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 258156 kB
Committed_AS: 1898016 kB
VmallocTotal: 450560 kB
VmallocUsed: 20564 kB
VmallocChunk: 423940 kB