[Piglit] [PATCH v3 2/2] framework/log: add an HTTP logger

Dylan Baker baker.dylan.c at gmail.com
Wed Sep 30 10:00:45 PDT 2015


This patch looks fine to me, minus the one minor nit.

With it fixed:
Reviewed-by: Dylan Baker <baker.dylan.c at gmail.com>

On Wed, Sep 23, 2015 at 02:35:38PM +0100, Thomas Wood wrote:
> Add an HTTP logger so that it is possible to monitor the progress and
> status of piglit remotely through a web server. The web server runs on
> port 8080 by default and can be configured to run on a different port by
> setting the "port" key in the "http" section of the configuration file.
> The server responds to requests for /summary, which provides a summary
> of the current state in JSON format.
> 
> v2: Add appropriate locking when reading state data for the web server
>     Stop the server after the request for the final results
>     Remove the full results page
>     Add a configuration option to set the server port
> v3: Use the new fallback parameter of safe_get
>     Convert the test result status back to string
> 
> Signed-off-by: Thomas Wood <thomas.wood at intel.com>
> ---
>  framework/log.py          | 72 +++++++++++++++++++++++++++++++++++++++++++++++
>  framework/programs/run.py |  2 +-
>  2 files changed, 73 insertions(+), 1 deletion(-)
> 
> diff --git a/framework/log.py b/framework/log.py
> index 423479f..623082a 100644
> --- a/framework/log.py
> +++ b/framework/log.py
> @@ -32,6 +32,13 @@ import abc
>  import itertools
>  import threading
>  import collections
> +from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler

Can you add a newline here?

> +try:
> +    import simplejson as json
> +except ImportError:
> +    import json
> +
> +from framework.core import PIGLIT_CONFIG
>  
>  __all__ = ['LogManager']
>  
> @@ -252,6 +259,65 @@ class DummyLog(BaseLog):
>          pass
>  
>  
> +class HTTPLogServer(threading.Thread):
> +    class RequestHandler(BaseHTTPRequestHandler):
> +        INDENT = 4
> +
> +        def do_GET(self):
> +            if self.path == "/summary":
> +                self.send_response(200)
> +                self.end_headers()
> +                with self.server.state_lock:
> +                    status = {
> +                        "complete": self.server.state["complete"],
> +                        "running" : self.server.state["running"],
> +                        "total"   : self.server.state["total"],
> +                        "results" : self.server.state["summary"],
> +                    }
> +                self.wfile.write(json.dumps(status, indent=self.INDENT))
> +            else:
> +                self.send_response(404)
> +                self.end_headers()
> +
> +    def __init__(self, state, state_lock):
> +        super(HTTPLogServer, self).__init__()
> +        port = int(PIGLIT_CONFIG.safe_get("http", "port", fallback=8080))
> +        self._httpd = HTTPServer(("", port), HTTPLogServer.RequestHandler)
> +        self._httpd.state = state
> +        self._httpd.state_lock = state_lock
> +
> +    def run(self):
> +        while True:
> +            with self._httpd.state_lock:
> +                # stop handling requests after the request for the final results
> +                if self._httpd.state["complete"] == self._httpd.state["total"]:
> +                    break;
> +            self._httpd.handle_request()
> +
> +
> +class HTTPLog(BaseLog):
> +    """ A Logger that serves status information over http """
> +
> +    def __init__(self, state, state_lock):
> +        super(HTTPLog, self).__init__(state, state_lock)
> +        self._name = None
> +
> +    def start(self, name):
> +        with self._LOCK:
> +            self._name = name
> +            self._state['running'].append(self._name)
> +
> +    def log(self, status):
> +        with self._LOCK:
> +            self._state['running'].remove(self._name)
> +            self._state['complete'] += 1
> +            assert status in self.SUMMARY_KEYS
> +            self._state['summary'][str(status)] += 1
> +
> +    def summary(self):
> +        pass
> +
> +
>  class LogManager(object):
>      """ Creates new log objects
>  
> @@ -274,6 +340,7 @@ class LogManager(object):
>          'quiet': QuietLog,
>          'verbose': VerboseLog,
>          'dummy': DummyLog,
> +        'http': HTTPLog,
>      }
>  
>      def __init__(self, logger, total):
> @@ -288,6 +355,11 @@ class LogManager(object):
>          }
>          self._state_lock = threading.Lock()
>  
> +        # start the http server for http logger
> +        if logger == 'http':
> +            self.log_server = HTTPLogServer(self._state, self._state_lock)
> +            self.log_server.start()
> +
>      def get(self):
>          """ Return a new log instance """
>          return self._log(self._state, self._state_lock)
> diff --git a/framework/programs/run.py b/framework/programs/run.py
> index 16c3d37..c35783d 100644
> --- a/framework/programs/run.py
> +++ b/framework/programs/run.py
> @@ -158,7 +158,7 @@ def _run_parser(input_):
>      log_parser.add_argument("-l", "--log-level",
>                              dest="log_level",
>                              action="store",
> -                            choices=['quiet', 'verbose', 'dummy'],
> +                            choices=['quiet', 'verbose', 'dummy', 'http'],
>                              default='quiet',
>                              help="Set the logger verbosity level")
>      parser.add_argument("--test-list",
> -- 
> 1.9.1
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20150930/76debdfe/attachment.sig>


More information about the Piglit mailing list