Category : tracemalloc

So I want to watch the memory consumption of 2 algorithms? My plan for that was get the memory consumption before the algorithm, after the algorithm and then subtract the results. before = tracemalloc.get_traced_memory()[0] algorithm() after = tracemalloc.get_traced_memory()[0] print(after – before) So I tried it with that: import tracemalloc tracemalloc.start() before1 = tracemalloc.get_traced_memory()[0] def recursive(i,max): ..

Read more

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

Read more