Skip to content

Commit 81f8763

Browse files
committed
WL#7894 - Improve dtrace support on Oracle Linux 6
Dtrace support is enabled and built if the build system(cmake) detects the "dtrace" command on the Solaris, Mac OS X and FreeBSD. As part of this WL, dtrace support is extented to the Oracle Linux 6 with UEK3 kernel. Now Dtrace support is enabled and built if Oracle Linux 6 with UEK3 has real dtrace.
1 parent ca7cd0f commit 81f8763

14 files changed

+680
-174
lines changed

cmake/dtrace.cmake

+11-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ MACRO(CHECK_DTRACE)
4040
SET(ENABLE_DTRACE ON CACHE BOOL "Enable dtrace")
4141
ENDIF()
4242
SET(HAVE_DTRACE ${ENABLE_DTRACE})
43-
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
43+
EXECUTE_PROCESS(
44+
COMMAND ${DTRACE} -V
45+
OUTPUT_VARIABLE out)
46+
IF(out MATCHES "Sun D" AND
47+
NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD" AND
48+
NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
49+
SET(HAVE_REAL_DTRACE_INSTRUMENTING ON CACHE BOOL "Real DTrace detected")
50+
ENDIF()
51+
IF(HAVE_REAL_DTRACE_INSTRUMENTING)
4452
IF(SIZEOF_VOIDP EQUAL 4)
4553
SET(DTRACE_FLAGS -32 CACHE INTERNAL "DTrace architecture flags")
4654
ELSE()
@@ -93,7 +101,7 @@ FUNCTION(DTRACE_INSTRUMENT target)
93101
ADD_DEPENDENCIES(${target} gen_dtrace_header)
94102

95103
# Invoke dtrace to generate object file and link it together with target.
96-
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
104+
IF(HAVE_REAL_DTRACE_INSTRUMENTING)
97105
SET(objdir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir)
98106
SET(outfile ${objdir}/${target}_dtrace.o)
99107
GET_TARGET_PROPERTY(target_type ${target} TYPE)
@@ -155,7 +163,7 @@ ENDFUNCTION()
155163
# run them again through dtrace -G to generate an ELF file that links
156164
# to mysqld.
157165
MACRO (DTRACE_INSTRUMENT_STATIC_LIBS target libs)
158-
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND ENABLE_DTRACE)
166+
IF(HAVE_REAL_DTRACE_INSTRUMENTING AND ENABLE_DTRACE)
159167
# Filter out non-static libraries in the list, if any
160168
SET(static_libs)
161169
FOREACH(lib ${libs})

mysql-test/r/dynamic_tracing.result

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
CREATE PROCEDURE create_table_and_insert_rows()
2+
BEGIN
3+
DECLARE count INT;
4+
SET count = 1;
5+
SELECT SLEEP(4);
6+
CREATE TABLE t1 (f1 INT);
7+
INSERT INTO t1 VALUES (7894);
8+
WHILE count <= 5 DO
9+
INSERT INTO t1 SELECT * FROM t1;
10+
SET count = count + 1;
11+
END WHILE;
12+
SET count = 1;
13+
WHILE count <= 10000 DO
14+
SELECT SQL_NO_CACHE count(*) from t1;
15+
SET count = count + 1;
16+
END WHILE;
17+
END
18+
$
19+
CALL create_table_and_insert_rows();
20+
SELECT SLEEP(4);
21+
22+
Dynamic tracing ...... started.
23+
24+
query-parse-start : 1
25+
query-parse-done : 1
26+
select-start : 1
27+
select-done : 1
28+
net-read-start : 1
29+
net-read-done : 1
30+
handler_rdlock_start : 1
31+
handler_rdlock_done : 1
32+
33+
Expected probe hits : 8
34+
Actual probe hits : 8
35+
36+
Dynamic tracing ...... completed.
37+
38+
DROP TABLE t1;
39+
DROP PROCEDURE create_table_and_insert_rows;

