Skip to content

Commit 4ca90de

Browse files
cdai2Myles Borins
authored and
Myles Borins
committed
build,src: add Intel Vtune profiling support
This feature supports the Intel Vtune profiling support for JITted JavaScript on IA32 / X64 / X32 platform. The advantage of this profiling is that the user / developer of NodeJS application can get the detailed profiling information for every line of the JavaScript source code. This information will be very useful for the owner to optimize their applications. This feature is a compile-time option. For windows platform, the user needs to pass the following parameter to vcbuild.bat: "enable-vtune" For other OS, the user needs to pass the following parameter to ./configure command: "--enable-vtune-profiling" Ref: #3785 PR-URL: #5527 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
1 parent bc81ce9 commit 4ca90de

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

configure

+17
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ parser.add_option("--partly-static",
9292
help="Generate an executable with libgcc and libstdc++ libraries. This "
9393
"will not work on OSX when using the default compilation environment")
9494

95+
parser.add_option("--enable-vtune-profiling",
96+
action="store_true",
97+
dest="enable_vtune_profiling",
98+
help="Enable profiling support for Intel Vtune profiler to profile"
99+
"JavaScript code executed in nodejs. This feature is only available "
100+
"for ia32, x32 or x64 platform.")
101+
102+
95103
parser.add_option("--link-module",
96104
action="append",
97105
dest="linked_module",
@@ -686,6 +694,15 @@ def configure_node(o):
686694
o['variables']['node_core_target_name'] = 'node_base'
687695
o['variables']['node_target_type'] = 'static_library'
688696

697+
if target_arch in ('x86', 'x64', 'ia32', 'x32'):
698+
o['variables']['node_enable_v8_vtunejit'] = b(options.enable_vtune_profiling)
699+
elif options.enable_vtune_profiling:
700+
raise Exception(
701+
'vtune profiler for JavaScript is only supported on x86, x32 or x64 '
702+
'platform.')
703+
else:
704+
o['variables']['node_enable_v8_vtunejit'] = 'false'
705+
689706
if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
690707
use_dtrace = not options.without_dtrace
691708
# Don't enable by default on linux and freebsd

node.gyp

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'node_use_openssl%': 'true',
1313
'node_shared_openssl%': 'false',
1414
'node_v8_options%': '',
15+
'node_enable_v8_vtunejit%': 'false',
1516
'node_target_type%': 'executable',
1617
'node_core_target_name%': 'node',
1718
'library_files': [
@@ -235,6 +236,13 @@
235236
'defines': [ 'NODE_HAVE_SMALL_ICU=1' ],
236237
}]],
237238
}],
239+
[ 'node_enable_v8_vtunejit=="true" and (target_arch=="x64" or \
240+
target_arch=="ia32" or target_arch=="x32")', {
241+
'defines': [ 'NODE_ENABLE_VTUNE_PROFILING' ],
242+
'dependencies': [
243+
'deps/v8/src/third_party/vtune/v8vtune.gyp:v8_vtune'
244+
],
245+
}],
238246
[ 'node_use_openssl=="true"', {
239247
'defines': [ 'HAVE_OPENSSL=1' ],
240248
'sources': [

src/node.cc

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
#include "v8-profiler.h"
4545
#include "zlib.h"
4646

47+
#ifdef NODE_ENABLE_VTUNE_PROFILING
48+
#include "../deps/v8/src/third_party/vtune/v8-vtune.h"
49+
#endif
50+
4751
#include <errno.h>
4852
#include <limits.h> // PATH_MAX
4953
#include <locale.h>
@@ -4070,6 +4074,9 @@ static void StartNodeInstance(void* arg) {
40704074
Isolate::CreateParams params;
40714075
ArrayBufferAllocator* array_buffer_allocator = new ArrayBufferAllocator();
40724076
params.array_buffer_allocator = array_buffer_allocator;
4077+
#ifdef NODE_ENABLE_VTUNE_PROFILING
4078+
params.code_event_handler = vTune::GetVtuneCodeEventHandler();
4079+
#endif
40734080
Isolate* isolate = Isolate::New(params);
40744081
if (track_heap_objects) {
40754082
isolate->GetHeapProfiler()->StartTrackingHeapObjects(true);

vcbuild.bat

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ set release_urls_arg=
3636
set build_release=
3737
set configure_flags=
3838
set build_addons=
39+
set enable_vtune_profiling=
3940

4041
:next-arg
4142
if "%1"=="" goto args-done
@@ -73,6 +74,7 @@ if /i "%1"=="full-icu" set i18n_arg=%1&goto arg-ok
7374
if /i "%1"=="intl-none" set i18n_arg=%1&goto arg-ok
7475
if /i "%1"=="download-all" set download_arg="--download=all"&goto arg-ok
7576
if /i "%1"=="ignore-flaky" set test_args=%test_args% --flaky-tests=dontcare&goto arg-ok
77+
if /i "%1"=="enable-vtune" set enable_vtune_profiling="--enable-vtune-profiling"&goto arg-ok
7678

7779
echo Warning: ignoring invalid command line option `%1`.
7880

@@ -179,7 +181,7 @@ if defined noprojgen goto msbuild
179181

180182
@rem Generate the VS project.
181183
echo configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG%
182-
python configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG%
184+
python configure %configure_flags% %enable_vtune_profiling% --dest-cpu=%target_arch% --tag=%TAG%
183185
if errorlevel 1 goto create-msvs-files-failed
184186
if not exist node.sln goto create-msvs-files-failed
185187
echo Project files generated.
@@ -294,14 +296,15 @@ goto exit
294296

295297
:help
296298

297-
echo vcbuild.bat [debug/release] [msi] [test-all/test-uv/test-internet/test-pummel/test-simple/test-message] [clean] [noprojgen] [small-icu/full-icu/intl-none] [nobuild] [nosign] [x86/x64] [vc2013/vc2015] [download-all]
299+
echo vcbuild.bat [debug/release] [msi] [test-all/test-uv/test-internet/test-pummel/test-simple/test-message] [clean] [noprojgen] [small-icu/full-icu/intl-none] [nobuild] [nosign] [x86/x64] [vc2013/vc2015] [download-all] [enable-vtune]
298300

299301
echo Examples:
300302
echo vcbuild.bat : builds release build
301303
echo vcbuild.bat debug : builds debug build
302304
echo vcbuild.bat release msi : builds release build and MSI installer package
303305
echo vcbuild.bat test : builds debug build and runs tests
304306
echo vcbuild.bat build-release : builds the release distribution as used by nodejs.org
307+
echo vcbuild.bat enable-vtune : builds nodejs with Intel Vtune profiling support to profile JavaScript
305308
goto exit
306309

307310
:exit

0 commit comments

Comments
 (0)