mirror of
https://github.com/ansible/awx.git
synced 2026-07-07 22:38:04 -02:30
add a custom DB backend that provides system-level SQL profiling
run this command on _any_ node in an awx cluster: $ awx-manage profile_sql --threshold=2.0 --minutes=1 ...and for 1 minute, the timing for _every_ SQL query in _every_ awx Python process that uses the Django ORM will be measured queries that run longer than (in this example) 2 seconds will be written to a per-process sqlite database in /var/lib/awx/profile, and the file will contain an EXPLAIN VERBOSE for the query and the full Python stack that led to that SQL query's execution (this includes not just WSGI requests, but background processes like the runworker and dispatcher) $ awx-manage profile_sql --threshold=0 ...can be used to disable profiling again (if you don't want to wait for the minute to expire)
This commit is contained in:
21
awx/main/management/commands/profile_sql.py
Normal file
21
awx/main/management/commands/profile_sql.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from awx.main.tasks import profile_sql
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Enable or disable SQL Profiling across all Python processes.
|
||||
SQL profile data will be recorded at /var/lib/awx/profile/
|
||||
"""
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--threshold', dest='threshold', type=float, default=2.0,
|
||||
help='The minimum query duration in seconds (default=2). Use 0 to disable.')
|
||||
parser.add_argument('--minutes', dest='minutes', type=float, default=5,
|
||||
help='How long to record for in minutes (default=5)')
|
||||
|
||||
def handle(self, **options):
|
||||
profile_sql.delay(
|
||||
threshold=options['threshold'], minutes=options['minutes']
|
||||
)
|
||||
Reference in New Issue
Block a user