Pyramid's debugtoolbar does exactly what you describe. They use SQLAlchemy's events to hook into the base Engine class:
from sqlalchemy import event
from sqlalchemy.engine.base import Engine
@event.listens_for(Engine, "before_cursor_execute")
def before_cursor_execute(conn, cursor, stmt, params, context, execmany):
# do something
@event.listens_for(Engine, "after_cursor_execute")
def after_cursor_execute(conn, cursor, stmt, params, context, execmany):
# do something
Maybe you can modify that code to work with web.py.