optimize get_mem_usage()
@@ -216,7 +216,7 @@ class Owner(commands.Cog):
await ctx.send(body)
- def get_mem_usage(self, obj, seen=None):
+ async def get_mem_usage(self, obj, seen=None):
if seen is None:
seen = []
@@ -229,19 +229,19 @@ class Owner(commands.Cog):
for obj_child in obj.values():
if obj_child not in seen:
seen.append(obj_child)
- mem += self.get_mem_usage(obj_child, seen)
+ mem += await self.get_mem_usage(obj_child, seen)
if isinstance(obj, list):
for obj_child in obj:
if obj_child not in seen:
seen.append(obj_child)
- mem += self.get_mem_usage(obj_child, seen)
+ mem += await self.get_mem_usage(obj_child, seen)
try:
for obj_child in obj.__dict__.values():
if obj_child not in seen:
seen.append(obj_child)
- mem += self.get_mem_usage(obj_child, seen)
+ mem += await self.get_mem_usage(obj_child, seen)
except AttributeError:
pass
@@ -256,31 +256,33 @@ class Owner(commands.Cog):
if thing is None:
for cog_name, cog in self.bot.cogs.items():
for name, obj in cog.__dict__.items():
- mem_usage[name] = self.get_mem_usage(obj) / 1000000 # mb
+ mem_usage[name] = await self.get_mem_usage(obj) / 1000000 # mb
else:
thing = eval(thing)
if isinstance(thing, dict):
for name, obj in thing.items():
- mem_usage[name] = self.get_mem_usage(obj) / 1000000
+ mem_usage[name] = await self.get_mem_usage(obj) / 1000000
elif isinstance(thing, list):
for i, obj in enumerate(thing):
- mem_usage[i] = self.get_mem_usage(obj) / 1000000
+ mem_usage[i] = await self.get_mem_usage(obj) / 1000000
else:
try:
for name, obj in thing.__dict__.items():
- mem_usage[name] = self.get_mem_usage(obj) / 1000000
+ mem_usage[name] = await self.get_mem_usage(obj) / 1000000
except AttributeError:
- mem_usage['thing'] = self.get_mem_usage(thing) / 1000000
+ mem_usage['thing'] = await self.get_mem_usage(thing) / 1000000
mem_usage_sorted = sorted(mem_usage.items(), key=(lambda t: t[1]), reverse=True)[:25]
body = ''
+ total = 0
for name, value in mem_usage_sorted:
- body += f'{name}: {value} mb\n'
+ body += f'`{name}`: {value} mb\n
+ total += value
- await ctx.send(body)
+ await ctx.send(f'Total: {total/1000} gb\n'body)
"""
@commands.command(name='updatesticky')
