| OLD | NEW |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 <HTML> | 2 <HTML> |
| 3 | 3 |
| 4 <HEAD> | 4 <HEAD> |
| 5 <link rel="stylesheet" href="designstyle.css"> | 5 <link rel="stylesheet" href="designstyle.css"> |
| 6 <title>Google CPU Profiler</title> | 6 <title>Gperftools CPU Profiler</title> |
| 7 </HEAD> | 7 </HEAD> |
| 8 | 8 |
| 9 <BODY> | 9 <BODY> |
| 10 | 10 |
| 11 <p align=right> | 11 <p align=right> |
| 12 <i>Last modified | 12 <i>Last modified |
| 13 <script type=text/javascript> | 13 <script type=text/javascript> |
| 14 var lm = new Date(document.lastModified); | 14 var lm = new Date(document.lastModified); |
| 15 document.write(lm.toDateString()); | 15 document.write(lm.toDateString()); |
| 16 </script></i> | 16 </script></i> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 43 system.)</p> | 43 system.)</p> |
| 44 | 44 |
| 45 | 45 |
| 46 <H1>Running the Code</H1> | 46 <H1>Running the Code</H1> |
| 47 | 47 |
| 48 <p>There are several alternatives to actually turn on CPU profiling | 48 <p>There are several alternatives to actually turn on CPU profiling |
| 49 for a given run of an executable:</p> | 49 for a given run of an executable:</p> |
| 50 | 50 |
| 51 <ol> | 51 <ol> |
| 52 <li> <p>Define the environment variable CPUPROFILE to the filename | 52 <li> <p>Define the environment variable CPUPROFILE to the filename |
| 53 to dump the profile to. For instance, to profile | 53 to dump the profile to. For instance, if you had a version of |
| 54 <code>/usr/local/bin/my_binary_compiled_with_libprofiler_so</code>:</p> | 54 <code>/bin/ls</code> that had been linked against libprofiler, |
| 55 <pre>% env CPUPROFILE=/tmp/mybin.prof /usr/local/bin/my_binary_compiled_w
ith_libprofiler_so</pre> | 55 you could run:</p> |
| 56 <pre>% env CPUPROFILE=ls.prof /bin/ls</pre> |
| 56 | 57 |
| 57 <li> <p>In your code, bracket the code you want profiled in calls to | 58 <li> <p>In your code, bracket the code you want profiled in calls to |
| 58 <code>ProfilerStart()</code> and <code>ProfilerStop()</code>. | 59 <code>ProfilerStart()</code> and <code>ProfilerStop()</code>. |
| 59 (These functions are declared in <code><google/profiler.h></code>.) | 60 (These functions are declared in <code><gperftools/profiler.h></cod
e>.) |
| 60 <code>ProfilerStart()</code> will take | 61 <code>ProfilerStart()</code> will take |
| 61 the profile-filename as an argument.</p> | 62 the profile-filename as an argument.</p> |
| 62 </ol> | 63 </ol> |
| 63 | 64 |
| 64 <p>In Linux 2.6 and above, profiling works correctly with threads, | 65 <p>In Linux 2.6 and above, profiling works correctly with threads, |
| 65 automatically profiling all threads. In Linux 2.4, profiling only | 66 automatically profiling all threads. In Linux 2.4, profiling only |
| 66 profiles the main thread (due to a kernel bug involving itimers and | 67 profiles the main thread (due to a kernel bug involving itimers and |
| 67 threads). Profiling works correctly with sub-processes: each child | 68 threads). Profiling works correctly with sub-processes: each child |
| 68 process gets its own profile with its own name (generated by combining | 69 process gets its own profile with its own name (generated by combining |
| 69 CPUPROFILE with the child's process id).</p> | 70 CPUPROFILE with the child's process id).</p> |
| 70 | 71 |
| 71 <p>For security reasons, CPU profiling will not write to a file -- and | 72 <p>For security reasons, CPU profiling will not write to a file -- and |
| 72 is thus not usable -- for setuid programs.</p> | 73 is thus not usable -- for setuid programs.</p> |
| 73 | 74 |
| 74 <p>See the include-file <code>google/profiler.h</code> for | 75 <p>See the include-file <code>gperftools/profiler.h</code> for |
| 75 advanced-use functions, including <code>ProfilerFlush()</code> and | 76 advanced-use functions, including <code>ProfilerFlush()</code> and |
| 76 <code>ProfilerStartWithOptions()</code>.</p> | 77 <code>ProfilerStartWithOptions()</code>.</p> |
| 77 | 78 |
| 78 | 79 |
| 79 <H2>Modifying Runtime Behavior</H2> | 80 <H2>Modifying Runtime Behavior</H2> |
| 80 | 81 |
| 81 <p>You can more finely control the behavior of the CPU profiler via | 82 <p>You can more finely control the behavior of the CPU profiler via |
| 82 environment variables.</p> | 83 environment variables.</p> |
| 83 | 84 |
| 84 <table frame=box rules=sides cellpadding=5 width=100%> | 85 <table frame=box rules=sides cellpadding=5 width=100%> |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 512 |
| 512 <hr> | 513 <hr> |
| 513 <address>Sanjay Ghemawat<br> | 514 <address>Sanjay Ghemawat<br> |
| 514 <!-- Created: Tue Dec 19 10:43:14 PST 2000 --> | 515 <!-- Created: Tue Dec 19 10:43:14 PST 2000 --> |
| 515 <!-- hhmts start --> | 516 <!-- hhmts start --> |
| 516 Last modified: Fri May 9 14:41:29 PDT 2008 | 517 Last modified: Fri May 9 14:41:29 PDT 2008 |
| 517 <!-- hhmts end --> | 518 <!-- hhmts end --> |
| 518 </address> | 519 </address> |
| 519 </BODY> | 520 </BODY> |
| 520 </HTML> | 521 </HTML> |
| OLD | NEW |