Re: [psutil] psutil on Android

244 views
Skip to first unread message

Giampaolo Rodolà

unread,
Nov 16, 2012, 2:00:42 PM11/16/12
to psu...@googlegroups.com
2012/11/16 Anthony Prieur <anthony...@gmail.com>
> I did not find a build for Android, has it been done somewhere ?

I have no idea but my guess is no, it hasn't. 
The platforms currently supported by psutil are Windows, OSX, FreeBSD and Linux.

> I added a build there

Not sure what this is about. 
Is it a porting attempt for Android?

> I tried all examples I found on the main page, all is working except

If you're trying a port then your final goal should be having all tests pass.


- G.

Anthony Prieur

unread,
Nov 16, 2012, 2:24:54 PM11/16/12
to psu...@googlegroups.com
Not sure what this is about. 
Is it a porting attempt for Android?

I just needed to have psutil work under Android so resolved the compilation issues.

If you're trying a port then your final goal should be having all tests pass

I could fix get_cpu_affinity and get_set_affinity by modifying the NDK libc and link statically to it, I guess it's was busybox does. But I wanted to know if someone see a better fix

Giampaolo Rodolà

unread,
Nov 16, 2012, 2:35:55 PM11/16/12
to psu...@googlegroups.com
2012/11/16 Anthony Prieur <anthony...@gmail.com>
Not sure what this is about. 
Is it a porting attempt for Android?

I just needed to have psutil work under Android so resolved the compilation issues.

If you're trying a port then your final goal should be having all tests pass

I could fix get_cpu_affinity and get_set_affinity by modifying the NDK libc and link statically to it, I guess it's was busybox does. But I wanted to know if someone see a better fix

I have never developed for Android so I have no idea, sorry.
If you keep making progress it would be great to convert your work in an actual patch to apply against psutil trunk and add support for Android though.

- G.

Anthony Prieur

unread,
Nov 17, 2012, 2:38:57 AM11/17/12
to psu...@googlegroups.com
I fixed get_cpu_affinity and get_set_affinity using syscall as there are present in libc on the Android device (just not exposed in the NDK). I can provide an APK if you want to try psutil on Android.

Anthony Prieur

unread,
Nov 17, 2012, 7:20:08 AM11/17/12
to psu...@googlegroups.com
Attached the patch to apply on trunk r1546 to add Android support.
psutil-trunkr1546-android.patch

Giampaolo Rodolà

unread,
Nov 17, 2012, 7:52:01 AM11/17/12
to psu...@googlegroups.com
This looks promising. Thanks.
What about tests? Do they pass?
I'll have to look into this carefully, and figure out what to do in order to try this on Android (any help/link/tutorial is appreciated).
In the meantime can you please file an issue on the bug tracker including this patch?


2012/11/17 Anthony Prieur <anthony...@gmail.com>
--
You received this message because you are subscribed to the "Python process utilities (psutil)" project group:
http://code.google.com/p/psutil
To post to this group, send email to psu...@googlegroups.com
To unsubscribe from this group, send email to psutil-un...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/psutil

Message has been deleted

Anthony Prieur

unread,
Dec 28, 2012, 7:00:57 AM12/28/12
to psu...@googlegroups.com
Attached new patch which added the ability to use "get_memory_maps()" under Android, so add ability to get process USS/PSS as suggested in issue http://code.google.com/p/psutil/issues/detail?id=347 .  The patch is to apply against 0.6.1 release.
psutil-0.6.1-android.patch

Giampaolo Rodolà

unread,
Dec 28, 2012, 7:17:01 AM12/28/12
to psu...@googlegroups.com
USS/PSS idea was rejected and should not be included in a patch which aims to add support for Android.
Please create an issue on the bug tracker including this patch and test results.

2012/12/28 Anthony Prieur <anthony...@gmail.com>
USS/PSS

Anthony Prieur

unread,
Dec 28, 2012, 7:19:58 AM12/28/12
to psu...@googlegroups.com
The patch does not provide USS/PSS, the patch just allow
get_memory_maps() to work under Android and not crash.