mysql-test/std_data/dtrace.d

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/sbin/dtrace -s
2+
3+
/*
4+
This Dtrace script is used by the test "dynamic_tracing.test" for
5+
dynamic tracing. This script is executed in background by
6+
"dynamic_tracing.test" and SQL queries are executed concurrently. When
7+
any probe used in this script are hit then counter is incremented. After
8+
hitting all the 8(exp_probe_hits) probes, summary containing probes enabled
9+
and their hit state is printed.
10+
*/
11+
12+
#pragma D option quiet
13+
14+
short query_parse_start;
15+
short query_parse_done;
16+
short select_start;
17+
short select_done;
18+
short net_read_start;
19+
short net_read_done;
20+
short handler_rdlock_start;
21+
short handler_rdlock_done;
22+
23+
short tot_probe_hits;
24+
short exp_probe_hits;
25+
26+
BEGIN
27+
{
28+
query_parse_start= 0;
29+
query_parse_done= 0;
30+
select_start= 0;
31+
select_done= 0;
32+
net_read_start= 0;
33+
net_read_done= 0;
34+
handler_rdlock_start= 0;
35+
handler_rdlock_done= 0;
36+
37+
tot_probe_hits= 0;
38+
exp_probe_hits= 8;
39+
printf("\n Dynamic tracing ...... started.\n");
40+
}
41+
42+
mysql*:::query-parse-start
43+
/query_parse_start == 0/
44+
{
45+
query_parse_start++;
46+
tot_probe_hits++;
47+
}
48+
49+
mysql*:::query-parse-done
50+
/query_parse_done == 0/
51+
{
52+
query_parse_done++;
53+
tot_probe_hits++;
54+
}
55+
56+
mysql*:::select-start
57+
/select_start == 0/
58+
{
59+
select_start++;
60+
tot_probe_hits++;
61+
}
62+
63+
mysql*:::select-done
64+
/select_done == 0/
65+
{
66+
select_done++;
67+
tot_probe_hits++;
68+
}
69+
70+
mysql*:::net-read-start
71+
/net_read_start == 0/
72+
{
73+
net_read_start++;
74+
tot_probe_hits++;
75+
}
76+
77+
mysql*:::net-read-done
78+
/net_read_done == 0/
79+
{
80+
net_read_done++;
81+
tot_probe_hits++;
82+
}
83+
84+
mysql*:::handler-rdlock-start
85+
/handler_rdlock_start == 0/
86+
{
87+
handler_rdlock_start++;
88+
tot_probe_hits++;
89+
}
90+
91+
mysql*:::handler-rdlock-done
92+
/handler_rdlock_done == 0/
93+
{
94+
handler_rdlock_done++;
95+
tot_probe_hits++;
96+
}
97+
98+
mysql*:::query-parse-start,
99+
mysql*:::query-parse-done,
100+
mysql*:::select-start,
101+
mysql*:::select-done,
102+
mysql*:::net-read-start,
103+
mysql*:::net-read-done,
104+
mysql*:::handler-rdlock-start,
105+
mysql*:::handler-rdlock-done
106+
/tot_probe_hits >= exp_probe_hits/
107+
{
108+
printf("\n query-parse-start : %d", query_parse_start);
109+
printf("\n query-parse-done : %d", query_parse_done);
110+
printf("\n select-start : %d", select_start);
111+
printf("\n select-done : %d", select_done);
112+
printf("\n net-read-start : %d", net_read_start);
113+
printf("\n net-read-done : %d", net_read_done);
114+
printf("\n handler_rdlock_start : %d", handler_rdlock_start);
115+
printf("\n handler_rdlock_done : %d", handler_rdlock_done);
116+
printf("\n");
117+
printf("\n Expected probe hits : %d", exp_probe_hits);
118+
printf("\n Actual probe hits : %d\n", tot_probe_hits);
119+
printf("\n Dynamic tracing ...... completed.\n");
120+
exit(0);
121+
}

