Attachment 'timing-log.diff'

Download

   1 diff -r 219eb584e133 MoinMoin/request.py
   2 --- a/MoinMoin/request.py	Sun Nov 05 21:41:16 2006 +0100
   3 +++ b/MoinMoin/request.py	Sun Nov 05 22:58:08 2006 +0100
   4 @@ -762,6 +762,17 @@ class RequestBase(object):
   5          msg = '[%s] %s\n' % (time.asctime(), msg)
   6          sys.stderr.write(msg)
   7      
   8 +    def timing_log(self, msg):
   9 +        """ Log to stderr, which may be error.log """
  10 +        msg = msg.strip()
  11 +        # Encode unicode msg
  12 +        if isinstance(msg, unicode):
  13 +            msg = msg.encode(config.charset)
  14 +        # Add time stamp
  15 +        msg = '[%s] %s\n' % (time.asctime(), msg)
  16 +        self.timing_logfile.write(msg)
  17 +        self.timing_logfile.flush()
  18 +    
  19      def write(self, *data):
  20          """ Write to output stream.
  21          """
  22 @@ -1066,6 +1077,10 @@ class RequestBase(object):
  23              
  24              action = self.form.get('action', [None])[0]
  25  
  26 +            if 1:
  27 +                pid = os.getpid()
  28 +                self.timing_log("pid %d %s %s" % (pid, action, self.url))
  29 +
  30              # The last component in path_info is the page name, if any
  31              path = self.getPathinfo()
  32              if path.startswith('/'):
  33 @@ -1169,6 +1184,23 @@ space between words. Group page name is 
  34              pass
  35          except Exception, err:
  36              self.fail(err)
  37 +
  38 +        if 1:
  39 +            pid = os.getpid()
  40 +            self.clock.stop('total')
  41 +            total_secs = self.clock.timings['total']
  42 +            if total_secs > 50:
  43 +                action += '!!!!!'
  44 +            elif total_secs > 20:
  45 +                action += '!!!!'
  46 +            elif total_secs > 10:
  47 +                action += '!!!'
  48 +            elif total_secs > 2:
  49 +                action += '!!'
  50 +            total = self.clock.value('total')
  51 +            indicator = self.page.exists() and '+' or '-'
  52 +            action = indicator + action
  53 +            self.timing_log("%s pid %d %s %s" % (total, pid, action, self.url))
  54  
  55          return self.finish()
  56  
  57 @@ -2041,6 +2073,13 @@ class RequestFastCGI(RequestBase):
  58          #sys.stderr.write(pformat(more_headers))
  59          #sys.stderr.write(pformat(self.user_headers))
  60  
  61 +    def open_logs(self):
  62 +        # create log file for catching stderr output
  63 +        if not self.opened_logs:
  64 +            sys.stderr = open(os.path.join(self.cfg.data_dir, 'error.log'), 'at')
  65 +            self.timing_logfile = open('/tmp/moin-timing.log', 'at')
  66 +            self.opened_logs = 1
  67 +
  68  # WSGI --------------------------------------------------------------
  69  
  70  class RequestWSGI(RequestBase):

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-04-12 18:34:55, 2.5 KB) [[attachment:timing-log.diff]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.