git: 15aa270064 - main - - The traditional Chinese translation of Handbook chapter 24 dtrace PR:270926 <If and which Problem Report is related.> Author: Wang Yan Hao <>

From: Ruey-Cherng Yu <>
Date: Wed, 24 May 2023 12:00:27 UTC
The branch main has been updated by rcyu:


commit 15aa270064689154d727ce5f2a57c3e4fe674c7a
Author:     Wang Yan Hao <>
AuthorDate: 2023-05-24 11:57:44 +0000
Commit:     Ruey-Cherng Yu <>
CommitDate: 2023-05-24 11:57:44 +0000

    - The traditional Chinese translation of Handbook chapter 24 dtrace
     PR:270926              <If and which Problem Report is related.>
     Author:    Wang Yan Hao <>
 .../zh-tw/books/handbook/dtrace/_index.adoc        | 108 +++++++++++++++------
 1 file changed, 76 insertions(+), 32 deletions(-)

diff --git a/documentation/content/zh-tw/books/handbook/dtrace/_index.adoc b/documentation/content/zh-tw/books/handbook/dtrace/_index.adoc
index d9fdbbd683..b6f203f478 100644
--- a/documentation/content/zh-tw/books/handbook/dtrace/_index.adoc
+++ b/documentation/content/zh-tw/books/handbook/dtrace/_index.adoc
@@ -3,9 +3,12 @@ title: 章 24. DTrace
 part: 部 III. 系統管理
 prev: books/handbook/cutting-edge
 next: books/handbook/usb-device-mode
+description: This chapter explains how to use DTrace in FreeBSD
+tags: ["DTrace", "features", "guide", "tutorial", "kldload"]
 showBookMenu: true
-weight: 28
+weight: 30
 path: "/books/handbook/"
+aliases: ["/en/books/handbook/dtrace-implementation/","/en/books/handbook/dtrace-enable/","/en/books/handbook/dtrace-using/"]
@@ -49,49 +52,69 @@ endif::[]
 == 概述
-DTrace, also known as Dynamic Tracing, was developed by Sun(TM) as a tool for locating performance bottlenecks in production and pre-production systems. In addition to diagnosing performance problems, DTrace can be used to help investigate and debug unexpected behavior in both the FreeBSD kernel and in userland programs.
+DTrace,又被稱作 Dynamic Tracing ,由 Sun(TM) 開發,用在生產 (production) 跟預生產 (pre-production) 系統中找出效能瓶頸的工具。
+除了診斷性能問題外,DTrace 還可以用於查詢以及除錯 FreeBSD 核心和使用者層級程式的未預期行為。
-DTrace is a remarkable profiling tool, with an impressive array of features for diagnosing system issues. It may also be used to run pre-written scripts to take advantage of its capabilities. Users can author their own utilities using the DTrace D Language, allowing them to customize their profiling based on specific needs.
+DTrace 是一個卓越的分析工具,具有一系列令人驚豔、用於診斷系統問題的功能。
+使用者可以用 DTrace D 語言編寫自己的工具,從而允許他們根據特定的需求客製化。
-The FreeBSD implementation provides full support for kernel DTrace and experimental support for userland DTrace. Userland DTrace allows users to perform function boundary tracing for userland programs using the `pid` provider, and to insert static probes into userland programs for later tracing. Some ports, such as package:databases/postgres-server[] and package:lang/php56[] have a DTrace option to enable static probes. FreeBSD 10.0-RELEASE has reasonably good userland DTrace support, but it is not considered production ready. In particular, it is possible to crash traced programs.
+FreeBSD 實做提供對核心層級的 DTrace 全面的支援,以及對使用者層級的 DTrace 實驗性的支援。
+使用者層級的 DTrace 允許使用者使用 `pid` 執行函式邊界追蹤 (function boundary tracing),並將 static probes 插入到使用者程式以供之後追蹤。
+一些 ports,像是 package:databases/postgresql12-server[] 和 package:lang/php74[] 提供 DTrace 選項,以提供 static probes 功能。
-The official guide to DTrace is maintained by the Illumos project at[DTrace Guide].
+DTrace 的官方指南由 Illumos 維護,在[DTrace Guide]。
-* What DTrace is and what features it provides.
-* Differences between the Solaris(TM) DTrace implementation and the one provided by FreeBSD.
-* How to enable and use DTrace on FreeBSD.
+* 什麼是 DTrace 以及其提供的功能。
+* Solaris(TM) 實做的 DTrace 跟 FreeBSD 提供的 DTrace 之間的不同之處。
+* 如何在 FreeBSD 上啟用和使用 DTrace。
 * 了解 UNIX(TM) 及 FreeBSD 基礎 (crossref:basics[basics,FreeBSD 基礎])。
