Is it possible to get back traces with the profiling output from Callgrind?
If it is, would you be able to explain how that's done?
[update] It could be my terminology. What is the backtrace/callstack called and where does it reside when using Kcachegrind to view Callgrind profiling results?
When you launch Kcachegrind for the first time, you have three areas :
At left, you have a DockWidget entitled "Flat profile", there is the list of the functions sorted by the percentage of cost in the application, including all sub-calls. (that's why the main usualy cost almost 100%).
Then in the bottom-right area, you have another dockwidget which have a "call graph" tab, there is here you have the tree of all the calls, and maybe what you are looking for ;)
But if you want a backtrace at a specific point, with more informations about the context, I advise you to use gdb with a breakpoint here, and continue the execution until you reached the context you want.
Profiling is mainly used to locate what function cost the most in your application, and then see if you can optimize it.
Related
I have a C++ function that I want to profile and only that function. One possible way is to use chrono and just measure the time it takes to run that function and print it out, run the program a few times and then do stats on the samples.
I am wondering if I can skip having to explicitly code time measurements and just ask perf to focus on the time spent in a specified function.
Have a look at Google's benchmarking library to micro-benchmark the function of interest.
You can then profile the resulting the executable as usual using perf.
For example, let's say that following the basic usage, you generated an executable named mybenchmark. Then, you can run perf on the binary as usual
$ perf stat ./mybenchmark
You can build a flame graph of whole application in SVG format. With flame graph you can quickly see function that take most of the time when consuming CPU. SVG flame graph is interactive: you can click any function and see detailed flame graph only for that selected function. From description of flame graphs:
It is also interactive: mouse over the SVGs to reveal details, and click to zoom.
You can try it in action for sample bash flame graph:
http://www.brendangregg.com/FlameGraphs/cpu-bash-flamegraph.svg
I am learning how to use quantlib to price derivatives. What is the best way to output some of the Quantlib specific classes to console window? For example
shared_ptr<YieldTermStructure> forwardCurve(new InterpolatedDiscountCurve<LogLinear>(dates,discountFactor,Actual360()));
Handle<YieldTermStructure> forwardingTermStructure(forwardCurve);
shared_ptr<IborIndex> euribor(new Euribor(3*Months,forwardingTermStructure));
What will be the best way for me to output forwardCurve to and euribor to console window? Then I can see the intermediate result of the code to see if they are as expected.
Many thanks.
There's no predefined way to output those classes to console, but you can use their inspector to output the relevant data (so, e.g., you can call forwardCurve->times() and forwardCurve->discounts() to inspect the values you're interpolating) or you can call their methods to see the results of their calculations (e.g., forwardCurve->discount(d) to retrieve the discount factor at a given date, or euribor->fixing(d) to retrieve the expected index fixing). The returned values can be written to console.
As an alternative, you might consider stepping through the code inside a debugger. In modern IDEs, this will give you the same information more easily.
I hope this makes sense, I am not sure how exactly I should word this...
Hi, I am trying to write a program that will be able to monitor the audio output of certain processes. I am having a hell of a time finding a way to actually do this. I have only been able to find ways to get the current volume level, but not the actual output level. I've been searching through Stackoverflow, but everything I've found is only able to fetch the program's volume control level (like the slider in the Windows Volume mixer, however I am basically looking to get the value of the fluctuating green bar in the mixer)
I basically want to check the output level of a program every x milliseconds and if it is above a certain threshold, run a method to do something. How can I do this?
Thanks!
Quick edit to be clear: Win 7+ with C++
You probably want IAudioPeakMeter
This sample app here looks promising.
Well, lately I have found a very interesting article about Map Hacks in online games.
After reading it I read they used a memory scanner to look for images in the memory.
How would they accomplish such a program, is there a solution for this freely available?
if not how would I code it in C++? How can I know a piece of memory is an "image"?
I can load my own DLL into the process so that shouldn't be a big issue..
To answer your questions:
A memory scanner uses OS apis to query memory from another process and perform searches for patterns or differences. A great tool for this is cheat engine.
The tool mentioned in the article visualizes the memory by coloring pixels according to the value of the bytes in memory. The alignment still needs to be done manually and could be very time consuming. I don't think the mentioned program was ever released.
The main problem is that you can't know that a particular piece of memory is supposed to be a map. Any big regular structure could look like one when colorized and aligned. Finding the actual piece of memory you are looking for is very hard.
Additional Info:
A property map in a game is very dynamic. If units or something moves the visibility has to update. So the actual format of a map like this is most likely a binary bitmap with no specific image format (png,jpg,...).
I personally find the approach to look for a map structure in memory is a very inefficient and time consuming approach. It's beatuful to show to people that have no idea about reverse engineering, but to me seems very impractical. The approach which is best totally depends on the game and your creativity.
I hope I can help you with the following example how I made a map hack for starcraft 2.
My idea was to load up a replay of a game, where I had full view of the map and find the difference to loading up a normal game where my vision is restricted. I switched a couple of times between replay and normal game and could indeed find a state variable that was 0 on normal game and 1 on replay (a common tool for finding memory like this is cheat engine).
Next I loaded the game up in a debugger and put a memory access breakpoint on this state variable. Now when loading up a normal game I would change the value when it is accessed while the map was loading. Through some trial and error I was able to find the correct location that was responsible for revealing the minimap and real map. The only task left was to create a dll that detours the code location and make sure the map is always revealed on every mapload.
Reply to typ1232: You mention that it's hard and impractical to find the map structure in memory. Heres a method I have had great success with: Load up a map in any game with fog of war, like StarCraft 2. Take a dump of the memory and save it. Send out troops/units and reveal as much of the previously undiscovered map and take another memory dump. Compare the two dumps and look closer at the areas in memory where there are a high frequency of changes. This is likely to be where the map is stored.
Sorry if I'm doing it wrong, new to stackoverflow :)
This might be a bit broader answer to the subject of "finding data" but there are binary analysis tools out there. For example, ..cantor.dust.. is a binary visualization tool (though its only in beta the idea remains the same). You can search for different patterns within a memory dump for "images" or structures. Youtube cantor dust and the creator did a presentation at DerbyCon of how he used it to find EFI structures to recreate an exploit of a PNG parser at the EFI level.
I also think the saving two memory states of visible map vs limited visibility map and search for the changes is viable, if not the best option, I just am trying to point out an alternative.
I was trying to find if there exists a library or tool that will allow me to visually debug my program. i.e. something that shows a graphviz like tree structure and highlights exactly where I am in the process tree at a breakpoint. This would give a faster understanding of how my process works rather than sequentially debug through and create a tree in my mind.
I found something that partially does what I am looking for, i.e. show a tree structure of my process and the number of calls made per function call
http://www.ibm.com/developerworks/library/l-graphvis/
If it doesn't exist then I might plan on writing something that does the job. Thanks
-CV
The debug visualization plugin for Eclipse sounds like something that might be helpful for you. Furthermore, the venerable Data Display Debugger also has some automatic routines for creating graphs, albeit of the data structures you are currently seeing. I also like the visualization of kcachegrind, but it is not exactly a debugging aid. However, its graphical view shows you the position in the execution tree.
Since there does not seem to be a tool that matches your requirements exactly, maybe these ones will inspire you to write your own ;)