Skip to content

Commit ed255ab

Browse files
cdai2rvagg
authored andcommitted
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" PR-URL: #3785 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 1f0e8dc commit ed255ab

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

‎configure‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ parser.add_option("--fully-static",
8686
help="Generate an executable without external dynamic libraries. This "
8787
"will not work on OSX when using default compilation environment")
8888

89+
parser.add_option("--enable-vtune-profiling",
90+
action="store_true",
91+
dest="enable_vtune_profiling",
92+
help="Enable profiling support for Intel Vtune profiler to profile"
93+
"JavaScript code executed in nodejs. This feature is only available "
94+
"for ia32, x32 or x64 platform.")
95+
96+
8997
parser.add_option("--link-module",
9098
action="append",
9199
dest="linked_module",
@@ -679,6 +687,15 @@ def configure_node(o):
679687
o['variables']['node_core_target_name'] ='node_base'
680688
o['variables']['node_target_type'] ='static_library'
681689

690+
iftarget_archin ('x86', 'x64', 'ia32', 'x32'):
691+
o['variables']['node_enable_v8_vtunejit'] =b(options.enable_vtune_profiling)
692+
elifoptions.enable_vtune_profiling:
693+
raiseException(
694+
'vtune profiler for JavaScript is only supported on x86, x32 or x64 '
695+
'platform.')
696+
else:
697+
o['variables']['node_enable_v8_vtunejit'] ='false'
698+
682699
ifflavorin ('solaris', 'mac', 'linux', 'freebsd'):
683700
use_dtrace=notoptions.without_dtrace
684701
# Don't enable by default on linux and freebsd

‎node.gyp‎

Lines changed: 8 additions & 0 deletions
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': [
@@ -221,6 +222,13 @@
221222
'defines': [ 'NODE_HAVE_SMALL_ICU=1' ],
222223
}]],
223224
}],
225+
[ 'node_enable_v8_vtunejit=="true" and (target_arch=="x64" or \
226+
target_arch=="ia32" or target_arch=="x32")',{
227+
'defines': [ 'NODE_ENABLE_VTUNE_PROFILING' ],
228+
'dependencies': [
229+
'deps/v8/src/third_party/vtune/v8vtune.gyp:v8_vtune'
230+
],
231+
}],
224232
[ 'node_use_openssl=="true"',{
225233
'defines': [ 'HAVE_OPENSSL=1' ],
226234
'sources': [

‎src/node.cc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#include"v8-profiler.h"
4444
#include"zlib.h"
4545

46+
#ifdef NODE_ENABLE_VTUNE_PROFILING
47+
#include"../deps/v8/src/third_party/vtune/v8-vtune.h"
48+
#endif
49+
4650
#include<errno.h>
4751
#include<limits.h>// PATH_MAX
4852
#include<locale.h>
@@ -4025,6 +4029,9 @@ static void StartNodeInstance(void* arg){
40254029
Isolate::CreateParams params;
40264030
ArrayBufferAllocator* array_buffer_allocator = newArrayBufferAllocator();
40274031
params.array_buffer_allocator = array_buffer_allocator;
4032+
#ifdef NODE_ENABLE_VTUNE_PROFILING
4033+
params.code_event_handler = vTune::GetVtuneCodeEventHandler();
4034+
#endif
40284035
Isolate* isolate = Isolate::New(params);
40294036
if (track_heap_objects){
40304037
isolate->GetHeapProfiler()->StartTrackingHeapObjects(true);

‎vcbuild.bat‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set i18n_arg=
3737
setdownload_arg=
3838
setrelease_urls_arg=
3939
setbuild_release=
40+
setenable_vtune_profiling=
4041

4142
:next-arg
4243
if"%1"==""goto args-done
@@ -71,6 +72,7 @@ if /i "%1"=="full-icu" set i18n_arg=%1&goto arg-ok
7172
if /i "%1"=="intl-none"seti18n_arg=%1&goto arg-ok
7273
if /i "%1"=="download-all"setdownload_arg="--download=all"&goto arg-ok
7374
if /i "%1"=="ignore-flaky"settest_args=%test_args% --flaky-tests=dontcare&goto arg-ok
75+
if /i "%1"=="enable-vtune"setenable_vtune_profiling="--enable-vtune-profiling"&goto arg-ok
7476

7577
echo Warning: ignoring invalid command line option `%1`.
7678

@@ -168,7 +170,7 @@ goto run
168170
ifdefined noprojgen goto msbuild
169171

170172
@rem Generate the VS project.
171-
python configure %download_arg%%i18n_arg%%debug_arg%%snapshot_arg%%noetw_arg%%noperfctr_arg% --dest-cpu=%target_arch% --tag=%TAG%
173+
python configure %download_arg%%i18n_arg%%debug_arg%%snapshot_arg%%noetw_arg%%noperfctr_arg%%enable_vtune_profiling%--dest-cpu=%target_arch% --tag=%TAG%
172174
iferrorlevel1goto create-msvs-files-failed
173175
ifnotexist node.sln goto create-msvs-files-failed
174176
echo Project files generated.
@@ -259,13 +261,14 @@ echo Failed to create vc project files.
259261
gotoexit
260262

261263
:help
262-
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] [download-all]
264+
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] [download-all] [enable-vtune]
263265
echo Examples:
264266
echo vcbuild.bat : builds release build
265267
echo vcbuild.bat debug : builds debug build
266268
echo vcbuild.bat release msi : builds release build and MSI installer package
267269
echo vcbuild.bat test : builds debug build and runs tests
268270
echo vcbuild.bat build-release : builds the release distribution as used by nodejs.org
271+
echo vcbuild.bat enable-vtune : builds nodejs with Intel Vtune profiling support to profile JavaScript
269272
gotoexit
270273

271274
:exit

0 commit comments

Comments
(0)