|
| 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 | + } |
0 commit comments