iPhone System Processes by CPU Rate (top/ps) - iphone

What is the best way to programmatically access the processes sorted by cpu rate on the iPhone (similar to that seen in the *nix top command)? sysctl()?

You can use Instruments to do this, open up Instruments (/Developer/Applications/Instruments) and choose iPhone -> Activity Monitor and hit record, it'll give you all the applications running and how much CPU, RAM and everything else they are running.
Obviously this isn't programatically but you only need to worry about the CPU of a single app at a time if your developing and using this you can profile the app in question very easily

I don't believe you can. Applications are sandboxed on the iPHone platform. A rule of thumb on that platform is to just worry about your own application because you can't access much outside of it.

Related

How can i get background running applications detail in my Application for iOS?

I want to develop one application which should be monitoring how much application is running on how much time on my I-Phone Device(including internet browsers).
Please share your idea regarding this post.
little similar like this:
https://itunes.apple.com/us/app/system-manager/id455736462?mt=8
thanks
You really can't since Apple has placed very restrictive guidelines on Apps for iOS.
Although with some low level call you might get some running process information.
Because of the sandbox environment you might not be abele to much more information then that.
Also app's in background are suspended if they have no background running flaggs (voip, audio, location or accessory). Also if the system gets low on memory app that are suspended get killed and there memory freed up.
What you can do:
Try the List of All Processes OS X code which
Can we retrieve the applications currently running in iPhone and iPad
But keep in mind the restiction placed on you app by Apple: The iOS Environment, thus that there are app availble in the appstore that do what you want does not mean that you app will be allowed.

Minimising an app's battery usage on iOS (while phone is locked etc)

I've noticed that since iOS 4.0, the apps I developed started to not "exit" when the home button is pressed, but rather they stay in the "system tray" thing which pops out when you double click the system.
At around the same time, I noticed that the battery in my phone starts draining a lot faster. Then again, theoretically all the app should be using right now is only memory, because it is not currently active.
Which begs the question, has there ever been any benchmark on what causes the iPhone to drain the most batteries? Perhaps opengl calls, which use the graphics card would consume quite a bit? Or maybe just having the apps active mean there's less memory, and this causes faster battery loss (say, because the memory allocator must do more work etc)?
I am keen to know what other developers have tried to do to optimise battery usage.
its not opengl or allocations that cause the battery drain in fact the variables are saved on the hard disk when the application quit. They don't stay in memory cause this wouldn't be possible with running all apps at the same time. (see comments)
special thanks to Stephen Furlani for this guide in documentation
I think the only ones that can cause the faster drain are background processes that still accepted to be run in background like the voice over IP feature from Skype. (the features where big announced at the iOS 4 SDK preview back then). Background audio/video, network transfers like pandora etc. (I can't name all) but not every app!
And by the way, I also noticed that my battery sometimes not hold as long as possible on other days. But I can't locate which App cause that :(

iPhone: leaks from other Apps taking up RAM?

I'm reading some people stating that if another (3rd party) app on someone's iPhone has been leaking memory, that this may reduce the (mystery) amount of RAM your app would otherwise have available.
This confuses me -- does not all app memory get released when the app is closed by the user? And only one app is open at a time on iPhone?
Normally, any memory that your application allocates will be freed when it exits. However, many of Apple's applications continue running after they're "closed", so memory leaks in Mail, for instance, can affect available memory.
In addition, there are apps out there that claim to free up allocated memory. They really don't do anything other than force some dirty pages out of the buffer cache, but they appear to do something, so people believe they must be doing something useful.
On a jailbroken phone - yes, third party apps can be running at the same time as yours. Running out of memory is common with people who like to have many apps running at once hence the need for task managers, killing tasks etc.
On an unhacked phone - no. Yours is the only non-apple app that is running, no others can run at the same time.
So what can you do? All you can do is try to use the minimum memory possible which you're probably already doing. Realistically you can only test with a factory, unhacked phone, unless you are going to spend hours trying to please everyone. If you think you are maybe using too much you could identify the larger allocations using the instruments tools ("Run with performance tool >" from within Xcode) and then post that chunk of code here to get ideas of how to reduce it.
You should run Instruments and then add the instrument "Memory Monitor" to see the memory use of all of the other processes on your phone. (Add with Window -> Library , then drag the Memory Monitor instrument to the instrument panel.
What I'm still trying to determine is why is iOS releasing memory from MY app, and not all of the other memory pig apps that are not currently running.

Memory allocation in iphone application

I'm developing a new application for the iphone.
I want to understand something - does the memory that my application uses shared with other applications?
What if an application causes memory leaks, does it effect the device performances after the user closes the application?
thanks.
At the moment, on iPhone you'll only be sharing memory with a certain few applications - MobilePhone, MobileMail, MobileMessaging, Safari, iPod and a few minor daemons.
If you're the active application and you need more memory than is free, then some of these applications (but not the most critical ones, like MobilePhone) will be terminated in order for you to continue. If you continue to use memory, you'll be terminated before the critical apps.
The amount of memory you can use depends on which device you're on and what else is going on on the device. Common advice is that as long as you stay under 30Mb, you'll be fine.
Once an application is terminated, the fact that it leaked memory (or not) is no longer an issue - the system will clean up and free it's entire address space.
Apps sometimes say that you should reboot your iPhone before running the app, clearing the RAM that critical daemons use for caching or whatever during normal use.
If you ever find yourself doing this, stop. If you ship an app with this requirement, you fail as a programmer and should be banned from programming. Why? Look up the amount of RAM a Playstation 2 has, then look at games like Gran Turismo and Grand Theft Auto.

Can I run multiple app in iphone simultaneously

I want to run two app simultaneously, I am using jailbroken phone and dont want to upload that app to the app store.
Is there any way so that I can log phone call time, this can only be done if my "logging app" is running in background.
Please suggest me, how can I do this on jailbroken phone.
Some thing like:http://msdn.microsoft.com/en-us/library/ms884959.aspx (its for windows)
Is this actually a programming question, or are you asking for an app that logs call times?
Assuming the former, you would write a iPhone program that hooks into current phone conversations some way (private APIs? Not sure if this is indeed possible, just assuming.) You would then run your app via Backgrounder or some other wrapper that provided an interface for multiple applications to run at the same time. This usually comes at the cost of increase battery life, depending on how much CPU (and maybe memory?) the backgrounded app consumes.
Backgrounder is available via Cydia, I believe.
Need to include CoreTelephony, will solve the issue