C++ get run time and memory usage [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 3 years ago.
Improve this question
I've been practicing my C++ programming on LeetCode and whenever I submit a solution it will tell me how long my program took to run and how much memory it used.
I'm using a mac and VSCode with g++ to compile my program locally. I want to find a tool or method I can use to get the same information about the run time and memory usage of my program so I can try tweaking it to see the effect on performance.
Is there a compiler option or something like a command line tool or VSCode extension I can run my program through or would I have to add code to my program to track the time and memory itself?

For simple outputs, you can use gnu time.
As suggested on that page:
/usr/bin/time -f "time result\ncmd:%C\nreal %es\nuser %Us \nsys %Ss \nmemory:%MKB \ncpu %P" <command>
For a version on Mac OSX, just take a look on this answer: https://apple.stackexchange.com/a/235404

You can use valgrind to find memory leaks or profiling. And Google benchmark for code snippet benchmarks. Or you can measure time yourself with chrono.
And an online benchmark tool, quick-bench
Update:
I found this nice info on godbolt which gives insights on the number of iterations or cycles...
Thanks to #Peter the tool
llvm-mca estimates the Instructions Per Cycle (IPC), as well as hardware resource pressure.
Which is a simulation on a theoretical model of the CPU, not a profile but still could be useful. It also does not cover cache miss.

Related

How to find hot spot in a C or C++ program? [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 want to find hot spots in MiBench benchmark suit programs. I also want to find out which variables and functions are most called during execution of a program. I've searched for a free useful tool but i couldn't find what i want. Is there any free tool for this purpose?
Use gprof, you can compile you code with -pg, such as
gcc test.cpp -pg -o test
./test
gprof -b -A -p -q test gmon.out
Then it will print all the stat info of the code, read gprof documentation to understand better.
Also if you want to see all the detail of the code, such as cache miss rate or something else like that, you can try tau.

Speed up compilation time with a multicore machine [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 manage a build server for an open source project and it often needs to rebuild huge libraries that take at least 30 minutes to build on a 8-logical-core i7 Intel processor, maxing at several hours.
Lately I was wondering if there are some relatively cheap dedicated multicore boards which I could use for speeding up compilation times, but my google-fu couldn't find anything except Parallella on Kickstarter, googling which doesn't seem to come up with many results of my use case.
Do you know of any cheap multicore boards that I could use to speed up compilation of C/C++ software?
Cheap on-demand could services providing multicore/distributed compilation would work, but they are a lot less favorable since you would need to check that their compilers, libraries and whatnot are authentic, so that they won't be injecting any backdoors in whatever code you compile, which is quite hard to check.
That's why I'm primarily looking for a multicore boards that I could manage myself to offload the compiling task to.

QNX C/C++ software [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 8 years ago.
Improve this question
How can I get QNX C/C++ sample code?
Since QNX is proprietary, it can be hard to get a "jump start".
But as Research In Motion (the makers of BlackBerry) acquired it and are heavily investing on it - in the hopes to get as many developers as possible to jump on the new BBX platform, you may benefit from learning QNX via RIM - and maybe even winning a free Playbook tablet.
You can download the Native Development Kit (NDK) from this website: https://bdsc.webapps.blackberry.com/native/
It is a slightly modified version of Eclipse called Momentics. Using the Playbook simulator (which runs under a - hopefully - free version of VMWare) you can write, compile and run your QNX softwares.
I suggest you taking a close look at PPS objects. They are the most outstanding "idiosyncrasy" of QNX and mastering it will pretty much enable you as a QNX developer. Also, try to register for Foundry27 on QNX website and there you will find handful of (unfortunately almost hidden from Google) resources on QNX.
I hope that helps!
EDIT: and with the NDK it comes with a handful of examples. You will find them pretty much similar to POSIX.
QNX Community Resources is always a good source of help and sample code for QNX.
Usually, library reference entries have a small sample code, e.g. MsgDeliverEvent.
If you go to QNX.com, download the QDE/Momentics trial, you'll get an Eclipse-CDT which will have examples available from the start page.
QNX Neutrino is also similar enough to Linux/Unix systems that most software examples (for example socket and terminal io code) will be equally applicable to QNX as they are for their Unix system.

C/C++ call-graph utility for Windows platform [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 have a large 95% C, 5% C++ Win32 code base that I am trying to grok.
What modern tools are available for generating call-graph diagrams for C or C++ projects?
Have you tried doxygen and codeviz ?
Doxygen is normally used as a documentation tool, but it can generate call graphs for you with the CALL_GRAPH/CALLER_GRAPH options turned on.
Wikipedia lists a bunch of other options that you can try.
Have you tried SourceInsight's call graph feature?
http://www.sourceinsight.com/docs35/ae1144092.htm
Good old cflow works fine for C. See here for an implementation.
Any decent static analysis tool should have this functionality (as well as all the other stuff that such tools do). Wikipedia has a good list of such tools.
Another group of tools that may be worth checking out are coverage tools. The call graph generated by the coverage tool will contain only the calls that actually take place during a run of the program. Initially this may be more helpful to you than a full call graph. I'm unable to make any suggestions on this for Windows, but for linux projects I highly recommend gcov and lcov.

Multithreaded Debugger [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
GDB has severe issues when debugging with multiple threads (pthreads).
Are there any other good multi-threaded debuggers for C/C++ on *nix?
I've personally not had any GDB specific issues when debugging a multi-threaded application, so it may helpful for you to elaborate on exactly what "issues" you are having. It will help us answer you better.
There are several aids that I have used in the past when debugging multi-threaded applications in linux, most of which build upon GDB rather than replace it. These include:
DDD http://www.gnu.org/software/ddd/
Eclipse http://www.eclipse.org/
Native POSIX Thread Library (NTPL) Trace Tool http://nptltracetool.sourceforge.net/
Additionally, if you are new to debugging in Linux (and even if you aren't!) I highly recommend the paper titled "Debugging Linux Applications" which you can find here:
http://www.scribd.com/doc/3009706/Debugging-Linux-Applications
Allinea DDT ... graphical debugger for scalar, multi-threaded and large-scale parallel applications that are written in C, C++ and Fortran.
TotalView is what the national labs use for huge clusters. I believe it has some good support for thread parallelism, too. It's probably out of your price range, but you can try it for free.
From my search, I have not found any good multi-thread debuggers for *nix. GDB seems to be getting better, and the last time I had to debug a multi-threaded application on FreeBSD (7.0-RELEASE) it behaved fairly well, letting me find where the error was.
I once looked for a gdb alternative, but unfortunately every one I found was based on gdb. I think this is because gdb is intricately tied to gcc, and it's hard for third-party debuggers to keep up with every gcc change.
The AIX debugger for windows, let's you debug multithread applications.