title: How does gcc's -pg flag work?
body: <p>I'm trying to understand how the <code>-pg</code> (or <code>-p</code>) flag works when compiling C code with <code>gcc</code>.</p>
  
  <p>The official gcc documentation <a href="http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#index-pg-540" rel="noreferrer">only states</a>: </p>
  
  <blockquote>
    <p><code>-pg</code><br>
    Generate extra code to write profile information suitable for the analysis program gprof. You must use this option when compiling the source files you want data about, and you must also use it when linking.</p>
  </blockquote>
  
  <p>This really interests me, as I'm doing a small research on profilers - trying to pick the best tool for the job.</p>