I have an application where I am using the FreeRTOS vTaskSuspend to suspend the task and xTaskResumeAll to resume the task.
I see that when taskENTER_CRITICAL() is called the progeam terminates
I thought it might be a stack overflow issue so I have changed the stack size in freeRTOSconfig.h but no luck
I am using an EK-RA6M5
With fsp 3.5.0
Related
I have sometimes app freezing I do not know what is the source of problem.
It happens rarely but happens. I consider how to track such issue
I have crashlytics from firebase but there is no errors as freezing is I suppose something with threads maybe some deadlocks or infinite loops.
Is there way to track such things?
What maybe reasons of app freezing and being inactive (it is SwiftUI app) ?
Are there possibilities to track/profile apps installed on devices (not connected via Xcode) and send informations such that are available in Instrument to something like firebase console or other 3rd party tools.
Update
I think I do not indicated important fact.
It freezes UI definitely not for a few seconds but app need do be killed and restarted again.
There might be some heavy process that locks your main thread, so it freezes your UI.
You track the problems, performance, leaks and more using Instruments.
There are sample topics:
Instruments Tutorial with Swift: Getting Started
How to find and fix slow code using Instruments
And WWDC videos like
Using Time Profiler in Instruments
Creating Custom Instruments
I have experienced some of these weird behaviours before. And mostly the reason behind it was a task that is blocking the main thread making it unresponsive. Pause the app and check the stack trace. Also make sure all your UI operations are done on the main thread. Hope this helps!
I'm trying to monitor performance of my app;
When cpu usage overloads, I dump the stack trace of the suspicious thread and main thread as string by two libs:
https://github.com/bestswifter/BSBacktraceLogger
https://github.com/plausiblelabs/plcrashreporter
Following are the stack trace of one thread that I record, but it cannot help me analyze and locate where the performance issue is.
Am I doing wrong or how can I analyze the stack trace of a thread?
Ohkay ! I somewhat got your problem. What is your app about,? I mean is it a Game or something.? With this very info, I'll give you few workarounds,
I would suggest you to thoroughly study the code and de-initialize all the resources which are not being used.
Check for how many static properties and global variables/properties you’re using and ask yourself are they even required ?
Also I would again suggest you to monitor your app with Instruments look very precisely when the memory bar is going high and when low [e.g. by opening what ViewController it eats up a lot, by closing what ViewController the memory bar goes down, is your app dependent on GPS coz in big applications like uber they do not update locations on didUpdateLocations rather they use other methods, like singletons / Timer / heartbeats etc,]
Plus if you wanna avoid all this manual work, go for NewRelic
A small tutorial for that : link
Post again for more, Would be happy to help. =)
Here are some links : by using and combining them with firebase you'll be able to see events and logs as well,
here's 1st -> watchdog
here's the 2nd 1 -> Prints the filename, function name, line number and textual..etc..
Now combine any of that with firebase and it'll send the logs to you directly.
I have an iOS app with which I was previously using performSelectorInBackground to open a persistent socket connection. However, according to this answer, one should never use performSelectorInBackground.
The alternative, GCD and NSOperationQueue, both appear to persist the full stack frame, including 4! separate context switches, when I pause my app in the debugger. Therefore, if I open a socket connection inside a particular deep stack, that stack will persist for the lifetime of my app.
Are there any downsides to this? Here is what my stack looks like when I call my own internal beginSocketConnection:
Before, my call to beginSocketConnection was always (basically) at the top of a very simple stack because it had been invoked by performSelectorInBackground. That looked nicer/cleaner/better to me, so I'm not sure if this new approach is a bad thing.
First off, I agree with the other answer: Don't use -performSelectorInBackground:withObject:. Ever.
Next... you said:
The alternative, GCD and NSOperationQueue, both appear to persist the
full stack frame, including 4! separate context switches, when I pause
my app in the debugger. Therefore, if I open a socket connection
inside a particular deep stack, that stack will persist for the
lifetime of my app.
Are there any downsides to this?
Short answer? No. There are no downsides to this.
Long answer:
You appear to be mistaking debugging features for reality. In your screen shot there, those dotted lines aren't "context switches" (for any definition of 'context switch' that I'm aware of.) Xcode is eliding frames from the stack that it believes are not of interest to you (i.e. aren't in your code, or crossing into/out of your code.) You can toggle this behavior with the leftmost control in the bottom bar.
The "Enqueued from" stack traces are historical information aimed at helping you understand what caused the current (i.e. top) stack trace to happen. They're not execution states that still exist. They're just debugging information. You can safely assume that there's no "cost" to you associated with this.
The notion that opening a socket somehow causes a stack to "persist for the lifetime of [your] app" also doesn't make any sense. A socket is just a data structure in memory with some associated behavior provided by the OS. You're thinking about this too much.
Lastly, do yourself a favor, and don't choose APIs based on what makes your debugger stack traces look "nicer/cleaner/better."
I am trying to figure out why my program is hanging at one point. I know full well about the hefty call I make on the main thread but I don't know what the dispatch queue is that accounts for nearly half of the time. How can I trace where that call is coming from? Here is a screenshot from Instruments:
I have an application which takes measurements every second (I am running it in demo mode & generating random data, so the problem is not to do with reading from devices attached to the serial port).
After 5 or 6 minutes it hangs.
I have added
try
// entire body of procedure/function goes here
except
on E: Exception do
begin
MessageDlg('Internal coding error in <function name>()',
mtError, [mbOK], 0);
end;
end;
to every single function (and Application.Run() in the project file), but I don't see any message dialogs. Any idea how I can test this?
Update: I woudl guess sit to be a resource problem, either RAM or MySql database - but other programs are running ok, and it's only 5 floats and timestamp that get saved with each measurement, so both seem unlikely after such a short time.
Solution: there were many great answers (thanks and +1 all round), but I finally got it (as suggested) by running in the IDE and using Run/Pause to see that it was an ever increasing loop.
Thanks again, everyone.
I'd try the following:
Attach and click Pause and see where it is, what threads are running, what threads are waiting (if all of them then you have a deadlock).
Refactor your main method into bunch of small ones (you may have already done that) and then replace small ones with dummy/hardcoded values. This may help but not necessarily identify faulty block.
Watch the system resource consumption (handles, threads, etc.) with PerfMon or something. See if you running out of memory and start using HDD.
If you using sockets, check if your reading timeout is set to infinity. If yes then change to some value and watch for timeouts.
In .NET it's possible to enabling handling of all exceptions, which means before the code handle it (like in catch statement), the IDE breaks at the point of the exception. Enable that in Delphi if possible and see if you are getting any.
Use the debugger to find out what your app is doing when it appears to hang.
Run your program under the debugger. Let it run until it hangs. When it hangs, switch to the debugger and select "Debug: Break All" (or equivalent) to make the debugger freeze all threads and take control of the process.
Now open the Threads view in the debugger and examine the stack traces of each thread in your program. Start with the main thread, obviously. Be sure to look back through the call stack for several calls to see if you recognize any of your code. If you find a stack trace that is in the middle of a loop, examine the local variables to see if your loop control variable has somehow slipped past the exit condition and put you into an infinite loop.
If your stack traces indicate that every thread is blocked waiting for some external event, you may have a thread deadlock - thread A taking lock A, then trying to take lock B, while thread B is holding lock B and trying to take lock A. If you're not using threads in your program, this is less likely but still keep an eye out for it.
If nothing odd jumps out at you after reviewing the stack traces of the threads, let the program run a few seconds more, then break into it again with the debugger and have another look around. See what's different in the stack traces.
This should help you narrow down at least which bodies of code are involved in your hang.
If you don't see an exception before adding the exception handlers, you won't produce any MessageDlgs to see.
If the program is hanging (rather than blowing up with an exception) you could have a looping problem, or you could have some blocking call that's never completing. Write log messages to a window or file (you can use OutputDebugStr) to isolate the problem to one section of your code — at least to the body of one function. You may see the problem right away. If not, you can use OutputDebugStr, breakpoints, and trace to learn what's happening in that section of code on a line-by-line basis.
First: try to debug it in Delphi IDE.
Second: if you can't do this (on customer PC), try the "Process Stack Viewer" of my (open source) sampling profiler:
http://code.google.com/p/asmprofiler/wiki/ProcessStackViewer
(you need some debug info: a .map or .jdbg file)
Then look at the stack of your threads (probably main/first thread). You can post the stack trace here then (if you can't find the problem).
If you want help with this sort of thing in an app that you cannot use the IDE for, then something like madExcept can help a lot. It has an automatic freeze checker for the main thread, and you can have it give you a stack dump to show what it was doing when it was frozen. The user can choose to kill or continue, and the app can tell madExcept it is busy and not to alert if appropriate (for doing long analysis or printing or something).