[Zope-CVS] CVS: Products/AdaptableStorage/gateway_sql - PsycopgConnection.py:1.8

Shane Hathaway shane@zope.com
Sat, 1 Mar 2003 10:18:12 -0500


Update of /cvs-repository/Products/AdaptableStorage/gateway_sql
In directory cvs.zope.org:/tmp/cvs-serv17704/gateway_sql

Modified Files:
	PsycopgConnection.py 
Log Message:
Added an option for profiling the SQL statements.


=== Products/AdaptableStorage/gateway_sql/PsycopgConnection.py 1.7 => 1.8 ===
--- Products/AdaptableStorage/gateway_sql/PsycopgConnection.py:1.7	Fri Jan 10 11:08:20 2003
+++ Products/AdaptableStorage/gateway_sql/PsycopgConnection.py	Sat Mar  1 10:18:11 2003
@@ -16,8 +16,13 @@
 $Id$
 """
 
+import os
+from time import time
+
 from mapper_public import ITPCConnection
 
+PROFILE = os.environ.get('ZOPE_PROFILE_PG')
+
 
 class PsycopgConnection:
 
@@ -64,7 +69,13 @@
             cursor = self.cursor
             if cursor is None:
                 raise RuntimeError('Not connected')
-        cursor.execute(text, kw)
+        if PROFILE:
+            start = time()
+            cursor.execute(text, kw)
+            end = time()
+            print 'PG: %0.6fs: %s' % (end - start, text)
+        else:
+            cursor.execute(text, kw)
         if fetch:
             return cursor.fetchall()
         return None