How does gcc's -pg flag work?

前端 未结 3 1684
一向
一向 2020-12-08 03:11

I\'m trying to understand how the -pg (or -p) flag works when compiling C code with gcc.

The official gcc documentation only s

3条回答
  •  悲&欢浪女
    2020-12-08 03:30

    From this source: https://elinux.org/images/0/0c/Bird-LS-2009-Measuring-function-duration-with-ftrace.pdf :

    " Instrumentation comes in two main forms—explicitly declared tracepoints, and implicit tracepoints. Explicit tracepoints consist of developer defined declarations which specify the location of the tracepoint, and additional information about what data should be collected at a particular trace site. Implicit tracepoints are placed into the code automatically by the compiler, either due to compiler flags or by developer redefinition of commonly used macros.

    To instrument functions implicitly, when the kernel is configured to support function tracing, the kernel build system adds -pg to the flags used with the compiler. This causes the compiler to add code to the prologue of each function, which calls a special assembly routine called mcount. This compiler option is specifically intended to be used for profiling and tracing purposes. "

提交回复
热议问题