11cb0ef41Sopenharmony_ciTurbolizer 21cb0ef41Sopenharmony_ci========== 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciTurbolizer is a HTML-based tool that visualizes optimized code along the various 51cb0ef41Sopenharmony_ciphases of Turbofan's optimization pipeline, allowing easy navigation between 61cb0ef41Sopenharmony_cisource code, Turbofan IR graphs, scheduled IR nodes and generated assembly code. 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciTurbolizer consumes .json files that are generated per-function by d8 by passing 91cb0ef41Sopenharmony_cithe '--trace-turbo' command-line flag. 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciTurbolizer is build using npm: 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci cd tools/turbolizer 141cb0ef41Sopenharmony_ci npm i 151cb0ef41Sopenharmony_ci npm run-script build 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciAfterwards, turbolizer can be hosted locally by starting a web server that serve 181cb0ef41Sopenharmony_cithe contents of the turbolizer directory, e.g.: 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci python -m SimpleHTTPServer 8000 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciTo deploy to a directory that can be hosted the script `deploy` can be used. The 231cb0ef41Sopenharmony_cifollowing command will deploy to the directory /www/turbolizer: 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci npm run deploy -- /www/turbolizer 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciOptionally, profiling data generated by the perf tools in linux can be merged 281cb0ef41Sopenharmony_ciwith the .json files using the turbolizer-perf.py file included. The following 291cb0ef41Sopenharmony_cicommand is an example of using the perf script: 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci perf script -i perf.data.jitted -s turbolizer-perf.py turbo-main.json 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciThe output of the above command is a json object that can be piped to a file 341cb0ef41Sopenharmony_ciwhich, when uploaded to turbolizer, will display the event counts from perf next 351cb0ef41Sopenharmony_cito each instruction in the disassembly. Further detail can be found in the 361cb0ef41Sopenharmony_cibottom of this document under "Using Perf with Turbo." 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ciUsing the python interface in perf script requires python-dev to be installed 391cb0ef41Sopenharmony_ciand perf be recompiled with python support enabled. Once recompiled, the 401cb0ef41Sopenharmony_civariable PERF_EXEC_PATH must be set to the location of the recompiled perf 411cb0ef41Sopenharmony_cibinaries. 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ciGraph visualization and manipulation based on Mike Bostock's sample code for an 441cb0ef41Sopenharmony_ciinteractive tool for creating directed graphs. Original source is at 451cb0ef41Sopenharmony_cihttps://github.com/metacademy/directed-graph-creator and released under the 461cb0ef41Sopenharmony_ciMIT/X license. 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciIcons derived from the "White Olive Collection" created by Breezi released under 491cb0ef41Sopenharmony_cithe Creative Commons BY license. 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ciUsing Perf with Turbo 521cb0ef41Sopenharmony_ci--------------------- 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ciIn order to generate perf data that matches exactly with the turbofan trace, you 551cb0ef41Sopenharmony_cimust use either a debug build of v8 or a release build with the flag 561cb0ef41Sopenharmony_ci'disassembler=on'. This flag ensures that the '--trace-turbo' will output the 571cb0ef41Sopenharmony_cinecessary disassembly for linking with the perf profile. 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ciThe basic example of generating the required data is as follows: 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci perf record -k mono /path/to/d8 --trace-turbo --perf-prof main.js 621cb0ef41Sopenharmony_ci perf inject -j -i perf.data -o perf.data.jitted 631cb0ef41Sopenharmony_ci perf script -i perf.data.jitted -s turbolizer-perf.py turbo-main.json 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ciThese commands combined will run and profile d8, merge the output into a single 661cb0ef41Sopenharmony_ci'perf.data.jitted' file, then take the event data from that and link them to the 671cb0ef41Sopenharmony_cidisassembly in the 'turbo-main.json'. Note that, as above, the output of the 681cb0ef41Sopenharmony_ciscript command must be piped to a file for uploading to turbolizer. 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ciThere are many options that can be added to the first command, for example '-e' 711cb0ef41Sopenharmony_cican be used to specify the counting of specific events (default: cycles), as 721cb0ef41Sopenharmony_ciwell as '--cpu' to specify which CPU to sample. 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ciTurbolizer build process 751cb0ef41Sopenharmony_ci------------------------ 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ciThe typescript sources reside in tools/turbolizer/src, and the typescript 781cb0ef41Sopenharmony_cicompiler will put the JavaScript output into tools/turbolizer/build/. The 791cb0ef41Sopenharmony_ciindex.html file is set up to load the JavaScript from that directory. 80