-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
31 lines (23 loc) · 712 Bytes
/
tasks.py
File metadata and controls
31 lines (23 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
TODO: Implement performance tracking for all tasks at once.
Execution time, Query time, Query count, Memory Usage
"""
import logging
from celery.signals import task_prerun, task_postrun
from django.db import reset_queries
from .utils import print_slow_queries, convert_size, install
install('guppy3')
from guppy import hpy
heap = hpy()
warn = logging.getLogger().warning
@task_prerun.connect()
def task_prerun(**kwargs):
reset_queries()
hp = heap.heap()
print(kwargs)
warn("MEM BEFORE: %s", convert_size(hp.size))
@task_postrun.connect()
def task_postrun(**kwargs):
hp = heap.heap()
print_slow_queries(kwargs.get('task').name)
warn("MEM AFTER: %s", convert_size(hp.size))