2

I am using the tracemalloc library to pinpoint memory concerns in my application.

This is the code that I am using.

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')

An example output is as follows.

[<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>

Can someone please explain what those values mean?

  • lineno
  • size
  • count

1 Answer 1

0

I found this snippet below here https://willnewton.name/2016/12/28/debugging-memory-leaks-in-python/:

"The numbers can be interpreted as follows:

  • size, the total size of allocations at this call site
  • count, the total number of allocations at this call site
  • average, the average size of allocations at this call site "

Lineno is the linenumber.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.