[FIX] loading: pool.get("ir.module.module") was done before it was available.
[odoo/odoo.git] / openerp / netsvc.py
index aca1b9c..3a2add2 100644 (file)
@@ -3,23 +3,19 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
-#    The refactoring about the OpenSSL support come from Tryton
-#    Copyright (C) 2007-2009 Cédric Krier.
-#    Copyright (C) 2007-2009 Bertrand Chenal.
-#    Copyright (C) 2008 B2CK SPRL.
+#    Copyright (C) 2004-2011 OpenERP SA (<http://www.openerp.com>)
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
+#    GNU Affero General Public License for more details.
 #
-#    You should have received a copy of the GNU General Public License
+#    You should have received a copy of the GNU Affero General Public License
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
@@ -35,7 +31,6 @@ import socket
 import sys
 import threading
 import time
-import warnings
 import types
 from pprint import pformat
 
@@ -62,6 +57,9 @@ def close_socket(sock):
     sock.close()
 
 
+#.apidoc title: Common Services: netsvc
+#.apidoc module-mods: member-order: bysource
+
 class Service(object):
     """ Base class for *Local* services
 
@@ -186,7 +184,6 @@ class ColoredFormatter(DBFormatter):
         return DBFormatter.format(self, record)
 
 def init_logger():
-    import os
     from tools.translate import resetlocale
     resetlocale()
 
@@ -248,19 +245,22 @@ def init_alternative_logger():
     logger.setLevel(logging.ERROR)
 
 class Agent(object):
-    """Singleton that keeps track of cancellable tasks to run at a given
-       timestamp.
-       The tasks are caracterised by:
+    """ Singleton that keeps track of cancellable tasks to run at a given
+        timestamp.
+       
+        The tasks are characterised by:
+       
             * a timestamp
             * the database on which the task run
             * the function to call
             * the arguments and keyword arguments to pass to the function
 
         Implementation details:
-          Tasks are stored as list, allowing the cancellation by setting
-          the timestamp to 0.
-          A heapq is used to store tasks, so we don't need to sort
-          tasks ourself.
+        
+          - Tasks are stored as list, allowing the cancellation by setting
+            the timestamp to 0.
+          - A heapq is used to store tasks, so we don't need to sort
+            tasks ourself.
     """
     __tasks = []
     __tasks_by_db = {}
@@ -430,10 +430,19 @@ class OpenERPDispatcher:
         log(title, msg, channel=channel, depth=depth, fn=fn)
     def dispatch(self, service_name, method, params):
         try:
-            logger = logging.getLogger('result')
-            self.log('service', tuple(replace_request_password(params)), depth=(None if logger.isEnabledFor(logging.DEBUG_RPC_ANSWER) else 1), fn='%s.%s'%(service_name,method))
             auth = getattr(self, 'auth_provider', None)
+            logger = logging.getLogger('result')
+            start_time = end_time = 0
+            if logger.isEnabledFor(logging.DEBUG_RPC_ANSWER):
+                self.log('service', tuple(replace_request_password(params)), depth=None, fn='%s.%s'%(service_name,method))
+            if logger.isEnabledFor(logging.DEBUG_RPC):
+                start_time = time.time()
             result = ExportService.getService(service_name).dispatch(method, auth, params)
+            if logger.isEnabledFor(logging.DEBUG_RPC):
+                end_time = time.time()
+            if not logger.isEnabledFor(logging.DEBUG_RPC_ANSWER):
+                self.log('service (%.3fs)' % (end_time - start_time), tuple(replace_request_password(params)), depth=1, fn='%s.%s'%(service_name,method))
+            self.log('execution time', '%.3fs' % (end_time - start_time), channel=logging.DEBUG_RPC_ANSWER)
             self.log('result', result, channel=logging.DEBUG_RPC_ANSWER)
             return result
         except Exception, e: