FreeBSD Bugzilla – Attachment 241576 Details for
Bug 270926
The zh-tw translation about handbook ch24-dtrace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
the patch
dtrace.patch (text/plain), 16.47 KB, created by
Yan-Hao Wang
on 2023-04-19 05:00:46 UTC
(
hide
)
Description:
the patch
Filename:
MIME Type:
Creator:
Yan-Hao Wang
Created:
2023-04-19 05:00:46 UTC
Size:
16.47 KB
patch
obsolete
>=================================================================== >--- a/documentation/content/zh-tw/books/handbook/dtrace/_index.adoc >+++ b/documentation/content/zh-tw/books/handbook/dtrace/_index.adoc >@@ -2,11 +2,14 @@ > 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/"] > --- > > [[dtrace]] > = DTrace >@@ -48,51 +51,71 @@ > > [[dtrace-synopsis]] > == æ¦è¿° > >-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 http://dtrace.org/guide[DTrace Guide]. >+DTrace çå®æ¹æåç± Illumos ç¶è·ï¼å¨ http://dtrace.org/guide[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,å®å ¨æ§])ã > > [[dtrace-implementation]] > == 實ä½å·®ç° > >-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) 實åçï¼ä¸¦ä¸å¨è¼å ¥æ¨¡çµä¹åç¡æ³ä½¿ç¨ã >+è¦è¼å ¥ææéè¦ç模çµ: > > [source,shell] > .... > # 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 http://opensource.org/licenses/CDDL-1.0[http://opensource.org/licenses/CDDL-1.0]. 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# æè å¨ http://opensource.org/licenses/CDDL-1.0[http://opensource.org/licenses/CDDL-1.0] ç·ä¸æ¥çã >+éç¶å ·æ DTrace æ¯æ´ç FreeBSD æ ¸å¿ä½¿ç¨ `BSD` ææ¬ï¼ä½ç¶æ¨¡çµä½¿ç¨äºé²å¶å½¢å¼æè äºé²å¶æ件ç¼å¸æï¼å°ä½¿ç¨ `CDDL` ææ¬ã > > [[dtrace-enable]] > == éå 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] ä¸ç說æéæ°ç·¨è¯æ ¸å¿: > > [.programlisting] > .... > options KDTRACE_HOOKS >@@ -100,54 +123,71 @@ > makeoptions DEBUG=-g > makeoptions WITH_CTF=1 > .... > >-Users of the AMD64 architecture should also add this line: >+AMD64 æ¶æ§ç使ç¨è æå å ¥ä¸åå¹¾è¡: > > [.programlisting] > .... > 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ã > > [NOTE] > ==== >-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 http://www.dtrace.org/guide[Illumos Dynamic Tracing Guide]. >+DTrace å·¥å ·ç®±å å«è¨±å¤ä½¿ç¨ DTrace ç¹æ®èªè¨çè ³æ¬ï¼ >+é種èªè¨è¢«ç¨±çº D èªè¨ï¼å®è C++ é常é¡ä¼¼ï¼ >+å°æ¼è©²èªè¨ç深度è¨è«è¶ åºäºæ¤æ件çç¯åï¼ >+ä»å¨ http://www.dtrace.org/guide[Illumos Dynamic Tracing Guide] æ廣æ³çä»ç´¹ã > > [[dtrace-using]] > == ä½¿ç¨ 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ï¼ç³»çµ±ç®¡çå¡å¯ä»¥å·è¡ä»¥ä¸æ令: > > [source,shell] > .... > # 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# è ³æ¬è¨è¨æè§å¯åªåå½å¼ä½¿ç¨çæ ¸å¿æéæå¤ï¼ >+å®æç¢çé¡ä¼¼æ¼ä»¥ä¸å §å®¹ç輸åº: > > [source,shell] > .... >-# 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] çµåéµåæ¢è¡ç¨ï¼ >+ä¸æ¢å¾ï¼è ³æ¬å°é¡¯ç¤ºä¸æ´åçæ ¸å¿å½å¼åæéè³è¨ï¼æç §æééå¢æåº: > > [source,shell] > .... > kernel`_thread_lock_flags 2 0.0% >@@ -177,9 +217,10 @@ > 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` å·è¡è ³æ¬: > > [source,shell] > .... > # ./hotkernel -m >@@ -199,9 +240,12 @@ > 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` çå¦ä¸åå身ä¸è¼¸å ¥ä¸äºæä»¤ï¼ >+以ä¸æ¯æ¬æ¬¡æ¸¬è©¦ççµæ: > > [source,shell] > .... > # ./procsystime -n csh >@@ -230,5 +274,5 @@ > sigsuspend 6985124 > 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()` 系統調ç¨ä½¿ç¨çæéæå°ã
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 270926
: 241576