![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I profile C++ code running on Linux?
In Linux platform there are many great profiling tools for profiling C++ programs. Valgrind is one of them. It is widely used. It is a programming tool for memory debugging, memory leak detection, and profiling. We can use Valgrind by passing the binary to it and setting the tool to callgrind. First generate the binary by compiling the program
$ g++ -o abc.cpp abc
Now use valgrind to profile it
$ valgrind --tool=callgrind ./abc
This will generate a file called callgrind.out.x. You can read this file using a tool called kcachegrind.
If you're using gcc, you can use the inbuilt profiling tool, gprof. You can use it while compiling the file as follows
$ g++ -o abc abc.cpp -g -pg
Advertisements