-* Have some familiarity with security and how it pertains to FreeBSD (crossref:security[security,安全性]).
+* 了解安全性以及其跟 FreeBSD 的關係 (crossref:security[security,安全性])。
 == 實作差異
-While the DTrace in FreeBSD is similar to that found in Solaris(TM), differences do exist. The primary difference is that in FreeBSD, DTrace is implemented as a set of kernel modules and DTrace can not be used until the modules are loaded. To load all of the necessary modules:
+雖然 FreeBSD 的 DTrace 和 Solaris(TM) 的 DTrace 類似,但是還是有存在差異。
+最重要的區別為,在 FreeBSD 中,DTrace 是作為一組核心模組 (kernel modules) 實做的,並且在載入模組之前無法使用。
 # kldload dtraceall
-Beginning with FreeBSD 10.0-RELEASE, the modules are automatically loaded when `dtrace` is run.
+從 FreeBSD 10.0-RELEASE 之後,模組會在執行 `dtrace` 時自動載入。
-FreeBSD uses the `DDB_CTF` kernel option to enable support for loading CTF data from kernel modules and the kernel itself. CTF is the Solaris(TM) Compact C Type Format which encapsulates a reduced form of debugging information similar to DWARF and the venerable stabs. CTF data is added to binaries by the `ctfconvert` and `ctfmerge` build tools. The `ctfconvert` utility parses DWARFELF debug sections created by the compiler and `ctfmerge` merges CTFELF sections from objects into either executables or shared libraries.
+FreeBSD 使用 `DDB_CTF` 核心選項來支援從核心模組和核心本身載入 `CTF` 資料。
+`CTF` 是 Solaris(TM) Compact C Type Format,它封裝了一種簡化形式的除錯資訊,類似於 `DWARF` 和 古老的 stabs。
+`CTF` 資料通過`ctfconvert` and `ctfmerge` 建構工具,加入到二進制文件中。
+`ctfconvert` 工具分析編譯器創建的 `DWARF``ELF` 除錯部份,而 `ctfmerge` 將目標的 `CTF``ELF` 部份合併到執行檔或函式庫中。
-Some different providers exist for FreeBSD than for Solaris(TM). Most notable is the `dtmalloc` provider, which allows tracing `malloc()` by type in the FreeBSD kernel. Some of the providers found in Solaris(TM), such as `cpc` and `mib`, are not present in FreeBSD. These may appear in future versions of FreeBSD. Moreover, some of the providers available in both operating systems are not compatible, in the sense that their probes have different argument types. Thus, D scripts written on Solaris(TM) may or may not work unmodified on FreeBSD, and vice versa.
+與 Solaris(TM) 相比,FreeBSD 存在一些不同的 providers。
+最值得注意的是 `dtmalloc` provider 允許在 FreeBSD 核心中按照類型 (type) 追蹤 `malloc()`。
+Solaris(TM) 中的一些 providers,例如 `cpc` 和 `mib`,在 FreeBSD 中則不存在。
+這些可能會在 FreeBSD 未來的版本中出現。
+此外,兩個作業系統中一些可用的 providers 是不相容的,因為他們具有不同的參數類型。
+因此,在 Solaris(TM) 上拓寫的 `D` 腳本在未經修改的情況下可能可以或不可以在 FreeBSD 上執行,反之亦然。
-Due to security differences, only `root` may use DTrace on FreeBSD. Solaris(TM) has a few low level security checks which do not yet exist in FreeBSD. As such, the [.filename]#/dev/dtrace/dtrace# is strictly limited to `root`.
+因為安全的差異,只有 `root` 可以在 FreeBSD 上使用 DTrace。
+Solaris(TM) 擁有一些 FreeBSD 中還不存在的低階 (low level) 安全檢查。
+因此 [.filename]#/dev/dtrace/dtrace# 被嚴格限制成 `root`。
-DTrace falls under the Common Development and Distribution License (CDDL) license. To view this license on FreeBSD, see [.filename]#/usr/src/cddl/contrib/opensolaris/OPENSOLARIS.LICENSE# or view it online at[]. While a FreeBSD kernel with DTrace support is BSD licensed, the CDDL is used when the modules are distributed in binary form or the binaries are loaded.
+DTrace 使用 Common Development and Distribution License (`CDDL`) 授權。
+要在 FreeBSD 上查看此授權, 請參閱 [.filename]#/usr/src/cddl/contrib/opensolaris/OPENSOLARIS.LICENSE# 或者在[] 線上查看。
+雖然具有 DTrace 支援的 FreeBSD 核心使用 `BSD` 授權,但當模組使用二進制形式或者二進制文件發布時,將使用 `CDDL` 授權。
 == 開啟 DTrace 支援
