You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: debugging.md
+53Lines changed: 53 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,6 +151,59 @@ Here are a few useful commands for getting around in psp-gdb:
151
151
152
152
You can type`help`for more information about the psp-gdb commands.
153
153
154
+
## Using a Profiler
155
+
{: .fs-6 .fw-700 }
156
+
157
+
When your application is running slow, you might want to know which functions are taking up the most time. A profiler can help with this and the PSPDEV SDK includes one called `psp-gprof`.
158
+
159
+
### Preparation
160
+
{: .fs-4 .fw-700 }
161
+
162
+
To prepare forprofiling, the application will have to be build using the flags `-pg` and `-g`. If you are using a Makefile, you can add these to `CFLAGS` likein [this example](https://github.com/pspdev/pspsdk/blob/master/src/samples/gprof/basic/Makefile.sample#L5). If you are using CMake, you can add the following line to your `CMakeLists.txt` to make it so debug builds can be profiled:
To use `psp-gprof` with an application with build in profiling support like shown above, just run it in PSPLINK and run the part of the application you want profiling information of. Then close it gracefully. After this a file called `gmon.out` can be found in the directory where the application is in.
184
+
185
+
To profile the application we run `psp-gprof` on the `gmon.out` file like so from a terminal in the directory where the application is:
186
+
187
+
```sh
188
+
psp-gprof file gmon.out
189
+
```
190
+
191
+
> You need to replace `file` with the elf file of the program you're trying to profile. It has the same name as the file loaded in pspsh, but without the `.prx` ending.
192
+
193
+
The output should start like this:
194
+
195
+
```
196
+
Each sample counts as 0.001 seconds.
197
+
% cumulative self self total
198
+
time seconds seconds calls ms/call ms/call name
199
+
95.98 0.17 0.17 104728 0.00 0.00 is_prime
200
+
4.02 0.17 0.01 1 7.00 7.00 dummy_function
201
+
0.00 0.17 0.00 1 0.00 174.00 main
202
+
0.00 0.17 0.00 1 0.00 167.00 sum_of_square_roots
203
+
```
204
+
205
+
It will even contain a breakdown of which function was called from where. In this case `is_prime` was called a lot, taking up a significant amount of time. Perhaps it would be possible to lower the amount of calls to it to gain performance. Another option might be to optimize `dummy_function`, since it is taking 4% of the time despite only being called once. Optimizing based on the result is up to you, but it is a whole lot easier with profiling information than without.
0 commit comments