aboutsummaryrefslogtreecommitdiff
path: root/libraries/libprof/README.txt
blob: 1fe378c6d2a712ea740dba9e8eb3c85cc48fe4c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Profiling the Cryptech Alpha
============================

Origin
------

This code was copied from https://github.com/ErichStyger/mcuoneclipse.git,
directory Examples/KDS/FRDM-K64F120M/FRDM-K64F_Profiling/Profiling, commit
9b7eedddd8b24968128582aedc63be95b61f782c, dated Mon Jan 9 16:56:17 2017 +0100.

References
----------

I recommend reading both of these to understand how the profiling code works.

[1]: https://mcuoneclipse.com/2015/08/23/tutorial-using-gnu-profiling-gprof-with-arm-cortex-m/
"Tutorial: Using GNU Profiling (gprof) with ARM Cortex-M"

[2]: http://bgamari.github.io/posts/2014-10-31-semihosting.html
"Semihosting with ARM, GCC, and OpenOCD"

How to build
------------

From the top level, run

    make DO_PROFILING=1 hsm

By default, all code is profiled, *except* the profiling code itself,
because that would cause fatal recursion.

How to run
----------

You need to start OpenOCD on the host, and enable semihosting, at least
before you try to use it as a remote file system.

I recommend executing the following in the projects/hsm directory, so that
gmon.out ends up in the same directory as hsm.elf.

Start OpenOCD:

    $ openocd -f /usr/share/openocd/scripts/board/stm32f4discovery.cfg &

Connect to OpenOCD:

    $ telnet localhost 4444

In the OpenOCD console, enable semihosting:

    > arm semihosting enable

In another window, start the debugger:

    $ sw/stm32/bin/debug projects/hsm/hsm

In the CLI, type `profile start`, then start the unit test or whatever
will be exercising the hsm. Afterwards, in the CLI, type `profile stop`.

After invoking `profile stop`, it can take several minutes to write
gmon.out over OpenOCD to the host.

In the projects/hsm directory, run gprof to analyse the gmon.out file:

    $ gprof hsm.elf >gprof.txt