Python tracemalloc,大小和计数是多少



我正在使用tracemalloc库来确定应用程序中的内存问题。

这是我正在使用的代码。

tracemalloc.start()
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')

numStats = len(top_stats)
statsThreshold = 100
if numStats < statsThreshold:
numStatsCollections = numStats
else: 
numStatsCollections = statsThreshold   
collectedStats = str(top_stats[:numStatsCollections])
self.memLogger.error('n----------START----------n' +                           
collectedStats.replace(',','n') + 'n----------END----------n')

输出示例如下。

[<Statistic traceback=<Traceback (<Frame filename='C:\Users\TheUser\AppData\Local\Programs\Python\Python38\lib\base64.py' lineno=87>
)> size=10308228 count=107>
<Statistic traceback=<Traceback (<Frame filename='C:\Users\TheUser\AppData\Local\Programs\Python\Python38\lib\json\decoder.py' lineno=353>
)> size=3549589 count=37774>

有人能解释一下这些价值观是什么意思吗?

  • lineno
  • 尺寸
  • 计数

我在下面找到了这个片段https://willnewton.name/2016/12/28/debugging-memory-leaks-in-python/:

"这些数字可以解释如下:

  • size,此调用站点的分配总大小
  • count,此调用站点的分配总数
  • average,此调用站点的平均分配大小">

Lineno是行号。

最新更新