Giampaolo Rodolà

unread,
Dec 28, 2012, 7:38:52 AM12/28/12
to psu...@googlegroups.com
Oh ok. What else needs to be done? Are all functionalities available on Linux also available on Android? Do tests pass?

2012/12/28 Anthony Prieur <anthony...@gmail.com>

Anthony Prieur

unread,
Dec 28, 2012, 7:56:04 AM12/28/12
to psu...@googlegroups.com
The Python build I'm using under Android currently misses unittest so
I did not try to run tests. Perhaps you could arrange a test suite for
Android I could try ?

I tested all example on psutil front page, only psutil.disk_usage was
failed because I do not have statvfs module and p.get_connections()
because AF_UNIX was not availble in Python socket module, but it's
more on Python build side than on psutil.

Anthony Prieur

unread,
Dec 28, 2012, 8:03:53 AM12/28/12
to psu...@googlegroups.com
p.get_connections() can be fixed by replacing in _pslinux.py AF_UNIX by 0.

Giampaolo Rodolà

unread,
Dec 28, 2012, 8:53:03 AM12/28/12
to psu...@googlegroups.com
I'm not sure how to arrange tests without using unittest module, sorry. I think it's easier to just figure out how to install unittest module.
Ideally what needs to be done is to provide a patch which is consistent with existing code base conventions (mostly meaning being PEP8 compliant - so your patch needs some adjustments) and which passes (reasonably) all unit tests.
Now, if we want to push this forward I would recommend to at least move this discussion on the bug tracker, rewrite the patch by following PEP8 conventions (no tabs, 4 spaces, etc.) and provide the results of a test suite run.
Quick instructions on how to setup a working Python env on Android would be a big plus (at least for me).

An initial and quick review about the patch.

- customize_compiler() function in setup.py looks kind of hackish. If there's no other way to achieve the same goal it's supposed to serve then a comment explaining what it does and/or where you took it from is necessary. Also it should be executed on Android only.

- _psutil_linux.h contains a lot of new code which should be executed on Android *only*. After applying your patch I couldn't compile psutil on Linux. Ideally, all the new stuff you added should be moved into a separate file(s) wherever possible (ideally psutil/_psutil_android.c and/or psutil/_psutil_android.h).


2012/12/28 Anthony Prieur <anthony...@gmail.com>

shashi...@gmail.com

unread,
Aug 11, 2014, 3:47:40 AM8/11/14
to psu...@googlegroups.com
Is there any doc which provides how to apply this patch?
I have a working environment of python on an android system.

Thank you.

Anthony Prieur

unread,
Aug 11, 2014, 3:57:36 AM8/11/14
to psu...@googlegroups.com
It's embeded by default in android-python27, see
https://code.google.com/p/android-python27/source/browse/python-build/bootstrap.sh
(NB: the patch was made for psutil-0.6.1 but it would not be difficult
to update it if you want to use latest psutil).
> ---
> You received this message because you are subscribed to the Google Groups
> "psutil" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to psutil+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Giampaolo Rodola'

unread,
Aug 11, 2014, 4:38:50 AM8/11/14
to psu...@googlegroups.com
Interesting, I didn't know about this (and kind of forgot about the Android patch). It would be great to update that patch and possibly include it in latest psutil version. Anthony, any thoughts?

Anthony Prieur

unread,
Aug 11, 2014, 5:06:17 PM8/11/14
to psu...@googlegroups.com
The "dirty" part of the patch is already done (add missing functions
of Android libc (bionic)), the update is then only adjustment to apis
and should not be complicated.

shashi...@gmail.com

unread,
Aug 14, 2014, 5:47:30 AM8/14/14
to psu...@googlegroups.com
Thanks Anthony! I got the android-python27.
Also one more thing  is this also included in kivy by default?

Anthony Prieur

unread,
Aug 14, 2014, 8:15:08 AM8/14/14
to psu...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages