Show
Ignore:
Timestamp:
02/21/06 18:15:40 (18 years ago)
Author:
jerome
Message:

Added timing information for SQL queries and transactions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/mysqlstorage.py

    r2649 r2741  
    2424# 
    2525 
     26import time 
     27 
    2628from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota 
    2729from pykota.storages.sql import SQLStorage 
     
    4648        self.tool.logdebug("Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..." % (host, port, dbname, user)) 
    4749        self.database = MySQLdb.connect(host=host, port=port, db=dbname, user=user, passwd=passwd) 
    48         self.database.autocommit(1) 
     50        self.database.autocommit(1) 
    4951        self.cursor = self.database.cursor() 
    5052        self.closed = 0 
     
    6163    def beginTransaction(self) :     
    6264        """Starts a transaction.""" 
     65        self.before = time.time() 
    6366        self.cursor.execute("BEGIN;") 
    6467        self.tool.logdebug("Transaction begins...") 
     
    6770        """Commits a transaction.""" 
    6871        self.database.commit() 
     72        after = time.time() 
    6973        self.tool.logdebug("Transaction committed.") 
     74        self.tool.logdebug("Transaction duration : %.4f seconds" % (after - self.before)) 
    7075         
    7176    def rollbackTransaction(self) :      
    7277        """Rollbacks a transaction.""" 
    7378        self.database.rollback() 
     79        after = time.time() 
    7480        self.tool.logdebug("Transaction aborted.") 
     81        self.tool.logdebug("Transaction duration : %.4f seconds" % (after - self.before)) 
    7582         
    7683    def doRawSearch(self, query) : 
     
    8087            query += ';' 
    8188        try : 
     89            before = time.time() 
    8290            self.tool.logdebug("QUERY : %s" % query) 
    8391            self.cursor.execute(query) 
     
    8694        else :     
    8795            # This returns a list of lists. Integers are returned as longs. 
    88             return self.cursor.fetchall() 
     96            result = self.cursor.fetchall() 
     97            after = time.time() 
     98            self.tool.logdebug("Query Duration : %.4f seconds" % (after - before)) 
     99            return result 
    89100             
    90101    def doSearch(self, query) :         
     
    115126            query += ';' 
    116127        try : 
     128            before = time.time() 
    117129            self.tool.logdebug("QUERY : %s" % query) 
    118130            self.cursor.execute(query) 
    119131        except self.database.Error, msg :     
    120132            raise PyKotaStorageError, str(msg) 
     133        else :     
     134            after = time.time() 
     135            self.tool.logdebug("Query Duration : %.4f seconds" % (after - before)) 
    121136             
    122137    def doQuote(self, field) :