FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-docs-zh-tw/howto/perf_profiling.po at 3.12 · python/python-docs-zh-tw · GitHub
python
python-docs-zh-tw
Repository navigation
Code
Issues
33
(33)
Pull requests
11
(11)
Discussions
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-docs-zh-tw
/
howto
/
perf_profiling.po
Copy path
More file actions
More file actions
Latest commit
History
History
History
492 lines (460 loc) · 20.7 KB
Breadcrumbs
python-docs-zh-tw
/
howto
/
perf_profiling.po
Copy path
File metadata and controls
492 lines (460 loc) · 20.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#
Copyright (C) 2001-2023, Python Software Foundation
#
This file is distributed under the same license as the Python package.
#
#
Translators:
#
Matt Wang <mattwang44@gmail.com>, 2023
msgid ""
msgstr ""
"
Project-Id-Version
:
Python 3.12\n
"
"
Report-Msgid-Bugs-To
:
\n
"
"
POT-Creation-Date
:
2024-09-03 11:11+0800\n
"
"
PO-Revision-Date
:
2023-12-09 17:39+0800\n
"
"
Last-Translator
:
Matt Wang <mattwang44@gmail.com>\n
"
"
Language-Team
:
Chinese - TAIWAN (https://github.com/python/python-docs-zh-
"
"
tw)\n
"
"
Language
:
zh_TW\n
"
"
MIME-Version
:
1.0\n
"
"
Content-Type
:
text/plain; charset=UTF-8\n
"
"
Content-Transfer-Encoding
:
8bit\n
"
#:
../../howto/perf_profiling.rst:7
msgid
"Python support for the Linux ``perf`` profiler"
msgstr
"Python 對 Linux ``perf`` 分析器的支援"
#:
../../howto/perf_profiling.rst:0
msgid
"author"
msgstr
"作者"
#:
../../howto/perf_profiling.rst:9
msgid
"Pablo Galindo"
msgstr
"Pablo Galindo"
#:
../../howto/perf_profiling.rst:11
msgid
""
"`The Linux perf profiler <https://perf.wiki.kernel.org>`_ is a very powerful "
"tool that allows you to profile and obtain information about the performance "
"of your application. ``perf`` also has a very vibrant ecosystem of tools "
"that aid with the analysis of the data that it produces."
msgstr
""
"`Linux 性能分析器 (Linux perf profiler) <https://perf.wiki.kernel.org>`_ 是一"
"個非常強大的工具,可讓你分析並獲取有關應用程式的性能資訊。``perf`` 還擁有一個"
"非常活躍的工具生態系統,有助於分析其生成的資料。"
#:
../../howto/perf_profiling.rst:17
msgid
""
"The main problem with using the ``perf`` profiler with Python applications "
"is that ``perf`` only gets information about native symbols, that is, the "
"names of functions and procedures written in C. This means that the names "
"and file names of Python functions in your code will not appear in the "
"output of ``perf``."
msgstr
""
"在 Python 應用程式中使用 ``perf`` 分析器的主要問題是 ``perf`` 僅獲取有關原生"
"符號的資訊,即用 C 編寫的函式和程式的名稱。這表示程式碼中的 Python 函式名稱和"
"檔案名稱不會出現在 ``perf`` 的輸出中。"
#:
../../howto/perf_profiling.rst:22
msgid
""
"Since Python 3.12, the interpreter can run in a special mode that allows "
"Python functions to appear in the output of the ``perf`` profiler. When this "
"mode is enabled, the interpreter will interpose a small piece of code "
"compiled on the fly before the execution of every Python function and it "
"will teach ``perf`` the relationship between this piece of code and the "
"associated Python function using :doc:`perf map files <../c-api/perfmaps>`."
msgstr
""
"從 Python 3.12 開始,直譯器可以在特殊模式下執行,該模式允許 Python 函式出現"
"在 ``perf`` 分析器的輸出中。啟用此模式後,直譯器將在執行每個 Python 函式之前"
"插入 (interpose) 一小段動態編譯的程式碼,並使用 :doc:`perf map 檔案 <../c-"
"api/perfmaps>`
\\
來告訴 ``perf`` 這段程式碼與相關聯的 Python 函式間的關係。"
#:
../../howto/perf_profiling.rst:31
msgid
""
"Support for the ``perf`` profiler is currently only available for Linux on "
"select architectures. Check the output of the ``configure`` build step or "
"check the output of ``python -m sysconfig | grep HAVE_PERF_TRAMPOLINE`` to "
"see if your system is supported."
msgstr
""
"目前對 ``perf`` 分析器的支援僅適用於 Linux 的特定架構上。檢查 ``configure`` "
"建構步驟的輸出或檢查 ``python -m sysconfig | grep HAVE_PERF_TRAMPOLINE`` 的輸"
"出來查看你的系統是否支援。"
#:
../../howto/perf_profiling.rst:36
msgid
"For example, consider the following script:"
msgstr
"例如,參考以下腳本:"
#:
../../howto/perf_profiling.rst:38
msgid
""
"def foo(n):\n"
" result = 0\n"
" for _ in range(n):\n"
" result += 1\n"
" return result\n"
"\n"
"def bar(n):\n"
" foo(n)\n"
"\n"
"def baz(n):\n"
" bar(n)\n"
"\n"
"if __name__ ==
\"
__main__
\"
:\n"
" baz(1000000)"
msgstr
""
"def foo(n):\n"
" result = 0\n"
" for _ in range(n):\n"
" result += 1\n"
" return result\n"
"\n"
"def bar(n):\n"
" foo(n)\n"
"\n"
"def baz(n):\n"
" bar(n)\n"
"\n"
"if __name__ ==
\"
__main__
\"
:\n"
" baz(1000000)"
#:
../../howto/perf_profiling.rst:55
msgid
"We can run ``perf`` to sample CPU stack traces at 9999 hertz::"
msgstr
"我們可以執行 ``perf`` 以 9999 赫茲採樣 CPU 堆疊追蹤 (stack trace): ::"
#:
../../howto/perf_profiling.rst:57
msgid
"$ perf record -F 9999 -g -o perf.data python my_script.py"
msgstr
"$ perf record -F 9999 -g -o perf.data python my_script.py"
#:
../../howto/perf_profiling.rst:59
msgid
"Then we can use ``perf report`` to analyze the data:"
msgstr
"然後我們可以使用 ``perf report`` 來分析資料:"
#:
../../howto/perf_profiling.rst:61
msgid
""
"$ perf report --stdio -n -g\n"
"\n"
"# Children Self Samples Command Shared Object Symbol\n"
"# ........ ........ ............ .......... .................. ..........................................\n"
"#\n"
" 91.08% 0.00% 0 python.exe python.exe [.] "
"_start\n"
" |\n"
" ---_start\n"
" |\n"
" --90.71%--__libc_start_main\n"
" Py_BytesMain\n"
" |\n"
" |--56.88%--pymain_run_python.constprop.0\n"
" | |\n"
" | |--56.13%--_PyRun_AnyFileObject\n"
" | | _PyRun_SimpleFileObject\n"
" | | |\n"
" | | |--55.02%--run_mod\n"
" | | | |\n"
" | | | --54.65%--"
"PyEval_EvalCode\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | |\n"
" | | | "
"|--51.67%--_PyEval_EvalFrameDefault\n"
" | | | "
"| |\n"
" | | | "
"| |--11.52%--_PyLong_Add\n"
" | | | "
"| | |\n"
" | | | "
"| | |--2.97%--_PyObject_Malloc\n"
"..."
msgstr
""
"$ perf report --stdio -n -g\n"
"\n"
"# Children Self Samples Command Shared Object Symbol\n"
"# ........ ........ ............ .......... .................. ..........................................\n"
"#\n"
" 91.08% 0.00% 0 python.exe python.exe [.] "
"_start\n"
" |\n"
" ---_start\n"
" |\n"
" --90.71%--__libc_start_main\n"
" Py_BytesMain\n"
" |\n"
" |--56.88%--pymain_run_python.constprop.0\n"
" | |\n"
" | |--56.13%--_PyRun_AnyFileObject\n"
" | | _PyRun_SimpleFileObject\n"
" | | |\n"
" | | |--55.02%--run_mod\n"
" | | | |\n"
" | | | --54.65%--"
"PyEval_EvalCode\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | |\n"
" | | | "
"|--51.67%--_PyEval_EvalFrameDefault\n"
" | | | "
"| |\n"
" | | | "
"| |--11.52%--_PyLong_Add\n"
" | | | "
"| | |\n"
" | | | "
"| | |--2.97%--_PyObject_Malloc\n"
"..."
#:
../../howto/perf_profiling.rst:100
msgid
""
"As you can see, the Python functions are not shown in the output, only "
"``_PyEval_EvalFrameDefault`` (the function that evaluates the Python "
"bytecode) shows up. Unfortunately that's not very useful because all Python "
"functions use the same C function to evaluate bytecode so we cannot know "
"which Python function corresponds to which bytecode-evaluating function."
msgstr
""
"如你所見,Python 函式未顯示在輸出中,僅顯示 ``_Py_Eval_EvalFrameDefault`` "
"(為 Python 位元組碼 (bytecode) 求值的函式)。不幸的是,這不是很有用,因為所"
"有 Python 函式都使用相同的 C 函式來替位元組碼求值,因此我們無法知道哪個 "
"Python 函式是對應於哪個位元組碼計算函式。"
#:
../../howto/perf_profiling.rst:105
msgid
""
"Instead, if we run the same experiment with ``perf`` support enabled we get:"
msgstr
""
"作為替代,如果我們在啟用 ``perf`` 支援的情況下執行相同的實驗,我們會得到:"
#:
../../howto/perf_profiling.rst:107
msgid
""
"$ perf report --stdio -n -g\n"
"\n"
"# Children Self Samples Command Shared Object Symbol\n"
"# ........ ........ ............ .......... .................. .....................................................................\n"
"#\n"
" 90.58% 0.36% 1 python.exe python.exe [.] "
"_start\n"
" |\n"
" ---_start\n"
" |\n"
" --89.86%--__libc_start_main\n"
" Py_BytesMain\n"
" |\n"
" |--55.43%--pymain_run_python.constprop.0\n"
" | |\n"
" | |--54.71%--_PyRun_AnyFileObject\n"
" | | _PyRun_SimpleFileObject\n"
" | | |\n"
" | | |--53.62%--run_mod\n"
" | | | |\n"
" | | | --53.26%--"
"PyEval_EvalCode\n"
" | | | py::"
"<module>:/src/script.py\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | py::baz:/"
"src/script.py\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | py::bar:/"
"src/script.py\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | py::foo:/"
"src/script.py\n"
" | | | |\n"
" | | | "
"|--51.81%--_PyEval_EvalFrameDefault\n"
" | | | "
"| |\n"
" | | | "
"| |--13.77%--_PyLong_Add\n"
" | | | "
"| | |\n"
" | | | "
"| | |--3.26%--_PyObject_Malloc"
msgstr
""
"$ perf report --stdio -n -g\n"
"\n"
"# Children Self Samples Command Shared Object Symbol\n"
"# ........ ........ ............ .......... .................. .....................................................................\n"
"#\n"
" 90.58% 0.36% 1 python.exe python.exe [.] "
"_start\n"
" |\n"
" ---_start\n"
" |\n"
" --89.86%--__libc_start_main\n"
" Py_BytesMain\n"
" |\n"
" |--55.43%--pymain_run_python.constprop.0\n"
" | |\n"
" | |--54.71%--_PyRun_AnyFileObject\n"
" | | _PyRun_SimpleFileObject\n"
" | | |\n"
" | | |--53.62%--run_mod\n"
" | | | |\n"
" | | | --53.26%--"
"PyEval_EvalCode\n"
" | | | py::"
"<module>:/src/script.py\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | py::baz:/"
"src/script.py\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | py::bar:/"
"src/script.py\n"
" | | | "
"_PyEval_EvalFrameDefault\n"
" | | | "
"PyObject_Vectorcall\n"
" | | | "
"_PyEval_Vector\n"
" | | | py::foo:/"
"src/script.py\n"
" | | | |\n"
" | | | "
"|--51.81%--_PyEval_EvalFrameDefault\n"
" | | | "
"| |\n"
" | | | "
"| |--13.77%--_PyLong_Add\n"
" | | | "
"| | |\n"
" | | | "
"| | |--3.26%--_PyObject_Malloc"
#:
../../howto/perf_profiling.rst:152
msgid
"How to enable ``perf`` profiling support"
msgstr
"如何啟用 ``perf`` 分析支援"
#:
../../howto/perf_profiling.rst:154
msgid
""
"``perf`` profiling support can be enabled either from the start using the "
"environment variable :envvar:`PYTHONPERFSUPPORT` or the :option:`-X perf <-"
"X>` option, or dynamically using :func:`sys.activate_stack_trampoline` and :"
"func:`sys.deactivate_stack_trampoline`."
msgstr
""
"要啟用 ``perf`` 分析支援,可以在一開始就使用環境變數 :envvar:"
"`PYTHONPERFSUPPORT` 或使用 :option:`-X perf <-X>` 選項,也可以使用 :func:"
"`sys.activate_stack_trampoline` 和 :func:`sys.deactivate_stack_trampoline` 來"
"動態啟用。"
#:
../../howto/perf_profiling.rst:160
msgid
""
"The :mod:`!sys` functions take precedence over the :option:`!-X` option, "
"the :option:`!-X` option takes precedence over the environment variable."
msgstr
""
":mod:`!sys` 函式優先於 :option:`!-X` 選項、:option:`!-X` 選項優先於環境變數。"
#:
../../howto/perf_profiling.rst:163
msgid
"Example, using the environment variable::"
msgstr
"例如,使用環境變數: ::"
#:
../../howto/perf_profiling.rst:165
msgid
""
"$ PYTHONPERFSUPPORT=1 python script.py\n"
"$ perf report -g -i perf.data"
msgstr
""
"$ PYTHONPERFSUPPORT=1 python script.py\n"
"$ perf report -g -i perf.data"
#:
../../howto/perf_profiling.rst:168
msgid
"Example, using the :option:`!-X` option::"
msgstr
"例如,使用 :option:`!-X` 選項: ::"
#:
../../howto/perf_profiling.rst:170
msgid
""
"$ python -X perf script.py\n"
"$ perf report -g -i perf.data"
msgstr
""
"$ python -X perf script.py\n"
"$ perf report -g -i perf.data"
#:
../../howto/perf_profiling.rst:173
msgid
"Example, using the :mod:`sys` APIs in file :file:`example.py`:"
msgstr
"例如,在 :file:`example.py` 檔案中使用 :mod:`sys` API:"
#:
../../howto/perf_profiling.rst:175
msgid
""
"import sys\n"
"\n"
"sys.activate_stack_trampoline(
\"
perf
\"
)\n"
"do_profiled_stuff()\n"
"sys.deactivate_stack_trampoline()\n"
"\n"
"non_profiled_stuff()"
msgstr
""
"import sys\n"
"\n"
"sys.activate_stack_trampoline(
\"
perf
\"
)\n"
"do_profiled_stuff()\n"
"sys.deactivate_stack_trampoline()\n"
"\n"
"non_profiled_stuff()"
#:
../../howto/perf_profiling.rst:185
msgid
"...then::"
msgstr
"...然後: ::"
#:
../../howto/perf_profiling.rst:187
msgid
""
"$ python ./example.py\n"
"$ perf report -g -i perf.data"
msgstr
""
"$ python ./example.py\n"
"$ perf report -g -i perf.data"
#:
../../howto/perf_profiling.rst:192
msgid
"How to obtain the best results"
msgstr
"如何獲得最佳結果"
#:
../../howto/perf_profiling.rst:194
msgid
""
"For best results, Python should be compiled with ``CFLAGS=
\"
-fno-omit-frame-"
"pointer -mno-omit-leaf-frame-pointer
\"
`` as this allows profilers to unwind "
"using only the frame pointer and not on DWARF debug information. This is "
"because as the code that is interposed to allow ``perf`` support is "
"dynamically generated it doesn't have any DWARF debugging information "
"available."
msgstr
""
"為了獲得最佳結果,應使用 ``CFLAGS=
\"
-fno-omit-frame-pointer -mno-omit-leaf-"
"frame-pointer
\"
`` 來進行 Python 編譯,因為這能允許分析器僅使用 frame 指標而不"
"是 DWARF 除錯資訊來解析 (unwind)。這是因為,由於插入以允許 ``perf`` 支援的程"
"式碼是動態生成的,因此它沒有任何可用的 DWARF 除錯資訊。"
#:
../../howto/perf_profiling.rst:201
msgid
""
"You can check if your system has been compiled with this flag by running::"
msgstr
"你可以透過執行以下指令來檢查你的系統是否已使用此旗標進行編譯: ::"
#:
../../howto/perf_profiling.rst:203
msgid
"$ python -m sysconfig | grep 'no-omit-frame-pointer'"
msgstr
"$ python -m sysconfig | grep 'no-omit-frame-pointer'"
#:
../../howto/perf_profiling.rst:205
msgid
""
"If you don't see any output it means that your interpreter has not been "
"compiled with frame pointers and therefore it may not be able to show Python "
"functions in the output of ``perf``."
msgstr
""
"如果你沒有看到任何輸出,則表示你的直譯器尚未使用 frame 指標進行編譯,因此它可"
"能無法在 ``perf`` 的輸出中顯示 Python 函式。"
Back
|
FazBrowse Home
|
New Git URL