I'm trying to use Instruments to figure out what in my app is eating up all my battery life.
I thought Time Profiler would work here, but I can't figure out how to get it to tell me what processes are running after a certain point in time. Currently, Time Profiler tells me about all the tasks that have run since the app first launched, but I only want to know about the ones that are running right now.
Is there any way to filter Time Profiler in this fashion?
Found the answer - hold down the option key while dragging across the timeline.
Related
My question involves keeping an app that monitors user interactions in the background, for example time spent in one or the app. The issue arises when you can not have a background process run for more than 10 min or violate Apple's sandbox restrictions. Since I am relatively new to the Apple API, and could not find a direct answer that didn't involve location services or VOIP (which are both interesting options, but my application will not be able to use either viably), I come to ask for options in which I can understand when another app opens, when it closes, when it fetches data, and when user holds phone in certain orientation (ie when people hold their phone at certain angles to read text and etc.) for certain amount of time.
The purpose of this analyzation is to predict an attention span for the user, so I need to be able to run in the background, as the user will not be using my app while it predicts attention span.
My thoughts on this are possibly accessing the system log, and somehow parse previous statements (I don't think sandbox will allow), but inevitably the iOS system will suspend my processes after some point unless I put a timer. There is also the option of having the system wake up my app via opportunistic fetching, but that won't be useful if I don't collect the data.
Keep in mind this is within IOS 11, so it is much more restrictive than previous iterations. I understand this may seem like a complex problem, but even a direction in which to head could be useful to me.
This solution might work, (not recommended since it drains the battery quicker).
Just update your current location, every 10 mins. It will reset the background thread timer.
I have an app that adds a lot of UIClasses to many different Views. Views get removed and get added again. But then after some time working with the app, the app starts to slow down. Reloading everything, including the Viewcontroller, doesn't help.
The problem is, that i don't know what could slow down the app. The Memory Usage of the app doesn't go up and the CPU usage doesn't go up aswell. It just seems that the App does everything slower. Views take longer to get added to the view and so on.
Is there anything that i could check what could cause the app to slow down over time? I know that this question is very broad, but maybe someone of you can show me the direction to look at. I`m out of ideas.
It's hard to answer a question like this in the abstract.
I suggest using the Instruments tool and running a time profile. That lets you see where your app is spending most of it's time. You should be able to run the app for a period of time and see the culprit start to take more and more time as you run the app.
My app gets stuck for a specific operation and that operation is too big having so many method calls and services requests, so i cannot put breakpoints on each method and debug, is there any other way i can get to know where exactly my app is stucked in xcode?
The operation wasn't too big to write the code, so it isn't too big to add breakpoints, logging statements, assertions and so on.
The only other way that works sometimes is taking a long shower in the morning, not thinking about work at all, and suddenly the realisation what you did wrong jumps to your mind. It has worked for me sometimes, but the first method is more reliable.
If you have reason to believe that the most time is spent in one operation, just let it run with the debugger attached and then press the pause button and see where you are...
A somewhat niftier approach would be to start with Instruments (i.e. the Time Profiler). It's easy to use and should be the first weapon of your choice for performance issues.
You can set a conditional break point in Xcode to debug a specific condition, for more detail go through Jeffrey Sambells blog!
My App is typically run overnight as a baby monitor, either as foreground app, or with background audio running.
Goals:
Track total app startups ie. active user count.
Track total usage time in foreground vs background and total session time.
Track various page-views if they navigate the settings screens.
As recommended, I start the tracker in didFinishLaunchingWithOptions, and track my first ViewController as my first 'page-view'. My App might stay on this page then for the next 8 hours...
A couple of issues then appear:
When do I call stopTracker and what does it do? I'm hoping that it terminates the tracking session. But since google kindly hid their code in a static lib, I have no idea what's going on under the covers, and the .h doesn't say much. First instinct is to put stopTracker in applicationWillResignActive however, if the user decides to enable background audio my app is still running...
Next I read that a session can timeout after 30mins with no new pageviews, or at midnight. I could set a repeating timer to send the same page-view every 20mins, that should keep my session alive, at least until midnight, but then my page views are going to be much larger? unless it's smart enough to know I'm on the same page with every call. google analytics blog
[Update: each call seems to be counted as a new pageview, and numbers are thus skewed, so still an issue how to handle this]
If my timer above runs past midnight and the session has expired, I'm going to end up with a new session and double the actual active user count?
If I do call stopTracker in applicationWillResignActive, will the next call to track a page-view restart the tracker? or do I need to call startTrackerWithAccountID again?
If instead I start the tracker in applicationDidBecomeActive, I lose the session that might have been running in the background.
[update: this seems to be the best approach so far, but testing is very slow due to time lag on analytics reports, I will report back soon]
PS EasyTracker doesn't seem to handle this any better.
I got this working by using a pageview called 'Backgrounded', and when the user has selected no background functionality, then instead the app is calling stopTracker. I see multiple hits, with an average session of 20mins, but i can multiple pageview by time to see total time for goal 2. I found two solutions for goal one, events (which were not exposed in easy tracker), and also in my applicationDidBecomeActive (if it's not a restore of backgrounded app) then i track a pageview for AppStarted. I ended up wrapping the whole thing in a utility class and rolled it into a couple of my apps, so will be interesting too see the results. If anyone else tries this, you might want to think about using the custom variables too. I added my app version to this, so I can also monitor how many users are migrating to the latest app releases.
I've seen is posible to know what applications are running with getVisibleApplications()from "ApplicationManager" class but, is it possible to know how long were these applications used?
Thanks
If you really needed this information it would be possible.
You could have a background process start a timer and every N minutes it could call getVisibleApplications() and keep track of what has been added or removed to the list.
The difficulty is finding the right balance between accurate data and battery life as a very small value of N (seconds/minutes) will prevent the device from sleeping and will cause severe battery life degradation. A very large value of N will have minimal effect on battery life but the data won't be very accurate.
You could also combine it with events... maybe you would monitor aggressively when the backlight was on and hourly when it's off.
Not really sure what you're trying to do so my apologies if this doesn't help at all.
Simple answer is, No you cannot the duration of how long the applications were used. Out of interest, why would you want to know that?