mysql-test/std_data/system_tap.stp

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# This systamtap script is used by the test "dynamic_tracing.test" for dynamic
2+
# tracing. This script is executed in background by "dynamic_tracing.test" and
3+
# SQL queries are executed concurrently. When any probe used in this script are
4+
# hit then counter is incremented. After hitting all the 8(exp_probe_hits)
5+
# probes, summary containing probes enabled and their hit state is printed.
6+
#
7+
# For the dynamic tracing of MySQL code using systemtap on Linux, the dtrace
8+
# probes defined in the code are converted to systemtap marks by the dtrace
9+
# tool. This dtrace tool is not used for dynamic tracing like real dtrace tool
10+
# supplied with Sun OS, Mac, FreeBSD and Oracle Linux.
11+
#
12+
13+
global query_parse_start
14+
global query_parse_done
15+
global select_start
16+
global select_done
17+
global net_read_start
18+
global net_read_done
19+
global handler_rdlock_start
20+
global handler_rdlock_done
21+
22+
global tot_probe_hits
23+
global exp_probe_hits
24+
25+
probe begin
26+
{
27+
query_parse_start= 0
28+
query_parse_done= 0
29+
select_start= 0
30+
select_done= 0
31+
net_read_start= 0
32+
net_read_done= 0
33+
handler_rdlock_start= 0
34+
handler_rdlock_done= 0
35+
36+
tot_probe_hits= 0
37+
exp_probe_hits= 8
38+
printf("\n Dynamic tracing ...... started.\n")
39+
}
40+
41+
probe process(@1).mark("query__parse__start")
42+
{
43+
if (query_parse_start == 0)
44+
{
45+
query_parse_start++
46+
tot_probe_hits++
47+
}
48+
49+
if (tot_probe_hits >= exp_probe_hits)
50+
{
51+
print_summary_and_exit()
52+
}
53+
}
54+
55+
probe process(@1).mark("query__parse__done")
56+
{
57+
if (query_parse_done == 0)
58+
{
59+
query_parse_done++
60+
tot_probe_hits++
61+
}
62+
63+
if (tot_probe_hits >= exp_probe_hits)
64+
{
65+
print_summary_and_exit()
66+
}
67+
}
68+
69+
probe process(@1).mark("select__start")
70+
{
71+
if (select_start == 0)
72+
{
73+
select_start++
74+
tot_probe_hits++
75+
}
76+
77+
if (tot_probe_hits >= exp_probe_hits)
78+
{
79+
print_summary_and_exit()
80+
}
81+
}
82+
83+
probe process(@1).mark("select__done")
84+
{
85+
if (select_done == 0)
86+
{
87+
select_done++
88+
tot_probe_hits++
89+
}
90+
91+
if (tot_probe_hits >= exp_probe_hits)
92+
{
93+
print_summary_and_exit()
94+
}
95+
}
96+
97+
probe process(@1).mark("net__read__start")
98+
{
99+
if (net_read_start == 0)
100+
{
101+
net_read_start++
102+
tot_probe_hits++
103+
}
104+
105+
if (tot_probe_hits >= exp_probe_hits)
106+
{
107+
print_summary_and_exit()
108+
}
109+
}
110+
111+
probe process(@1).mark("net__read__done")
112+
{
113+
if (net_read_done == 0)
114+
{
115+
net_read_done++
116+
tot_probe_hits++
117+
}
118+
119+
if (tot_probe_hits >= exp_probe_hits)
120+
{
121+
print_summary_and_exit()
122+
}
123+
}
124+
125+
probe process(@1).mark("handler__rdlock__start")
126+
{
127+
if (handler_rdlock_start == 0)
128+
{
129+
handler_rdlock_start++
130+
tot_probe_hits++
131+
}
132+
133+
if (tot_probe_hits >= exp_probe_hits)
134+
{
135+
print_summary_and_exit()
136+
}
137+
}
138+
139+
probe process(@1).mark("handler__rdlock__done")
140+
{
141+
if (handler_rdlock_done == 0)
142+
{
143+
handler_rdlock_done++
144+
tot_probe_hits++
145+
}
146+
147+
if (tot_probe_hits >= exp_probe_hits)
148+
{
149+
print_summary_and_exit()
150+
}
151+
}
152+
153+
function print_summary_and_exit()
154+
{
155+
printf("\n query-parse-start : %d", query_parse_start)
156+
printf("\n query-parse-done : %d", query_parse_done)
157+
printf("\n select-start : %d", select_start)
158+
printf("\n select-done : %d", select_done)
159+
printf("\n net-read-start : %d", net_read_start)
160+
printf("\n net-read-done : %d", net_read_done)
161+
printf("\n handler_rdlock_start : %d", handler_rdlock_start)
162+
printf("\n handler_rdlock_done : %d", handler_rdlock_done)
163+
printf("\n")
164+
printf("\n Expected probe hits : %d", exp_probe_hits)
165+
printf("\n Actual probe hits : %d\n", tot_probe_hits)
166+
printf("\n Dynamic tracing ...... completed.\n\n")
167+
exit()
168+
}

0 commit comments

Comments
 (0)