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
  • 尺寸
  • 计数

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)