C++ code dependency / call-graph "viewer"? [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
is there such a thing as a (free) tool that would display a graph of all functions call in a given function?
For instance, if I use it on a complex function fun() I'm trying to understand, it would show me all the functions called by fun() in order, then I would have the possibility to see the same thing for the function called by fun(), and so on.
I'm looking for this for C++ code.
Does such a thing even exist?
edit : I am using VS 2008 if that helps, but I was thinking that such a software would work on the source files anyway

Doxygen can do this. See the CALL_GRAPH configuration option:
If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will generate a call dependency graph for every global function or class method. Note that enabling this option will significantly increase the time of a run. So in most cases it will be better to enable call graphs for selected functions only using the \callgraph command.

Yes, Eclipse CDT Call Hierarchy view provides exactly this. Moreover, this view has 2 options:
Show Callers
Show Callees
You are asking about second one, but I am prefer the first one in code analysis.

Intel(R) Single Event API is free open-source project that utilises GraphVis for call-graph visualisation. It takes a bit of labour to do manual or compiler-automated instrumentation, but beside statistics and call-graphs you will get the overtime views as well.

Yes such things exist. Google under the heading static code analysis. There are, for example, tools such as Understand, and it is extremely likely that your compiler can do this too for which I refer you to its documentation.

You can use callgrind, and it's GUI tool kcachegrind.

I don't know of any tool specially desgined for this. However, there are a few ways of doing it:
Using a IDE (QtCreator is free, Visual Studio Express might also be helpful, Eclipse CDT)
Using (ctags)[http://ctags.sourceforge.net/] and a able text editor.
Using callgrind and the several views it brings. Advantage: you get to see the functions that are really called. Disadvantage: only runs in unixes, and you have to profile.
Using Doxygen... this one is really fancy, as it generates an html "view" of your code, provided that you supply the correct options.

g++ and most compilers can do what you want. It is called profiling. Also there is the oprofile. A profiler gives you the call graph of an application after its execution. This is very useful to study code, you can also walk through the [debug] output as you look at the graph. A code analyzer, in contrast, will give you all possible call paths however, you will not be able to see the significant path easily.

VC++2008/2010 profiler generates among others the file *CallerCalleeSummary.csv, that contains this information. And this is the link to the article explaining how to use it with sample program: Profiling of C++ Applications in Visual Studio

Related

Stripping C++ library of not required code for an application [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have an application dependent on many libraries. I am building everything from sources on an ubuntu machine. I want to remove any function/class that is not required by an application. Is there any tool to help with that?
P.S. I want to remove source code from the library not just symbols from object files.
Standard strip utility was created exactly for this.
I have now researched this a bit in the context of my own project and decided this was worth a full answer rather than just a comment. This answer is based on Apple's toolchain on macOS (which uses clang, rather than gcc), but I think things work in much the same way for both.
The key to this is enabling 'link time optimization' when building your libraries and executable(s). The mechanics of this are actually very simple - just pass -flto to gcc and ld on the command line. This has two effects:
Code (functions / methods) in object files or archives that is never called is omitted from the final executable.
The linker performs the sort of optimisations that the compiler can perform (such as function inlining), but with knowledge that extends across compilation unit boundaries.
It won't help you if you are linking against a shared library, but it might help if that shared library links with other (static) libraries which contain code that the shared library never calls.
On the upside, this reduced the size of my final executable by about 5%, which I'm pleased about. YMMV.
On the downside, my object files roughly doubled in size and sometimes link times increased dramatically (by something like a factor of 100). Then, if I re-linked, it was much faster. This behaviour might be a peculiarity of Apple's toolchain however. Perhaps it is stashing away some build intermediates somewhere on the first link. In any case, if you only enable this option for release builds it should not be a major issue.
There are more details of the full set of gcc command line options that control optimisation here: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html. Search that page for flto to narrow down your search.
And for a glimpse behind the scenes, see: https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html
Edit:
A bit more information about link times. Apple's linker creates some huge files in a directory called LTOCache when you link. I've not seen these before today so these look to be the build intermediates that speed up linking second time around. As for my initial link being so slow, this may in part be due to the fact that, in my case, these are created on an SMB server. But then again, the CPU was maxed out so maybe not.
OK, now that I understand the OP's requirements better I have another answer for this that I think might better suit his needs. I think the way to tackle this is with a code coverage tool. After all, the problem is identifying what you can safely get rid of it. Actually stripping it out is easy.
My IDE (Visual Studio) has one of these built in but I think the OP is using gcc so the first port of call appears to be gcov. There are a number of commercial options, but they are expensive. There's also a potentially useful post here.
The other thing you need, of course, is a program that exercises all the parts of the library that you want to keep to give you a coverage report to work from, but it sounds like the OP already has that. A good IDE will also help as it makes navigating around the code so much easier. In Visual Studio, I find Jump to Definition and quick and easy 'bookmarking' to be key features.

Good free profiler that supports MingW32 please? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I asked in another thread, how to profile my stuff, and people gave me lots of good replies, except that when I tried to use several of free profilers, including AMD Codeanalyst for example, they only support Microsoft PDB format, and MingW is unable to generate those.
So, what profiler can help me profile a multi-threaded application with Lua scripting and is compiled with MingW?
EDIT: gprof is crap, the awnser that says why I don't want it, is right on the spot... If I get all the functions that it litsts as troublesome, NONE of them are related to the issue that I have (there are a certain action that causes a massive slowdown, and I can't figure why, and gprof can't figure it either)
If you don't want to use gprof, I'm not surprised.
It took me a while to figure out how to do this under GDB, but here's what I do. Get the app running and change focus to the app's output window, even if it's only a DOS-box. Then I hit the Control-Break key (while it's being slow). Then GDB halts and I do info threads and it tells me what threads there are, typically 1 and 2. I switch to the thread I want, like thread 2. Then I do bt to see a stack trace. This tells me exactly what it was doing when I hit Control-Break. I do this a number of times, like 10 or 20, and if there's a performance problem, no matter what it is, it shows up on multiple samples of the stack. The slower it makes the program, the fewer samples I have to take before I see it.
For a complete analysis of how and why it works, see that link.
P.S. I also do handle SIGINT stop print nopass when I start GDB.
Does gprof not do it?
I thought MingW provided a gprof version to go with it.
If you want to profile Lua scripting, I could suggest using the LuaProfiler: http://luaprofiler.luaforge.net/manual.html. It works quite nicely.
I would strongly suggest implementing some sort of timers or your own profiler to get a simple profiling tool. A really simple one is to just output the times when certain points in your code is hit, output those times into a textfile and then write a simple lua or python script to parse the file and filter the interesting information.
I've used this (or a slightly more complex) version of profiling for most of my hobby-projects and it has proven very helpful.

Code polisher / reformater for C, C++ or Fortran [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Suppose you have got a bunch of files written in C, C++ or Fortran, by different authors, with different opinions on formatting, how to comment, and so on. I think many people know situations like these.
Are there any free tools for ends like:
uniform format of code (indent, etc.)
create standard comment bodies
rename variables
?
Have a look at
AStyle. It's a command line based formatter/beautifier. It doesn't handle Fortran though it works with C, C++, C# and Java
You can have a look at the indent (unix) command. It doesn't do everything you are asking for , but that's a good start I think
For Fortran there is plusFORT, which can do much more than what you ask for, such as reorganizing code and translating from FORTRAN 77 to Fortran 90. See http://www.polyhedron.com/pf-plusfort0html and http://www.polyhedron.com/pflinux0html
The CDT Plugin for Eclipse has great formatting and refactoring tools for C/C++.
The formatter can be customized to fit almost all needs.
Also the refactoring tools are quite powerful and renaming variables, classes etc. is an easy and safe task with them. (They use the indexer/parser to recognize scope of variables, so its not a simple search and replace. Matching patterns within comments can be changed automatically, too).
However, as far as I know there is no batch processing possible.
Edit: Another - obvious - drawback is, that you have to create a project to make the indexer (and thus the refactoring tools) work. So at least you have to add all include paths and important compiler defines to project settings.
I never tried, but the indexer should work fine without a real compiler available, but it may be necessary to make the project to use the "internal builder", otherwise you cannot set include paths. (I'm unsure about this, because I use the internal builder with gcc in my projects - this works fine.)
I've used Uncrustify with UniversalIndentGui for formatting C++ code. It works pretty well. Uncrustify offers many customization options and UniversalIndentGui "offers a live preview for setting the parameters of nearly any indenter. You change the value of a parameter and directly see how your reformatted code will look like."

C++ logging framework suggestions [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm looking for a C++ logging framework with the following features:
logs have a severity (info, warning, error, critical, etc)
logs are tagged with a module name
framework has a UI (or CLI) to configure for which modules we will actually log to file, and the minimum severity required for a log to be written to file.
has a viewer which lets me search per module, severity, module name, error name, etc
Not sure about the configuration from a UI or CLI. I've used both of these logging frameworks at one point or other.
https://sourceforge.net/projects/log4cplus/
https://logging.apache.org/log4cxx/index.html
It wouldn't be too hard to drive your logging based on a configuration file that could be editable by hand or through a quick and dirty GUI or CLI app. Might be a bit harder to adjust these dynamically but not too bad.
Update:
It looks like the proposed Boost.Log is now in Boost 1.54 which is at a stable release. If you are already using Boost than I would take a look at it.
No viewer but you could try pantheios. I have been using it for almost a year now and am quite happy with it.
I strongly suggest Pantheios, as it's the only one that's completely type-safe, and is also very efficient. It imposes a little work on the user, in selecting the right "front-end" and "back-end", but once you've got it working, you can just fix and forget.
It doesn't provide sophisticated logging facilities - e.g. rolling files - but that's by design, because it's intended to be used in combination with other logging libraries that have more functionality (but poorer performance / type-safety).
If you care about performance, I suggest you check out Pantheios. In particular, it's got very high performance, and it can be used in combination with other logging libraries -- it acts as an efficient and type-safe layer between the logging library (such as log4cxx) and your application code.
You could use wxWidgets and use it's excellent class for logging. It's rather easy and straightforward. For instance, you can create a dialog which gathers all your logs (e.g. wxLogError, wxLogMessage, wxLogDebug, etc.).
Pantheios is a good candidate in term of perormance but my personal preference is P7 library.
My internal tests (CPU i7-4870HQ, SSD) shows that P7 is faster than Pantheios.
Pantheios writes 1.8M logs lines per second (time & text message)
P7 writes 2.4M logs lines per second (time, thread, CPU core, function, file, line and text message)

Visually marking conditional compilation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
We have a large amount of C/C++ code that's compiled for multiple targets, separated by #ifdefs. One of the targets is very different from the others and it's often important to know if the code you're editing is compiled for that target. Unfortunately the #ifdefs can be very spread out, so it's not always obvious which code is compiled for which targets.
Visual Studio's #ifdef highlighting can be helpful for visually identifying which code is compiled for which target, but changing the highlighting apparently requires modifications to the project file.
I'm interested in finding a tool or method that can help coders quickly recognize which targets are using each line of code. Even if it requires some sort of manual in-source annotation I think it could still be helpful. Best case it's automated, not tied to a specific editor or IDE, and it could be configured to warn in certain conditions (eg "you modified some code on Target X, be sure to test your code on that platform!").
If your code is getting that big that you can't tell what #ifdef your in then it's time to refactor your code. I would recommend that you refactor it into seperate cpp files per platform.
I noramlly only use #idef when the code is only one or two lines long, any longer and I normally refactor into it's only function or class into there own cpp file. That makes it simple to figure out where you are.
Check out Visual SlickEdit. The "Selective Display" option might be what you are looking for. I can't find any on-line documentation on it, but it will allow you to essentially apply a set of macro definitions to the code. So you can tell it to show you the code as the compiler will see it with a set of macros defined. This is a lot more than preprocessor output since it literally hides blocks of code that would be excluded based on the macro definitions.
This doesn't give you the ability to answer the question "Under what preprocessor conditions is this line of code included in compilation" though. The nice thing is that it applies the selective display filter to searches and printing.
I know for a fact that eclipse cdt does it. It has other nice features and some not-so-nice features for an IDE. Now, I code with vi, so I might be biased.
I don't know if there is a tool for this already, but I'd guess would be fairly easy to roll your own by using the precompiler. Precompile your file with a set of specific #defines and the output is what the compiler sees for that platform. I reckon this is not the same as highlighting the current file, but it can be automated and integrated into your IDE, push a button get a temp file with te current edited one under specific #define. Didn't try it myself, is just an idea.
PS. Yes, I had to read couple times your post to searching for where exactly is 'code coverage' involved lol.
Check XRefactory and Cscout.