OLD | NEW |
(Empty) | |
| 1 # Introduction |
| 2 |
| 3 V8 has built-in sample based profiling. Profiling is turned off by default, but
can be enabled via the --prof command line option. The sampler records stacks of
both JavaScript and C/C++ code. |
| 4 |
| 5 # Build |
| 6 Build the d8 shell following the instructions at [BuildingWithGYP](BuildingWithG
YP.md). |
| 7 |
| 8 |
| 9 # Command Line |
| 10 To start profiling, use the `--prof` option. When profiling, V8 generates a `v8
.log` file which contains profiling data. |
| 11 |
| 12 Windows: |
| 13 ``` |
| 14 build\Release\d8 --prof script.js |
| 15 ``` |
| 16 |
| 17 Other platforms (replace "ia32" with "x64" if you want to profile the x64 build)
: |
| 18 ``` |
| 19 out/ia32.release/d8 --prof script.js |
| 20 ``` |
| 21 |
| 22 # Process the Generated Output |
| 23 |
| 24 Log file processing is done using JS scripts running by the d8 shell. For this t
o work, a `d8` binary (or symlink, or `d8.exe` on Windows) must be in the root o
f your V8 checkout, or in the path specified by the environment variable `D8_PAT
H`. Note: this binary is just used to process the log, but not for the actual pr
ofiling, so it doesn't matter which version etc. it is. |
| 25 |
| 26 Windows: |
| 27 ``` |
| 28 tools\windows-tick-processor.bat v8.log |
| 29 ``` |
| 30 |
| 31 Linux: |
| 32 ``` |
| 33 tools/linux-tick-processor v8.log |
| 34 ``` |
| 35 |
| 36 Mac OS X: |
| 37 ``` |
| 38 tools/mac-tick-processor v8.log |
| 39 ``` |
| 40 |
| 41 ## Snapshot-based VM build and builtins reporting |
| 42 |
| 43 When a snapshot-based VM build is being used, code objects from a snapshot that
don't correspond to functions are reported with generic names like _"A builtin f
rom the snapshot"_, because their real names are not stored in the snapshot. To
see the names the following steps must be taken: |
| 44 |
| 45 * `--log-snapshot-positions` flag must be passed to VM (along with `--prof`);
this way, for deserialized objects the `(memory address, snapshot offset)` pairs
are being emitted into profiler log; |
| 46 |
| 47 * `--snapshot-log=<log file from mksnapshot>` flag must be passed to the tick
processor script; a log file from the `mksnapshot` program (a snapshot log) cont
ains address-offset pairs for serialized objects, and their names; using the sna
pshot log, names can be mapped onto deserialized objects during profiler log pro
cessing; the snapshot log file is called `snapshot.log` and resides alongside wi
th V8's compiled files. |
| 48 |
| 49 An example of usage: |
| 50 ``` |
| 51 out/ia32.release/d8 --prof --log-snapshot-positions script.js |
| 52 tools/linux-tick-processor --snapshot-log=out/ia32.release/obj.target/v8_snapsho
t/geni/snapshot.log v8.log |
| 53 ``` |
| 54 |
| 55 # Programmatic Control of Profiling |
| 56 If you would like to control in your application when profile samples are collec
ted, you can do so. |
| 57 |
| 58 First you'll probably want to use the `--noprof-auto` command line switch which
prevents the profiler from automatically starting to record profile ticks. |
| 59 |
| 60 Profile ticks will not be recorded until your application specifically invokes t
hese APIs: |
| 61 * `V8::ResumeProfiler()` - start/resume collection of data |
| 62 * `V8::PauseProfiler()` - pause collection of data |
| 63 |
| 64 # Example Output |
| 65 |
| 66 ``` |
| 67 Statistical profiling result from benchmarks\v8.log, (4192 ticks, 0 unaccounted,
0 excluded). |
| 68 |
| 69 [Shared libraries]: |
| 70 ticks total nonlib name |
| 71 9 0.2% 0.0% C:\WINDOWS\system32\ntdll.dll |
| 72 2 0.0% 0.0% C:\WINDOWS\system32\kernel32.dll |
| 73 |
| 74 [JavaScript]: |
| 75 ticks total nonlib name |
| 76 741 17.7% 17.7% LazyCompile: am3 crypto.js:108 |
| 77 113 2.7% 2.7% LazyCompile: Scheduler.schedule richards.js:188 |
| 78 103 2.5% 2.5% LazyCompile: rewrite_nboyer earley-boyer.js:3604 |
| 79 103 2.5% 2.5% LazyCompile: TaskControlBlock.run richards.js:324 |
| 80 96 2.3% 2.3% Builtin: JSConstructCall |
| 81 ... |
| 82 |
| 83 [C++]: |
| 84 ticks total nonlib name |
| 85 94 2.2% 2.2% v8::internal::ScavengeVisitor::VisitPointers |
| 86 33 0.8% 0.8% v8::internal::SweepSpace |
| 87 32 0.8% 0.8% v8::internal::Heap::MigrateObject |
| 88 30 0.7% 0.7% v8::internal::Heap::AllocateArgumentsObject |
| 89 ... |
| 90 |
| 91 |
| 92 [GC]: |
| 93 ticks total nonlib name |
| 94 458 10.9% |
| 95 |
| 96 [Bottom up (heavy) profile]: |
| 97 Note: percentage shows a share of a particular caller in the total |
| 98 amount of its parent calls. |
| 99 Callers occupying less than 2.0% are not shown. |
| 100 |
| 101 ticks parent name |
| 102 741 17.7% LazyCompile: am3 crypto.js:108 |
| 103 449 60.6% LazyCompile: montReduce crypto.js:583 |
| 104 393 87.5% LazyCompile: montSqrTo crypto.js:603 |
| 105 212 53.9% LazyCompile: bnpExp crypto.js:621 |
| 106 212 100.0% LazyCompile: bnModPowInt crypto.js:634 |
| 107 212 100.0% LazyCompile: RSADoPublic crypto.js:1521 |
| 108 181 46.1% LazyCompile: bnModPow crypto.js:1098 |
| 109 181 100.0% LazyCompile: RSADoPrivate crypto.js:1628 |
| 110 ... |
| 111 ``` |
| 112 |
| 113 # Timeline plot |
| 114 The timeline plot visualizes where V8 is spending time. This can be used to find
bottlenecks and spot things that are unexpected (for example, too much time spe
nt in the garbage collector). Data for the plot are gathered by both sampling an
d instrumentation. Linux with gnuplot 4.6 is required. |
| 115 |
| 116 To create a timeline plot, run V8 as described above, with the option `--log-tim
er-events` additional to `--prof`: |
| 117 ``` |
| 118 out/ia32.release/d8 --prof --log-timer-events script.js |
| 119 ``` |
| 120 |
| 121 The output is then passed to a plot script, similar to the tick-processor: |
| 122 ``` |
| 123 tools/plot-timer-events v8.log |
| 124 ``` |
| 125 |
| 126 This creates `timer-events.png` in the working directory, which can be opened wi
th most image viewers. |
| 127 |
| 128 # Options |
| 129 Since recording log output comes with a certain performance overhead, the script
attempts to correct this using a distortion factor. If not specified, it tries
to find out automatically. You can however also specify the distortion factor ma
nually. |
| 130 ``` |
| 131 tools/plot-timer-events --distortion=4500 v8.log |
| 132 ``` |
| 133 |
| 134 You can also manually specify a certain range for which to create the plot or st
atistical profile, expressed in milliseconds: |
| 135 ``` |
| 136 tools/plot-timer-events --distortion=4500 --range=1000,2000 v8.log |
| 137 tools/linux-tick-processor --distortion=4500 --range=1000,2000 v8.log |
| 138 ``` |
| 139 |
| 140 # HTML 5 version |
| 141 Both statistical profile and timeline plot are available [in the browser](http:/
/v8.googlecode.com/svn/branches/bleeding_edge/tools/profviz/profviz.html). Howev
er, the statistical profile lacks C++ symbol resolution and the Javascript port
of gnuplot performs an order of magnitude slower than the native one. |
OLD | NEW |