adding gprof page
This commit is contained in:
@@ -5,13 +5,13 @@
|
|||||||
|
|
||||||
## Installing `gprof`
|
## Installing `gprof`
|
||||||
```sh
|
```sh
|
||||||
sudo apt-get install binutils
|
$ sudo apt-get install binutils
|
||||||
```
|
```
|
||||||
|
|
||||||
## Compiling a C++ Program for Profiling
|
## Compiling a C++ Program for Profiling
|
||||||
To use `gprof`, compile your program with the `-pg` flag:
|
To use `gprof`, compile your program with the `-pg` flag:
|
||||||
```sh
|
```sh
|
||||||
g++ -pg -o my_program my_program.cpp
|
$ g++ -pg -o my_program my_program.cpp
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example C++ Program
|
## Example C++ Program
|
||||||
@@ -39,16 +39,16 @@ int main() {
|
|||||||
## Running and Profiling the Program
|
## Running and Profiling the Program
|
||||||
1. Compile the program:
|
1. Compile the program:
|
||||||
```sh
|
```sh
|
||||||
g++ -pg -o my_program my_program.cpp
|
$ g++ -pg -o my_program my_program.cpp
|
||||||
```
|
```
|
||||||
2. Execute the program to generate `gmon.out`:
|
2. Execute the program to generate `gmon.out`:
|
||||||
```sh
|
```sh
|
||||||
./my_program
|
$ ./my_program
|
||||||
```
|
```
|
||||||
3. Analyze the profiling data:
|
3. Analyze the profiling data:
|
||||||
```sh
|
```sh
|
||||||
gprof my_program gmon.out > profile.txt
|
$ gprof my_program gmon.out > profile.txt
|
||||||
cat profile.txt
|
$ cat profile.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
## Understanding the Output
|
## Understanding the Output
|
||||||
|
|||||||
Reference in New Issue
Block a user