-In FreeBSD 9.2 and 10.0, DTrace support is built into the [.filename]#GENERIC# kernel. Users of earlier versions of FreeBSD or who prefer to statically compile in DTrace support should add the following lines to a custom kernel configuration file and recompile the kernel using the instructions in crossref:kernelconfig[kernelconfig,設定 FreeBSD 核心]:
+在 FreeBSD 9.2 和 10.0 中,DTrace 內建於 [.filename]#GENERIC#  核心裡。
+FreeBSD 早期版本的使用者或喜歡在 DTrace 支援下靜態編譯的使用者應加入下列幾行到客製化核心配置文件,並根據 crossref:kernelconfig[kernelconfig,Configuring the FreeBSD Kernel] 中的說明重新編譯核心:
@@ -101,52 +124,69 @@ makeoptions	DEBUG=-g
 makeoptions	WITH_CTF=1
-Users of the AMD64 architecture should also add this line:
+AMD64 架構的使用者應加入下列幾行:
 options         KDTRACE_FRAME
-This option provides support for FBT. While DTrace will work without this option, there will be limited support for function boundary tracing.
+此選項提供對 `FBT` 的支援,
+雖然 DTrace 可以在沒有此選項的情況下運作,但對函式邊界追蹤的支援有限。
-Once the FreeBSD system has rebooted into the new kernel, or the DTrace kernel modules have been loaded using `kldload dtraceall`, the system will need support for the Korn shell as the DTrace Toolkit has several utilities written in `ksh`. Make sure that the package:shells/ksh93[] package or port is installed. It is also possible to run these tools under package:shells/pdksh[] or package:shells/mksh[].
+一旦 FreeBSD 系統使用新的核心重新啟動,或者使用 `kldload dtraceall` 載入 DTrace 核心模組後,系統需要支援 Korn shell,因為 DTrace 工具箱有幾個用 `ksh` 拓寫的工具。
+確保已經安裝 package:shells/ksh93[] 套件或者 port,
+也可以在 package:shells/pdksh[] 或者 package:shells/mksh[] 下執行這些工具。
-Finally, install the current DTrace Toolkit, a collection of ready-made scripts for collecting system information. There are scripts to check open files, memory, CPU usage, and a lot more. FreeBSD 10 installs a few of these scripts into [.filename]#/usr/shared/dtrace#. On other FreeBSD versions, or to install the full DTrace Toolkit, use the package:sysutils/dtrace-toolkit[] package or port.
+最後,安裝目前的 DTrace 工具箱,這是一組用於收集系統資訊的現成腳本,
+有一些腳本可以檢查打開的文件、記憶體、`CPU` 使用情況等等。
+FreeBSD 10 將其中一些腳本安裝在 [.filename]#/usr/share/dtrace# 中。
+在其他 FreeBSD 的版本中,要安裝 DTrace 工具箱,請使用 package:sysutils/dtrace-toolkit[] 套件或者 port。
-The scripts found in [.filename]#/usr/shared/dtrace# have been specifically ported to FreeBSD. Not all of the scripts found in the DTrace Toolkit will work as-is on FreeBSD and some scripts may require some effort in order for them to work on FreeBSD.
+[.filename]#/usr/share/dtrace# 中的腳本已專門移植到 FreeBSD,
+並非所有在 DTrace 工具箱中的所有腳本都能在 FreeBSD 上按照原樣運作,一些腳本可能需要一些修改才能在 FreeBSD 上運作。
-The DTrace Toolkit includes many scripts in the special language of DTrace. This language is called the D language and it is very similar to C++. An in depth discussion of the language is beyond the scope of this document. It is covered extensively in the[Illumos Dynamic Tracing Guide].
+DTrace 工具箱包含許多使用 DTrace 特殊語言的腳本,
+這種語言被稱為 D 語言,它與 C++ 非常類似,
+他在[Illumos Dynamic Tracing Guide] 有廣泛的介紹。
 == 使用 DTrace
