blob: 58fbbba022c0bf8c85e0d7ac3a4c9d1204b759dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# Copyright (C) 2009 Sun Microsystems, Inc
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# Check if OS supports DTrace
MACRO(CHECK_DTRACE)
FIND_PROGRAM(DTRACE dtrace)
MARK_AS_ADVANCED(DTRACE)
# On FreeBSD, dtrace does not handle userland tracing yet
IF(DTRACE AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
SET(ENABLE_DTRACE ON CACHE BOOL "Enable dtrace")
ENDIF()
SET(HAVE_DTRACE ${ENABLE_DTRACE})
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
SET(DTRACE_FLAGS -32 CACHE INTERNAL "DTrace architecture flags")
ELSE()
SET(DTRACE_FLAGS -64 CACHE INTERNAL "DTrace architecture flags")
ENDIF()
ENDIF()
ENDMACRO()
CHECK_DTRACE()
# Produce a header file with
# DTrace macros
MACRO (DTRACE_HEADER provider header header_no_dtrace)
IF(ENABLE_DTRACE)
ADD_CUSTOM_COMMAND(
OUTPUT ${header} ${header_no_dtrace}
COMMAND ${DTRACE} -h -s ${provider} -o ${header}
COMMAND perl ${CMAKE_SOURCE_DIR}/scripts/dheadgen.pl -f ${provider} > ${header_no_dtrace}
DEPENDS ${provider}
)
ENDIF()
ENDMACRO()
# Create provider headers
IF(ENABLE_DTRACE)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/include/probes_mysql.d.base
${CMAKE_BINARY_DIR}/include/probes_mysql.d COPYONLY)
DTRACE_HEADER(
${CMAKE_BINARY_DIR}/include/probes_mysql.d
${CMAKE_BINARY_DIR}/include/probes_mysql_dtrace.h
${CMAKE_BINARY_DIR}/include/probes_mysql_nodtrace.h
)
ADD_CUSTOM_TARGET(gen_dtrace_header
DEPENDS
${CMAKE_BINARY_DIR}/include/probes_mysql.d
${CMAKE_BINARY_DIR}/include/probes_mysql_dtrace.h
${CMAKE_BINARY_DIR}/include/probes_mysql_nodtrace.h
)
ENDIF()
MACRO (DTRACE_INSTRUMENT target)
IF(ENABLE_DTRACE)
ADD_DEPENDENCIES(${target} gen_dtrace_header)
# On Solaris, invoke dtrace -G to generate object file and
# link it together with target.
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
SET(objdir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir)
SET(outfile ${objdir}/${target}_dtrace.o)
ADD_CUSTOM_COMMAND(
TARGET ${target} PRE_LINK
COMMAND ${CMAKE_COMMAND}
-DDTRACE=${DTRACE}
-DOUTFILE=${outfile}
-DDFILE=${CMAKE_BINARY_DIR}/include/probes_mysql.d
-DDTRACE_FLAGS=${DTRACE_FLAGS}
-P ${CMAKE_SOURCE_DIR}/cmake/dtrace_prelink.cmake
WORKING_DIRECTORY ${objdir}
)
GET_TARGET_PROPERTY(target_link_flags ${target} LINK_FLAGS)
IF(NOT target_link_flags)
SET(target_link_flags)
ENDIF()
SET_TARGET_PROPERTIES(${target} PROPERTIES LINK_FLAGS
"${target_link_flags} ${outfile}")
ENDIF()
ENDIF()
ENDMACRO()
|