Skip to content

Commit 122403b

Browse files
authored
USDT tracing improvements (#12179)
- Add tracing documentation. - Fix uninitizlied sm_id in milestone_sm_start.
1 parent 561771b commit 122403b

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

doc/developer-guide/debugging/index.en.rst

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ Debugging and Analysis
3131
core-dump-analysis.en
3232
profiling.en
3333
memory-leaks.en
34+
tracing.en
3435

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
.. Licensed to the Apache Software Foundation (ASF) under one
2+
or more contributor license agreements. See the NOTICE file
3+
distributed with this work for additional information
4+
regarding copyright ownership. The ASF licenses this file
5+
to you under the Apache License, Version 2.0 (the
6+
"License"); you may not use this file except in compliance
7+
with the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
18+
.. include:: ../../common.defs
19+
.. default-domain:: cpp
20+
21+
.. _developer-tracing:
22+
23+
Tracing
24+
*********
25+
26+
ATS includes statically defined tracepoints. These are useful for debugging a running instance with minimal overhead.
27+
28+
USDT
29+
====
30+
31+
A number of tools can be used to read USDT tracepoints. Tools such as bpftrace, bcc, and perf use eBPF technology within the Linux kernel to provide tracing capabilities.
32+
33+
These tools can list available tracepoints, attach to a tracepoint, and some can process trace data in real time with eBPF programs.
34+
35+
Built-in tracepoints
36+
====================
37+
38+
ATS includes a tracepoint at each HTTP state machine state. The state machine id, sm_id, is included as an argument to help isolate each transaction. These tracepoints
39+
are named milestone_<state> and are located in the HttpSM.cc file. See :func:`TSHttpTxnMilestoneGet` for a list of the states.
40+
41+
Example with bpftrace
42+
=====================
43+
.. code-block:: bash
44+
45+
#!/usr/bin/env bpftrace
46+
47+
BEGIN {
48+
@ = (uint64)0;
49+
}
50+
51+
usdt:/opt/ats/bin/traffic_server:trafficserver:milestone_sm_start {
52+
$sm_id = arg0;
53+
if (@ == 0) {
54+
@ = $sm_id;
55+
}
56+
@start_time = nsecs;
57+
}
58+
59+
usdt:/opt/ats/bin/traffic_server:trafficserver:milestone_* {
60+
$sm_id = arg0;
61+
if ($sm_id == @) {
62+
printf("%s %d\n", probe, nsecs - @start_time);
63+
}
64+
}
65+
66+
usdt:/opt/ats/bin/traffic_server:trafficserver:milestone_sm_finish {
67+
$sm_id = arg0;
68+
if ($sm_id == @) {
69+
printf("End of state machine %d\n", $sm_id);
70+
exit();
71+
}
72+
}

src/proxy/http/HttpSM.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ HttpSM::destroy()
282282
void
283283
HttpSM::init(bool from_early_data)
284284
{
285-
ATS_PROBE1(milestone_sm_start, sm_id);
286285
milestones[TS_MILESTONE_SM_START] = ink_get_hrtime();
287286

288287
_from_early_data = from_early_data;
@@ -292,7 +291,8 @@ HttpSM::init(bool from_early_data)
292291
server_txn = nullptr;
293292

294293
// Unique state machine identifier
295-
sm_id = next_sm_id++;
294+
sm_id = next_sm_id++;
295+
ATS_PROBE1(milestone_sm_start, sm_id);
296296
t_state.state_machine = this;
297297

298298
t_state.http_config_param = HttpConfig::acquire();

0 commit comments

Comments
 (0)