-DTrace scripts consist of a list of one or more _probes_, or instrumentation points, where each probe is associated with an action. Whenever the condition for a probe is met, the associated action is executed. For example, an action may occur when a file is opened, a process is started, or a line of code is executed. The action might be to log some information or to modify context variables. The reading and writing of context variables allows probes to share information and to cooperatively analyze the correlation of different events.
+DTrace 腳本由一個或多個 _probes_ 或檢查點 (instrumentation points) 的列表組成,其中每個 probe 都與一個行為有關,
+只要能滿足 probe 的條件,就會執行相關的行為,
+該行為可能是紀錄一些資訊,或修改上下文變數 (context variables),
+上下文變數的讀寫允許 probes 分享資訊和共同分析不同事件的相關性。
-To view all probes, the administrator can execute the following command:
+想要查看所有的 probes,系統管理員可以執行以下指令:
 # dtrace -l | more
-Each probe has an `ID`, a `PROVIDER` (dtrace or fbt), a `MODULE`, and a `FUNCTION NAME`. Refer to man:dtrace[1] for more information about this command.
+每個 probe 都有一個 `ID`、一個 `PROVIDER` (dtrace 或者 fbt)、一個 `MODULE` 和一個 `FUNCTION NAME`。
+有關此指令的更多資訊,請參閱 man:dtrace[1]。
-The examples in this section provide an overview of how to use two of the fully supported scripts from the DTrace Toolkit: the [.filename]#hotkernel# and [.filename]#procsystime# scripts.
+本節中的例子概述如何使用 DTrace 工具箱中完全支援的兩個腳本: [.filename]#hotkernel# 和 [.filename]#procsystime# 腳本。
-The [.filename]#hotkernel# script is designed to identify which function is using the most kernel time. It will produce output similar to the following:
+[.filename]#hotkernel# 腳本設計成觀察哪個函式使用的核心時間最多,
-# cd /usr/shared/dtrace/toolkit
+# cd /usr/local/share/dtrace-toolkit
 # ./hotkernel
 Sampling... Hit Ctrl-C to end.
-As instructed, use the kbd:[Ctrl+C] key combination to stop the process. Upon termination, the script will display a list of kernel functions and timing information, sorting the output in increasing order of time:
+按照說明,使用 kbd:[Ctrl+C] 組合鍵停止行程,
@@ -178,7 +218,8 @@ kernel`sched_idletd                                       137   0.3%
 0xc10981a5                                              42139  99.3%
-This script will also work with kernel modules. To use this feature, run the script with `-m`:
+要使用此功能,請使用 `-m` 執行腳本:
@@ -200,7 +241,10 @@ kernel                                                    874   0.4%
 0xc10981a5                                             213781  99.6%
-The [.filename]#procsystime# script captures and prints the system call time usage for a given process ID (PID) or process name. In the following example, a new instance of [.filename]#/bin/csh# was spawned. Then, [.filename]#procsystime# was executed and remained waiting while a few commands were typed on the other incarnation of `csh`. These are the results of this test:
+[.filename]#procsystime# 抓取和輸出系統調用時間,給設定行程 ID (PID) 或行程名稱的行程。
+在以下的例子中,生成了 [.filename]#/bin/csh# 新物件,
+然後,[.filename]#procsystime# 被執行並一直等待,同時在 `csh` 的另一個化身上輸入一些指令,
@@ -231,4 +275,4 @@ Elapsed Times for processes csh,
             read         3988049784
-As shown, the `read()` system call used the most time in nanoseconds while the `getpid()` system call used the least amount of time.
+如圖所示,`read()` 系統調用使用的時間最多(以奈秒為單位),而 `getpid()` 系統調用使用的時間最少。