77msgstr ""
88"Project-Id-Version : Python 3.12\n "
99"Report-Msgid-Bugs-To : \n "
10- "POT-Creation-Date : 2024-08-30 18:24 +0000\n "
10+ "POT-Creation-Date : 2024-09-10 00:04 +0000\n "
1111"PO-Revision-Date : 2023-08-17 22:17+0800\n "
1212"
Last-Translator :
Matt Wang <[email protected] >\n "
1313"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
@@ -94,17 +94,29 @@ msgstr ""
9494msgid "On a Linux machine, this can be done via::"
9595msgstr "在 Linux 機器上,這可以透過以下方式完成: ::"
9696
97+ #: ../../howto/instrumentation.rst:42
98+ msgid "$ yum install systemtap-sdt-devel"
99+ msgstr ""
100+
97101#: ../../howto/instrumentation.rst:44
98102msgid "or::"
99103msgstr "或是: ::"
100104
105+ #: ../../howto/instrumentation.rst:46
106+ msgid "$ sudo apt-get install systemtap-sdt-dev"
107+ msgstr ""
108+
101109#: ../../howto/instrumentation.rst:49
102110msgid ""
103111"CPython must then be :option:`configured with the --with-dtrace option <--"
104112"with-dtrace>`:"
105113msgstr ""
106114"然後 CPython 必須使用\\ :option:`配置 --with-dtrace 選項 <--with-dtrace>`:"
107115
116+ #: ../../howto/instrumentation.rst:52
117+ msgid "checking for --with-dtrace... yes"
118+ msgstr ""
119+
108120#: ../../howto/instrumentation.rst:56
109121msgid ""
110122"On macOS, you can list available DTrace probes by running a Python process "
@@ -114,6 +126,28 @@ msgstr ""
114126"在 macOS 上,你可以透過在後台運行 Python 行程並列出 Python 發布者 (provider) "
115127"所提供的所有可用探針,以列出可用的 DTrace 探針: ::"
116128
129+ #: ../../howto/instrumentation.rst:60
130+ msgid ""
131+ "$ python3.6 -q &\n"
132+ "$ sudo dtrace -l -P python$! # or: dtrace -l -m python3.6\n"
133+ "\n"
134+ " ID PROVIDER MODULE FUNCTION NAME\n"
135+ "29564 python18035 python3.6 _PyEval_EvalFrameDefault "
136+ "function-entry\n"
137+ "29565 python18035 python3.6 dtrace_function_entry "
138+ "function-entry\n"
139+ "29566 python18035 python3.6 _PyEval_EvalFrameDefault "
140+ "function-return\n"
141+ "29567 python18035 python3.6 dtrace_function_return "
142+ "function-return\n"
143+ "29568 python18035 python3.6 collect gc-"
144+ "done\n"
145+ "29569 python18035 python3.6 collect gc-"
146+ "start\n"
147+ "29570 python18035 python3.6 _PyEval_EvalFrameDefault line\n"
148+ "29571 python18035 python3.6 maybe_dtrace_line line"
149+ msgstr ""
150+
117151#: ../../howto/instrumentation.rst:73
118152msgid ""
119153"On Linux, you can verify if the SystemTap static markers are present in the "
@@ -122,6 +156,12 @@ msgstr ""
122156"在 Linux 上,你可以透過查看二進位建置檔案中是否包含 \" .note.stapsdt\" 部分來"
123157"驗證 SystemTap 靜態標記是否存在。"
124158
159+ #: ../../howto/instrumentation.rst:78
160+ msgid ""
161+ "$ readelf -S ./python | grep .note.stapsdt\n"
162+ "[30] .note.stapsdt NOTE 0000000000000000 00308d78"
163+ msgstr ""
164+
125165#: ../../howto/instrumentation.rst:81
126166msgid ""
127167"If you've built Python as a shared library (with the :option:`--enable-"
@@ -131,10 +171,64 @@ msgstr ""
131171"如果你已將 Python 建置為共享函式庫(使用 :option:`--enable-shared` 配置選"
132172"項),則需要在共享函式庫中查找。例如: ::"
133173
174+ #: ../../howto/instrumentation.rst:85
175+ msgid ""
176+ "$ readelf -S libpython3.3dm.so.1.0 | grep .note.stapsdt\n"
177+ "[29] .note.stapsdt NOTE 0000000000000000 00365b68"
178+ msgstr ""
179+
134180#: ../../howto/instrumentation.rst:88
135181msgid "Sufficiently modern readelf can print the metadata::"
136182msgstr "足夠現代化的 readelf 可以印出元資料 (metadata): ::"
137183
184+ #: ../../howto/instrumentation.rst:90
185+ msgid ""
186+ "$ readelf -n ./python\n"
187+ "\n"
188+ "Displaying notes found at file offset 0x00000254 with length 0x00000020:\n"
189+ " Owner Data size Description\n"
190+ " GNU 0x00000010 NT_GNU_ABI_TAG (ABI version "
191+ "tag)\n"
192+ " OS: Linux, ABI: 2.6.32\n"
193+ "\n"
194+ "Displaying notes found at file offset 0x00000274 with length 0x00000024:\n"
195+ " Owner Data size Description\n"
196+ " GNU 0x00000014 NT_GNU_BUILD_ID (unique build "
197+ "ID bitstring)\n"
198+ " Build ID: df924a2b08a7e89f6e11251d4602022977af2670\n"
199+ "\n"
200+ "Displaying notes found at file offset 0x002d6c30 with length 0x00000144:\n"
201+ " Owner Data size Description\n"
202+ " stapsdt 0x00000031 NT_STAPSDT (SystemTap probe "
203+ "descriptors)\n"
204+ " Provider: python\n"
205+ " Name: gc__start\n"
206+ " Location: 0x00000000004371c3, Base: 0x0000000000630ce2, Semaphore: "
207+ "0x00000000008d6bf6\n"
208+ " Arguments: -4@%ebx\n"
209+ " stapsdt 0x00000030 NT_STAPSDT (SystemTap probe "
210+ "descriptors)\n"
211+ " Provider: python\n"
212+ " Name: gc__done\n"
213+ " Location: 0x00000000004374e1, Base: 0x0000000000630ce2, Semaphore: "
214+ "0x00000000008d6bf8\n"
215+ " Arguments: -8@%rax\n"
216+ " stapsdt 0x00000045 NT_STAPSDT (SystemTap probe "
217+ "descriptors)\n"
218+ " Provider: python\n"
219+ " Name: function__entry\n"
220+ " Location: 0x000000000053db6c, Base: 0x0000000000630ce2, Semaphore: "
221+ "0x00000000008d6be8\n"
222+ " Arguments: 8@%rbp 8@%r12 -4@%eax\n"
223+ " stapsdt 0x00000046 NT_STAPSDT (SystemTap probe "
224+ "descriptors)\n"
225+ " Provider: python\n"
226+ " Name: function__return\n"
227+ " Location: 0x000000000053dba8, Base: 0x0000000000630ce2, Semaphore: "
228+ "0x00000000008d6bea\n"
229+ " Arguments: 8@%rbp 8@%r12 -4@%eax"
230+ msgstr ""
231+
138232#: ../../howto/instrumentation.rst:125
139233msgid ""
140234"The above metadata contains information for SystemTap describing how it can "
@@ -158,14 +252,77 @@ msgstr ""
158252"以下範例示範 DTrace 腳本可用於顯示 Python 腳本的呼叫/回傳階層結構,僅在名為 "
159253"\" start\" 的函式的呼叫內進行追蹤。換句話說,引入時的函式呼叫不會被列出:"
160254
255+ #: ../../howto/instrumentation.rst:138
256+ msgid ""
257+ "self int indent;\n"
258+ "\n"
259+ "python$target:::function-entry\n"
260+ "/copyinstr(arg1) == \" start\" /\n"
261+ "{\n"
262+ " self->trace = 1;\n"
263+ "}\n"
264+ "\n"
265+ "python$target:::function-entry\n"
266+ "/self->trace/\n"
267+ "{\n"
268+ " printf(\" %d\\ t%*s:\" , timestamp, 15, probename);\n"
269+ " printf(\" %*s\" , self->indent, \"\" );\n"
270+ " printf(\" %s:%s:%d\\ n\" , basename(copyinstr(arg0)), copyinstr(arg1), "
271+ "arg2);\n"
272+ " self->indent++;\n"
273+ "}\n"
274+ "\n"
275+ "python$target:::function-return\n"
276+ "/self->trace/\n"
277+ "{\n"
278+ " self->indent--;\n"
279+ " printf(\" %d\\ t%*s:\" , timestamp, 15, probename);\n"
280+ " printf(\" %*s\" , self->indent, \"\" );\n"
281+ " printf(\" %s:%s:%d\\ n\" , basename(copyinstr(arg0)), copyinstr(arg1), "
282+ "arg2);\n"
283+ "}\n"
284+ "\n"
285+ "python$target:::function-return\n"
286+ "/copyinstr(arg1) == \" start\" /\n"
287+ "{\n"
288+ " self->trace = 0;\n"
289+ "}"
290+ msgstr ""
291+
161292#: ../../howto/instrumentation.rst:172 ../../howto/instrumentation.rst:230
162293msgid "It can be invoked like this::"
163294msgstr "可以這樣呼叫: ::"
164295
296+ #: ../../howto/instrumentation.rst:174
297+ msgid "$ sudo dtrace -q -s call_stack.d -c \" python3.6 script.py\" "
298+ msgstr ""
299+
165300#: ../../howto/instrumentation.rst:176 ../../howto/instrumentation.rst:236
166301msgid "The output looks like this:"
167302msgstr "輸出如下所示:"
168303
304+ #: ../../howto/instrumentation.rst:178
305+ msgid ""
306+ "156641360502280 function-entry:call_stack.py:start:23\n"
307+ "156641360518804 function-entry: call_stack.py:function_1:1\n"
308+ "156641360532797 function-entry: call_stack.py:function_3:9\n"
309+ "156641360546807 function-return: call_stack.py:function_3:10\n"
310+ "156641360563367 function-return: call_stack.py:function_1:2\n"
311+ "156641360578365 function-entry: call_stack.py:function_2:5\n"
312+ "156641360591757 function-entry: call_stack.py:function_1:1\n"
313+ "156641360605556 function-entry: call_stack.py:function_3:9\n"
314+ "156641360617482 function-return: call_stack.py:function_3:10\n"
315+ "156641360629814 function-return: call_stack.py:function_1:2\n"
316+ "156641360642285 function-return: call_stack.py:function_2:6\n"
317+ "156641360656770 function-entry: call_stack.py:function_3:9\n"
318+ "156641360669707 function-return: call_stack.py:function_3:10\n"
319+ "156641360687853 function-entry: call_stack.py:function_4:13\n"
320+ "156641360700719 function-return: call_stack.py:function_4:14\n"
321+ "156641360719640 function-entry: call_stack.py:function_5:18\n"
322+ "156641360732567 function-return: call_stack.py:function_5:21\n"
323+ "156641360747370 function-return:call_stack.py:start:28"
324+ msgstr ""
325+
169326#: ../../howto/instrumentation.rst:201
170327msgid "Static SystemTap markers"
171328msgstr "靜態 SystemTap 標記"
@@ -185,6 +342,44 @@ msgid ""
185342"hierarchy of a Python script:"
186343msgstr "例如,此 SystemTap 腳本可用於顯示 Python 腳本的呼叫/回傳階層結構:"
187344
345+ #: ../../howto/instrumentation.rst:210
346+ msgid ""
347+ "probe process(\" python\" ).mark(\" function__entry\" ) {\n"
348+ " filename = user_string($arg1);\n"
349+ " funcname = user_string($arg2);\n"
350+ " lineno = $arg3;\n"
351+ "\n"
352+ " printf(\" %s => %s in %s:%d\\\\ n\" ,\n"
353+ " thread_indent(1), funcname, filename, lineno);\n"
354+ "}\n"
355+ "\n"
356+ "probe process(\" python\" ).mark(\" function__return\" ) {\n"
357+ " filename = user_string($arg1);\n"
358+ " funcname = user_string($arg2);\n"
359+ " lineno = $arg3;\n"
360+ "\n"
361+ " printf(\" %s <= %s in %s:%d\\\\ n\" ,\n"
362+ " thread_indent(-1), funcname, filename, lineno);\n"
363+ "}"
364+ msgstr ""
365+
366+ #: ../../howto/instrumentation.rst:232
367+ msgid ""
368+ "$ stap \\ \n"
369+ " show-call-hierarchy.stp \\ \n"
370+ " -c \" ./python test.py\" "
371+ msgstr ""
372+
373+ #: ../../howto/instrumentation.rst:238
374+ msgid ""
375+ "11408 python(8274): => __contains__ in Lib/_abcoll.py:362\n"
376+ "11414 python(8274): => __getitem__ in Lib/os.py:425\n"
377+ "11418 python(8274): => encode in Lib/os.py:490\n"
378+ "11424 python(8274): <= encode in Lib/os.py:493\n"
379+ "11428 python(8274): <= __getitem__ in Lib/os.py:426\n"
380+ "11433 python(8274): <= __contains__ in Lib/_abcoll.py:366"
381+ msgstr ""
382+
188383#: ../../howto/instrumentation.rst:247
189384msgid "where the columns are:"
190385msgstr "其中的行 (column) 是:"
@@ -216,10 +411,20 @@ msgstr ""
216411"函式庫中,並且探針的帶點路徑 (dotted path) 需要反映這一點。例如,上面範例中的"
217412"這一列:"
218413
414+ #: ../../howto/instrumentation.rst:259
415+ msgid "probe process(\" python\" ).mark(\" function__entry\" ) {"
416+ msgstr ""
417+
219418#: ../../howto/instrumentation.rst:263
220419msgid "should instead read:"
221420msgstr "應該改為讀取:"
222421
422+ #: ../../howto/instrumentation.rst:265
423+ msgid ""
424+ "probe process(\" python\" ).library(\" libpython3.6dm.so.1.0\" )."
425+ "mark(\" function__entry\" ) {"
426+ msgstr ""
427+
223428#: ../../howto/instrumentation.rst:269
224429msgid "(assuming a :ref:`debug build <debug-build>` of CPython 3.6)"
225430msgstr "(假設 CPython 3.6 的\\ :ref:`除錯建置版本 <debug-build>`)"
@@ -342,6 +547,29 @@ msgstr ""
342547msgid "Here is a tapset file, based on a non-shared build of CPython:"
343548msgstr "這是一個 tapset 檔案,是基於 CPython 的非共享建置版本:"
344549
550+ #: ../../howto/instrumentation.rst:351
551+ msgid ""
552+ "/*\n"
553+ " Provide a higher-level wrapping around the function__entry and\n"
554+ " function__return markers:\n"
555+ " \\ */\n"
556+ "probe python.function.entry = process(\" python\" ).mark(\" function__entry\" )\n"
557+ "{\n"
558+ " filename = user_string($arg1);\n"
559+ " funcname = user_string($arg2);\n"
560+ " lineno = $arg3;\n"
561+ " frameptr = $arg4\n"
562+ "}\n"
563+ "probe python.function.return = process(\" python\" )."
564+ "mark(\" function__return\" )\n"
565+ "{\n"
566+ " filename = user_string($arg1);\n"
567+ " funcname = user_string($arg2);\n"
568+ " lineno = $arg3;\n"
569+ " frameptr = $arg4\n"
570+ "}"
571+ msgstr ""
572+
345573#: ../../howto/instrumentation.rst:372
346574msgid ""
347575"If this file is installed in SystemTap's tapset directory (e.g. ``/usr/share/"
@@ -381,6 +609,21 @@ msgstr ""
381609"此 SystemTap 腳本使用上面的 tapset 來更清晰地實作上面給出的追蹤 Python 函式呼"
382610"叫階層結構的範例,而無需直接命名靜態標記:"
383611
612+ #: ../../howto/instrumentation.rst:395
613+ msgid ""
614+ "probe python.function.entry\n"
615+ "{\n"
616+ " printf(\" %s => %s in %s:%d\\ n\" ,\n"
617+ " thread_indent(1), funcname, filename, lineno);\n"
618+ "}\n"
619+ "\n"
620+ "probe python.function.return\n"
621+ "{\n"
622+ " printf(\" %s <= %s in %s:%d\\ n\" ,\n"
623+ " thread_indent(-1), funcname, filename, lineno);\n"
624+ "}"
625+ msgstr ""
626+
384627#: ../../howto/instrumentation.rst:410
385628msgid ""
386629"The following script uses the tapset above to provide a top-like view of all "
@@ -389,3 +632,25 @@ msgid ""
389632msgstr ""
390633"以下腳本使用上面的 tapset 來提供所有正在運行之 CPython 程式碼的近乎最高層視"
391634"角,顯示整個系統中每秒最常被進入的 20 個位元組碼幀 (bytecode frame):"
635+
636+ #: ../../howto/instrumentation.rst:414
637+ msgid ""
638+ "global fn_calls;\n"
639+ "\n"
640+ "probe python.function.entry\n"
641+ "{\n"
642+ " fn_calls[pid(), filename, funcname, lineno] += 1;\n"
643+ "}\n"
644+ "\n"
645+ "probe timer.ms(1000) {\n"
646+ " printf(\"\\ 033[2J\\ 033[1;1H\" ) /* clear screen \\ */\n"
647+ " printf(\" %6s %80s %6s %30s %6s\\ n\" ,\n"
648+ " \" PID\" , \" FILENAME\" , \" LINE\" , \" FUNCTION\" , \" CALLS\" )\n"
649+ " foreach ([pid, filename, funcname, lineno] in fn_calls- limit 20) {\n"
650+ " printf(\" %6d %80s %6d %30s %6d\\ n\" ,\n"
651+ " pid, filename, lineno, funcname,\n"
652+ " fn_calls[pid, filename, funcname, lineno]);\n"
653+ " }\n"
654+ " delete fn_calls;\n"
655+ "}"
656+ msgstr ""
0 commit comments