On Tuesday, June 21, 2016 at 11:25:36 PM UTC+2, Martijn van Oosterhout wrote: > > Hi, > > In an effort to find the bottlenecks in our system we'd like to collect > statistics about which queries take a long time, or return a lot of rows, > or paths which are triggering lots of queries. > > Now, the system consists of lots of parts working in parallel, each with > their own Session object, so we want the stats per Session. > > In answer to my own question, this is what I came up with: https://gist.github.com/kleptog/1a866b67faa2c917758496a4fbbf92b8
It allows you to do things like: s1 = SessionMaker() s1.execute("SELECT 1") s1.commit() print s1._query_stats print s1._query_stats.query_log Output: <QueryStats count=1 time=0.00s> [(1467010565.738685, 'SELECT 1', {}, [('__main__', '<module>', 127), ('__main__', 'test', 115)], 0.0002570152282714844)] Using the log you have access to all the executed queries, which you can the aggregate, save to disk, etc. It tracks start time, parameters, call stack and duration. The adding of extra attributes to the Session and Connection objects is not pretty, but it works. Have a nice day, -- Martijn van Oosterhout <klep...@gmail.com> http://svana.org/kleptog/ -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.