# 27.1.概述

DTrace，也称为动态跟踪，是由 Sun™ 开发的工具，用于定位生产环境和预生产系统中的性能瓶颈。除了诊断性能问题外，DTrace 还可以用来帮助调查和调试 FreeBSD 内核和用户空间程序中的意外行为。

DTrace 是一款出色的性能分析工具，具有强大的功能，能够诊断系统问题。它还可以运行预编写的脚本，以利用其能力。用户可以使用 DTrace D 语言编写自己的实用程序，从而根据特定需求定制其性能分析。

FreeBSD 实现提供了对内核 DTrace 的完整支持，以及对用户空间 DTrace 的实验性支持。用户空间 DTrace 允许用户使用 `pid` 提供者进行用户空间程序的函数边界跟踪，并在用户空间程序中插入静态探针以供后续跟踪。某些 Port，如 [databases/postgresql12-server](https://cgit.freebsd.org/ports/tree/databases/postgresql12-server/) 和 [lang/php74](https://cgit.freebsd.org/ports/tree/lang/php74/)，提供了 DTrace 选项以启用静态探针。

DTrace 的官方指南由 Illumos 项目维护，网址为 [illumos DTrace Guide](https://illumos.org/books/dtrace/bookinfo.html)。

阅读完本章后，你将了解：

* DTrace 是什么，它提供了哪些功能。
* Solaris™ DTrace 实现与 FreeBSD 提供的实现之间的差异。
* 如何在 FreeBSD 上启用和使用 DTrace。

在阅读本章之前，你应该：

* 了解 UNIX® 和 FreeBSD 基础知识（[FreeBSD Basics](https://docs.freebsd.org/en/books/handbook/basics/#basics)）。
* 对安全性有所了解，以及它如何与 FreeBSD 相关（[Security](https://docs.freebsd.org/en/books/handbook/security/#security)）。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://handbook.bsdcn.org/di-27-zhang-dtrace/27.1.-gai-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
