| 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>Gperftools CPU Profiler</title> | 6 <title>Google 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, if you had a version of | 53 to dump the profile to. For instance, to profile |
| 54 <code>/bin/ls</code> that had been linked against libprofiler, | 54 <code>/usr/local/bin/my_binary_compiled_with_libprofiler_so</code>:</p> |
| 55 you could run:</p> | 55 <pre>% env CPUPROFILE=/tmp/mybin.prof /usr/local/bin/my_binary_compiled_w
ith_libprofiler_so</pre> |
| 56 <pre>% env CPUPROFILE=ls.prof /bin/ls</pre> | |
| 57 | 56 |
| 58 <li> <p>In your code, bracket the code you want profiled in calls to | 57 <li> <p>In your code, bracket the code you want profiled in calls to |
| 59 <code>ProfilerStart()</code> and <code>ProfilerStop()</code>. | 58 <code>ProfilerStart()</code> and <code>ProfilerStop()</code>. |
| 60 (These functions are declared in <code><gperftools/profiler.h></cod
e>.) | 59 (These functions are declared in <code><google/profiler.h></code>.) |
| 61 <code>ProfilerStart()</code> will take | 60 <code>ProfilerStart()</code> will take |
| 62 the profile-filename as an argument.</p> | 61 the profile-filename as an argument.</p> |
| 63 </ol> | 62 </ol> |
| 64 | 63 |
| 65 <p>In Linux 2.6 and above, profiling works correctly with threads, | 64 <p>In Linux 2.6 and above, profiling works correctly with threads, |
| 66 automatically profiling all threads. In Linux 2.4, profiling only | 65 automatically profiling all threads. In Linux 2.4, profiling only |
| 67 profiles the main thread (due to a kernel bug involving itimers and | 66 profiles the main thread (due to a kernel bug involving itimers and |
| 68 threads). Profiling works correctly with sub-processes: each child | 67 threads). Profiling works correctly with sub-processes: each child |
| 69 process gets its own profile with its own name (generated by combining | 68 process gets its own profile with its own name (generated by combining |
| 70 CPUPROFILE with the child's process id).</p> | 69 CPUPROFILE with the child's process id).</p> |
| 71 | 70 |
| 72 <p>For security reasons, CPU profiling will not write to a file -- and | 71 <p>For security reasons, CPU profiling will not write to a file -- and |
| 73 is thus not usable -- for setuid programs.</p> | 72 is thus not usable -- for setuid programs.</p> |
| 74 | 73 |
| 75 <p>See the include-file <code>gperftools/profiler.h</code> for | 74 <p>See the include-file <code>google/profiler.h</code> for |
| 76 advanced-use functions, including <code>ProfilerFlush()</code> and | 75 advanced-use functions, including <code>ProfilerFlush()</code> and |
| 77 <code>ProfilerStartWithOptions()</code>.</p> | 76 <code>ProfilerStartWithOptions()</code>.</p> |
| 78 | 77 |
| 79 | 78 |
| 80 <H2>Modifying Runtime Behavior</H2> | 79 <H2>Modifying Runtime Behavior</H2> |
| 81 | 80 |
| 82 <p>You can more finely control the behavior of the CPU profiler via | 81 <p>You can more finely control the behavior of the CPU profiler via |
| 83 environment variables.</p> | 82 environment variables.</p> |
| 84 | 83 |
| 85 <table frame=box rules=sides cellpadding=5 width=100%> | 84 <table frame=box rules=sides cellpadding=5 width=100%> |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 511 |
| 513 <hr> | 512 <hr> |
| 514 <address>Sanjay Ghemawat<br> | 513 <address>Sanjay Ghemawat<br> |
| 515 <!-- Created: Tue Dec 19 10:43:14 PST 2000 --> | 514 <!-- Created: Tue Dec 19 10:43:14 PST 2000 --> |
| 516 <!-- hhmts start --> | 515 <!-- hhmts start --> |
| 517 Last modified: Fri May 9 14:41:29 PDT 2008 | 516 Last modified: Fri May 9 14:41:29 PDT 2008 |
| 518 <!-- hhmts end --> | 517 <!-- hhmts end --> |
| 519 </address> | 518 </address> |
| 520 </BODY> | 519 </BODY> |
| 521 </HTML> | 520 </HTML> |
| OLD | NEW |