Bladeren bron

Performance wanking: don't go through toggle_capture if we know we're not a process that wants to capture events; don't use apply.

Chris McDonough 18 jaren geleden
bovenliggende
commit
e186e60de1
3 gewijzigde bestanden met toevoegingen van 45 en 4 verwijderingen
  1. 7 0
      src/supervisor/dispatchers.py
  2. 1 1
      src/supervisor/options.py
  3. 37 3
      src/supervisor/tests/test_dispatchers.py

+ 7 - 0
src/supervisor/dispatchers.py

@@ -128,6 +128,13 @@ class POutputDispatcher(PDispatcher):
             self.process.config.options.logger.trace(msg)
 
     def record_output(self):
+        if self.capturelog is None:
+            # shortcut trying to find capture data
+            data = self.output_buffer
+            self.output_buffer = ''
+            self._log(data)
+            return
+            
         if self.capturemode:
             token = self.event_type.END_TOKEN
         else:

+ 1 - 1
src/supervisor/options.py

@@ -1067,7 +1067,7 @@ class ServerOptions(Options):
         if self.logger.manager.disable >= loggers.TRACE:
             return
         if loggers.TRACE >= self.logger.getEffectiveLevel():
-            apply(self.logger._log, (loggers.TRACE, msg, args), kwargs)
+            self.logger._log(loggers.TRACE, msg, args, **kwargs)
 
     def close_fd(self, fd):
         try:

+ 37 - 3
src/supervisor/tests/test_dispatchers.py

@@ -59,7 +59,8 @@ class POutputDispatcherTests(unittest.TestCase):
     def test_handle_read_event(self):
         options = DummyOptions()
         options.readfd_result = 'abc'
-        config = DummyPConfig(options, 'process1', '/bin/process1')
+        config = DummyPConfig(options, 'process1', '/bin/process1',
+                              stdout_capturefile='abc')
         process = DummyProcess(config)
         dispatcher = self._makeOne(process)
         self.assertEqual(dispatcher.handle_read_event(), None)
@@ -139,13 +140,31 @@ class POutputDispatcherTests(unittest.TestCase):
         self.assertEqual(dispatcher.childlog.handlers[0].reopened, True)
         self.assertEqual(dispatcher.mainlog.handlers[0].reopened, True)
 
-    def test_record_output(self):
-        # stdout/stderr goes to the process log and the main log
+    def test_record_output_non_capturemode(self):
+        # stdout/stderr goes to the process log and the main log,
+        # in non-capturemode, the data length doesn't matter
         options = DummyOptions()
         config = DummyPConfig(options, 'process1', '/bin/process1',
                               stdout_logfile='/tmp/foo')
         process = DummyProcess(config)
         dispatcher = self._makeOne(process)
+        dispatcher.output_buffer = 'a'
+        dispatcher.record_output()
+        self.assertEqual(dispatcher.childlog.data, ['a'])
+        self.assertEqual(options.logger.data[0],
+             "'process1' stdout output:\na")
+        self.assertEqual(dispatcher.output_buffer, '')
+
+    def test_record_output_capturemode_string_longer_than_token(self):
+        # stdout/stderr goes to the process log and the main log,
+        # in capturemode, the length of the data needs to be longer
+        # than the capture token to make it out.
+        options = DummyOptions()
+        config = DummyPConfig(options, 'process1', '/bin/process1',
+                              stdout_logfile='/tmp/foo',
+                              stdout_capturefile='/tmp/capture')
+        process = DummyProcess(config)
+        dispatcher = self._makeOne(process)
         dispatcher.output_buffer = 'stdout string longer than a token'
         dispatcher.record_output()
         self.assertEqual(dispatcher.childlog.data,
@@ -153,6 +172,21 @@ class POutputDispatcherTests(unittest.TestCase):
         self.assertEqual(options.logger.data[0],
              "'process1' stdout output:\nstdout string longer than a token")
 
+    def test_record_output_capturemode_string_not_longer_than_token(self):
+        # stdout/stderr goes to the process log and the main log,
+        # in capturemode, the length of the data needs to be longer
+        # than the capture token to make it out.
+        options = DummyOptions()
+        config = DummyPConfig(options, 'process1', '/bin/process1',
+                              stdout_logfile='/tmp/foo',
+                              stdout_capturefile='/tmp/capture')
+        process = DummyProcess(config)
+        dispatcher = self._makeOne(process)
+        dispatcher.output_buffer = 'a'
+        dispatcher.record_output()
+        self.assertEqual(dispatcher.childlog.data, [])
+        self.assertEqual(dispatcher.output_buffer, 'a')
+
     def test_stdout_capturemode_single_buffer(self):
         # mike reported that comm events that took place within a single
         # output buffer were broken 8/20/2007