Metadata-Version: 2.1
Name: django-sql-sniffer
Version: 1.0.3.dev0
Summary: Django SQL Sniffer
Home-page: https://github.com/gruuya/django-sql-sniffer
Author: Marko Grujic
Author-email: markoog@gmail.com
License: MIT
Keywords: django sql query remote process analysis
Platform: UNKNOWN
Requires-Python: >=3.5
Description-Content-Type: text/markdown
Requires-Dist: django

Django SQL Sniffer
==================
A simple command line tool for analyzing Django ORM SQL execution from a running process.
Minimally invasive and granular - no need to change the logging config or the source code 
of the target process, and no need to restart the process.

# Usage
Install though pip
```
pip install django-sql-sniffer
```
Run the tool by passing it the target process id
```
django-sql-sniffer -p 76441
```
`Ctrl + C` to stop and show the query stats summary. Take a look at a short demo:
[demo](https://github.com/gruuya/django-sql-sniffer)\
By default, stats summary shows queries sorted by max duration; the possible options include:
- `-t` print queries in tail mode, i.e. as they are executed
- `-c` sort stats summary by query count
- `-s` sort stats summary by total combined query duration
- `-n` set the number of top queries to display in stats summary
- `-v` for verbose logging mode on both the client and server side
- if OS supports `SIGINFO` signal press `Ctrl + T` to display snapshot stats summary without killing the process
# How it works
The tool is composed out of a client and a server. Running `django-sql-sniffer` starts the server, which then 
injects the client into the running process using GDB/LLDB and waits for it to connect. 
The client monkey patches the Django DB cursor and starts streaming queries to the server as they are executed.
The queries are then collected and analyzed on the server side.\
Finally, when the server gets a shutdown signal, it stops the client which in turn rolls back the monkey patch leaving
the target process in the original state.

