Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
23f628de
Kaydet (Commit)
23f628de
authored
Şub 16, 2014
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20616: Add a format() method to tracemalloc.Traceback.
üst
f617fa88
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
7 deletions
+59
-7
tracemalloc.rst
Doc/library/tracemalloc.rst
+24
-7
test_tracemalloc.py
Lib/test/test_tracemalloc.py
+20
-0
tracemalloc.py
Lib/tracemalloc.py
+13
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/tracemalloc.rst
Dosyayı görüntüle @
23f628de
...
...
@@ -118,7 +118,6 @@ Get the traceback of a memory block
Code to display the traceback of the biggest memory block::
import linecache
import tracemalloc
# Store 25 frames
...
...
@@ -132,12 +131,8 @@ Code to display the traceback of the biggest memory block::
# pick the biggest memory block
stat = top_stats[0]
print("%s memory blocks: %.1f KiB" % (stat.count, stat.size / 1024))
for frame in stat.traceback:
print(' File "%s", line %s' % (frame.filename, frame.lineno))
line = linecache.getline(frame.filename, frame.lineno)
line = line.strip()
if line:
print(' ' + line)
for line in stat.traceback.format():
print(line)
Example of output of the Python test suite (traceback limited to 25 frames)::
...
...
@@ -602,4 +597,26 @@ Traceback
The :attr:`Trace.traceback` attribute is an instance of :class:`Traceback`
instance.
.. method:: format(limit=None)
Format the traceback as a list of lines with newlines. Use the
:mod:`linecache` module to retrieve lines from the source code. If
*limit* is set, only format the *limit* most recent frames.
Similar to the :func:`traceback.format_tb` function, except that
:meth:`format` does not include newlines.
Example::
print("Traceback (most recent call first):")
for line in traceback:
print(line)
Output::
Traceback (most recent call first):
File "test.py", line 9
obj = Object()
File "test.py", line 12
tb = tracemalloc.get_object_traceback(f())
Lib/test/test_tracemalloc.py
Dosyayı görüntüle @
23f628de
...
...
@@ -510,6 +510,26 @@ class TestSnapshot(unittest.TestCase):
self
.
assertEqual
(
traceback
[:
2
],
(
traceback
[
0
],
traceback
[
1
]))
def
test_format_traceback
(
self
):
snapshot
,
snapshot2
=
create_snapshots
()
def
getline
(
filename
,
lineno
):
return
' <
%
s,
%
s>'
%
(
filename
,
lineno
)
with
unittest
.
mock
.
patch
(
'tracemalloc.linecache.getline'
,
side_effect
=
getline
):
tb
=
snapshot
.
traces
[
0
]
.
traceback
self
.
assertEqual
(
tb
.
format
(),
[
' File "a.py", line 2'
,
' <a.py, 2>'
,
' File "b.py", line 4'
,
' <b.py, 4>'
])
self
.
assertEqual
(
tb
.
format
(
limit
=
1
),
[
' File "a.py", line 2'
,
' <a.py, 2>'
])
self
.
assertEqual
(
tb
.
format
(
limit
=-
1
),
[])
class
TestFilters
(
unittest
.
TestCase
):
maxDiff
=
2048
...
...
Lib/tracemalloc.py
Dosyayı görüntüle @
23f628de
from
collections
import
Sequence
from
functools
import
total_ordering
import
fnmatch
import
linecache
import
os.path
import
pickle
...
...
@@ -205,6 +206,18 @@ class Traceback(Sequence):
def
__repr__
(
self
):
return
"<Traceback
%
r>"
%
(
tuple
(
self
),)
def
format
(
self
,
limit
=
None
):
lines
=
[]
if
limit
is
not
None
and
limit
<
0
:
return
lines
for
frame
in
self
[:
limit
]:
lines
.
append
(
' File "
%
s", line
%
s'
%
(
frame
.
filename
,
frame
.
lineno
))
line
=
linecache
.
getline
(
frame
.
filename
,
frame
.
lineno
)
.
strip
()
if
line
:
lines
.
append
(
'
%
s'
%
line
)
return
lines
def
get_object_traceback
(
obj
):
"""
...
...
Misc/NEWS
Dosyayı görüntüle @
23f628de
...
...
@@ -25,6 +25,8 @@ Core and Builtins
Library
-------
- Issue #20616: Add a format() method to tracemalloc.Traceback.
- Issue #19744: the ensurepip installation step now just prints a warning to
stderr rather than failing outright if SSL/TLS is unavailable. This allows
local installation of POSIX builds without SSL/TLS support.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment