When analyzing stack traces with Windbg, I am using ~*e!clrstack
It would be useful to have a way to report identical stacks only once, especially when the number of threads is large.
One option would be a small parser utility for the output, but this requires additional steps.
Is there some Windbg extension or command that could help?
For native code, you would use !uniqstack to display a stack trace for each thread with similar stack traces omitted.
I'm not sure that an equivalent managed extension command exists. Your best bet for an overview may be to use !EEStack -short -EE to hide stacks that are not running managed code, holding a lock, or waiting on GC.
Depending on the problem you are looking at, one or the other (or maybe both) could help you.
You can simultaneously open the dump in Visual Studio 2010 or 2012 and use the “parallel Stacks” window. Don’t know how good this works is for managed.
Related
My CPU is oscillating between 20 and 30% usage for CPU usage based on Windows Task manager. it is occurring for several hours now.
I expect this VS Code instance to do nothing.
How can I investigate what is going wrong?
I tried to open "Developer: Toggle Developer Tools", then go to performance tab and record. Unfortunately it is reporting that most of the time is in "idle" (which is what I would expect)
(I also tried to ask on Twitter without success https://twitter.com/apupier/status/1100348567926071296)
regards,
Based on the comments it seems that what the Task Manager reports is the total use of VS both on CPU utilization and memory.
A broad range of reasons could explain the observations you made.
1.Increased CPU and Memory usage by VS Studio.
2. Increased Fan Speed.
3. Your code being idle.
It can be the case that the VS Code or one of its plugins is actually doing something even if you do not actively use it. For sure if it is opened, even without being used the program will use some memory.
You can find more information on the CPU usage per VS Code Extension by typing: code --status in the command line. You can also try to execute: code --disable-extensions to run VS Code without any extensions to see if the CPU/Memory usage is reduced.
Results of the code --status will look like this
There are some related issues you could also see in GitHub, I checked before writing this answer:
100% core CPU usage without apparent reason
Excess CPU usage
Excess CPU usage editing C file
It is usually an extension. E.g. Python Intellisense. It is perhaps outsourcing processing for some scientific project aimed for the good of humanity. Fingers crossed.
Update 2022:
Earlier you could find them easily with VS Codes builtin Process Explorer. Help > "Open Process Explorer."
But the newer versions are very sneaky. They seem to have evolved making them difficult to catch while stealing your cpu. Disclaimer: the behavior may very well be even an unintentional glitch although it does not appear so.
Can you catch it in action?
Its as tough as catching a fly. As of Feb 2022, the moment you attempt to probe into the cpu usage either via vs code "help/Open Process Explorer" OR sometimes even win task manager, it stops/vanishes like a fly. Then it stays inactive for some hours or a day. You forget about it and get busy coding only to find the fans are going crazy because it has sneaked in to be active again. The newer version of the bug is perhaps programmed as such.
None the less with a lot of patience, you can sometimes catch them. Here is one instance and yet it vanished before i could scroll to catch the name.
VS Code Process manager
Solution:
I don't have a reason to probe it beyond a limit, but a small monitoring script should be able to catch the culprit.
Personally, I just had to remove the "Python extension for Visual Studio Code (Python IntelliSense - Pylance)" and that was enough to resolve.
IDE's a notoriously expensive to run. As soon as you open VS Code it loads the program from your hard drive, into RAM; acting as a staging point for all the processes VS Code uses to manage its environment. Things like,
Overhead of the Electron framework upon which it is built
Checking for external file changes that need to be synchronized to the editor
Render pipeline
Child processes to support any extensions you have running
Terminal instances (and by extension anything running in those terminals)
Here's a nifty little extension I found after some quick Googling. It will show you the subprocesses running in VS Code, and may help you identify exactly what is taking up the most bandwidth. Do keep in mind, that by killing some of those processes, you may begin to lose the associated functionality, and indeed possibly even cause VS Code to crash. The only sure-fire way to keep it from taxing your CPU, is to shut it down completely when you're not using it.
Perhaps you could try out another IDE like Sublime, IntelliJ, or Atom and see if they act more as you expect when idle. Personally, I really love the features of Jetbrain's IntelliJ (and similar: Webstorm, PhpStorm, etc).
I got the same problem. It might have something to do with the git operations. You might have DELETED many projects from your current folder, while git didn't register the deletion.
When you do something with the changes, git operations will use a lot of CPU.
The simplest solution is to create a new folder and start running VSCode in it. You can delete the whole old folder, or you can leave it alone. It's up to you.
TLDR: C program, hundreds of threads, Eclipse (Oxygen 3) CDT debug view with lengthy tree. How to search?
I'm debugging some software I've written (in C, FWIW) that can generate several hundred threads. About 300 of these are started at launch, and about as many others are started dynamically to perform tasks at runtime. During certain operations I can have well over 500 threads running.
In earlier versions of the software it was possible to exercise a problem to debug it in such a way that only a handful of threads were running when the failure (eg. segfault etc) occurred, so it was reasonable to just look through the thread list in the Debug view and have an understanding of what's going on. More recently I've made many more threads launch at the beginning and while that's had a huge benefit on performance, it means that at any time I'll have a list of threads that's just too long to manually look through.
How can I find a thread based on something I know about the thread, i.e. what function it was started with (passed to pthread_create())? Specifically, how can I search through the tree displayed in the Debug window? Alternatively, I've found a way to copy the contents of this view to the clipboard, but (inexplicably) this only copies what's visible, not the actual tree contents -- how can I auto-expand the entire tree so I can copy it and search in a text editor? Clicking the little arrows to expand each of hundreds of threads to their respective call stacks is just not reasonable.
I'm developing on a RHEL 6 platform (long story, migration to modernity is pending), and for the moment I've found roadblocks in upgrading beyond Eclipse Oxygen 3a (4.7.3a), so that's what I'm stuck with for now.
EDIT: I should clarify -- it's true that I can just press Ctrl-F in the Debug window, and I get a search dialog. However, and I'm seriously dropping my jaw in disbelief here, it also only searches what's visible, not the actual contents of the tree. So for this to be useful, I'd still have to expand every thread in the list manually; there still appears to be no command to do this.
It appears that there is simply no way of searching the list of threads within the Debug view in Eclipse, in a way that is actually useful. Again, the "Find" and "Copy Stack" functions (accessible via right-click) only operate on the text that's visible in the GUI view, not the real contents of the tree.
So, as far as I can tell the only way to get the information I want is to query gdb directly, through the Debugger Console view:
thread apply all bt
OF COURSE, the contents of the Debugger Console view are not directly searchable (unlike the regular Console and most other views in Eclipse), so the text listing must then be copied and pasted into some other editor and searched, to find the thread I'm looking for. Then, with that information I can scroll to it in the Debug list, expand that thread's trace, and continue debugging.
I am using Eclipse Kepler Service Release 2 , EPIC 0.5.46 and Strawberry Perl 5 version 18 for perl programming. For debugging I am using Eclipse debugger and PadWalker .
I have an interactive perl program that writes to files based on answers provided by the users to multiple prompts. While debugging , every time i change a single line of code I have to rerun the whole program again and provide inputs to every prompt , which is really time consuming.
Is there a way to make changes to the code in a sub routine , in the middle of debugging session such that the instruction pointer resets itself to the first line of that sub routine. This way i do not have to restart the session to recompile the new code.
Appreciate your inputs and suggestions. Thank You!!!
What you want to do can be done, and I've done it many times in Perl myself. For example, see this.
However although what you describe may work (and is a bit dangerous), the way it is generally done a bit different and safer.
First one has to assume a regular kind of command structure like a command processor, or say a web server.
In a command processor or web server, you read a command (or get a web request), perform an action, then read another command, perform another action and so on. From your description, it sounds like you have such a structure.
In my case, I have each debugger command stored as in Perl file. This is helpful not only for facilitating this task, but also for understanding, testing and changing the code.
Given this kind of program structure, instead of trying to change the program counter, you complete the command and at the level where you are about to read a new command, you make the change and then reload the file which changes the code.
The specific Perl construct to do this is called do. Don't use require or use which will load in a Perl file only if that file or module hasn't been previously loaded. In your situation, you want to reload even if it has been loaded before.
So now how do you get to be able to issue a do command? As you suggest, you could do it through a debugger. Assuming you have this overall program stucture as described above, you put the breakpoint somewhere a common point in the caller which loops over things to process, rather than try to change things in indvidual commands.
And you don't even need a debugger to do this! Many web frameworks like Ruby on Rails, have a "development" mode where they save timestamps on files that implement functionality. If the file has changed they issue the "do" command before running the request.
I would like to know how it's possible to run a integrity test without starting it in background. So I want to run it in foreground and wait until it's finished.
The following runs on background (http://docs.intersystems.com/cache20071/csp/docbook/DocBook.UI.Page.cls?KEY=GSA_manage):
Do Silent^Integrity("/tmp/logfile")
I also can't find the routine of ^Integrity (in %SYS). How may I see the code?
Using Caché Intersystems 2008.
Thanks by advance,
In the %SYS namespace, you can run ^Integrity directly without providing a tag name, e.g.:
> Do ^Integrity
You should be able to view the source code in Cache Studio in your version, assuming you are in the %SYS namespace. I can pull it up fine in Cache 2010, though I understand that Intersystems has stopped providing the underlying source for much of their standard codebase in more recent versions. If, in fact, you don't have the source for ^Integrity available on your system, you'll simply have to contact them for any information you need beyond what the documentation provides.
I am looking to develop a framework, for which I dont want get into details.
Suppose if I am having 100+ classes with 1000+ methods in my iPhone application.
In this scenario I want to add NSLog in each method(at start or end or both) of each class.
Manually adding NSLog is possible but is there any better solution?
Like building application in such a way that I can add this Log without me having to do manual work.
Thanks and Regards,
Denis,
Your answer was most useful throughout many forums.
Thanks a lot.
The reason I'm looking for something like this is, we have many client projects and many time it happens that we get some crashing or other issues while QA and UAT. ~80% of them are not reproducible or require some particular scenario. We were using .crash and dsym to track such issues. But it is not that useful in such scenario.
What I'm looking for is providing add hoc build which will log the steps which user has followed so that it will make easy to reproduce such issues.
Currently I am using precompiled headers and first method you have mentioned (searching for the first opening brace then replace it with macro).
I will look into DTrace and objc_msgSend as you mentioned. I will google out these meanwhile if you have any preferred tutorials it will be great.
Thanks and Regards,
:D
So you want to add a trace facility to your code?
Apple doesn't provide anything like this. You'll have to add your trace facility yourself. If your source code style is consistent, this might be relatively easy to do automatically, something like searching for the first opening brace following a line starting with a minus (or plus) sign...
Alternatively, you might want to use the public Objective-C runtime functions to enumerate all classes and all their methods, then method-swizzle each of them with another one that NSLog before jumping to the original.
Alternatively, you can take the open source implementation of objc_msgSend and insert a call to NSLog at the beginning. Note that obj_msgSend tail calls into the method, so that will prevent you from adding a call upon return. Be prepared to humongous output of course. You might want to condition your call to NSLog to the value of the selector parameter to objc_msgSend (such as a common prefix).
Finally, the best way to trace is probably to attach a DTrace probe to the entry to objc_msgSend. For the same tail-call reason mentioned above, you won't be able to attach a DTrace probe to its return though.
But the better question is why do you want to do that.