Skip to content

Commit 3313ff1

Browse files
thughesry
authored andcommitted
cmake: dtrace support.
1 parent 9d49c93 commit 3313ff1

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ option(SHARED_CARES "use system shared c-ares library")
2727
option(V8_SNAPSHOT "turn on snapshot when building stock v8")
2828
option(V8_OPROFILE "Add oprofile support")
2929
option(V8_GDBJIT "add gdbjit support")
30+
option(DTRACE "build with DTrace (experimental)")
3031

3132
# cmake policies to get rid of some warnings
3233
cmake_policy(SET CMP0009 NEW) # GLOB_RECURSE should no follow symlinks

cmake/configure.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ else()
7272
add_definitions(-DHAVE_FDATASYNC=0)
7373
endif()
7474

75+
if(DTRACE)
76+
if(NOT ${node_platform} MATCHES sunos)
77+
message(FATAL_ERROR "DTrace support only currently available on Solaris")
78+
endif()
79+
find_program(dtrace_bin dtrace)
80+
if(NOT dtrace_bin)
81+
message(FATAL_ERROR "DTrace binary not found")
82+
endif()
83+
add_definitions(-DHAVE_DTRACE=1)
84+
endif()
85+
7586
add_definitions(
7687
-DPLATFORM="${node_platform}"
7788
-DX_STACKSIZE=65536

cmake/node_build.cmake

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22
# node build stuff
33
#
44

5+
set(macros_file ${PROJECT_BINARY_DIR}/macros.py)
6+
7+
# replace debug(x) and assert(x) with nothing in release build
8+
if(${CMAKE_BUILD_TYPE} MATCHES Release)
9+
file(APPEND ${macros_file} "macro debug(x) = ;\n")
10+
file(APPEND ${macros_file} "macro assert(x) = ;\n")
11+
endif()
12+
13+
if(NOT DTRACE)
14+
set(dtrace_probes
15+
DTRACE_HTTP_CLIENT_REQUEST
16+
DTRACE_HTTP_CLIENT_RESPONSE
17+
DTRACE_HTTP_SERVER_REQUEST
18+
DTRACE_HTTP_SERVER_RESPONSE
19+
DTRACE_NET_SERVER_CONNECTION
20+
DTRACE_NET_STREAM_END
21+
DTRACE_NET_SOCKET_READ
22+
DTRACE_NET_SOCKET_WRITE)
23+
foreach(probe ${dtrace_probes})
24+
file(APPEND ${macros_file} "macro ${probe}(x) = ;\n")
25+
endforeach()
26+
endif()
27+
28+
# include macros file in generation
29+
set(js2c_files ${js2c_files} ${macros_file})
30+
531
add_custom_command(
632
OUTPUT ${PROJECT_BINARY_DIR}/src/node_natives.h
733
COMMAND ${PYTHON_EXECUTABLE} tools/js2c.py ${PROJECT_BINARY_DIR}/src/node_natives.h ${js2c_files}
@@ -66,6 +92,15 @@ include_directories(
6692
${PROJECT_BINARY_DIR}/src
6793
)
6894

95+
if(DTRACE)
96+
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src/node_provider.h
97+
COMMAND ${dtrace_bin} -x nolibs -h -o ${PROJECT_BINARY_DIR}/src/node_provider.h -s ${PROJECT_SOURCE_DIR}/src/node_provider.d
98+
DEPENDS ${PROJECT_SOURCE_DIR}/src/node_provider.d)
99+
100+
set(node_sources ${node_sources} src/node_provider.o)
101+
set(node_sources src/node_provider.h ${node_sources})
102+
endif()
103+
69104
add_executable(node ${node_sources})
70105
set_target_properties(node PROPERTIES DEBUG_POSTFIX "_g")
71106
target_link_libraries(node
@@ -77,6 +112,20 @@ target_link_libraries(node
77112
${CMAKE_THREAD_LIBS_INIT}
78113
${extra_libs})
79114

115+
if(DTRACE)
116+
# manually gather up the object files for dtrace
117+
get_property(sourcefiles TARGET node PROPERTY SOURCES)
118+
foreach(src_file ${sourcefiles})
119+
if(src_file MATCHES ".*\\.cc$")
120+
set(node_objs ${node_objs} ${PROJECT_BINARY_DIR}/CMakeFiles/node.dir/${src_file}.o)
121+
endif()
122+
endforeach()
123+
124+
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src/node_provider.o
125+
#COMMAND cmake -E echo ${node_objs}
126+
COMMAND ${dtrace_bin} -G -x nolibs -s ${PROJECT_SOURCE_DIR}/src/node_provider.d -o ${PROJECT_BINARY_DIR}/src/node_provider.o ${node_objs}
127+
DEPENDS ${node_objs})
128+
endif()
80129

81130
install(TARGETS node RUNTIME DESTINATION bin)
82131
install(FILES

0 commit comments

Comments
 (0)